logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

patch.1p (19652B)


  1. '\" et
  2. .TH PATCH "1P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. patch
  12. \(em apply changes to files
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. patch \fB[\fR-blNR\fB] [\fR-c|-e|-n|-u\fB] [\fR-d \fIdir\fB] [\fR-D \fIdefine\fB] [\fR-i \fIpatchfile\fB]
  17. [\fR-o \fIoutfile\fB] [\fR-p \fInum\fB] [\fR-r \fIrejectfile\fB] [\fIfile\fB]\fR
  18. .fi
  19. .SH DESCRIPTION
  20. The
  21. .IR patch
  22. utility shall read a source (patch) file containing any of four
  23. forms of difference (diff) listings produced by the
  24. .IR diff
  25. utility (normal, copied context, unified context, or in the style of
  26. .IR ed )
  27. and apply those differences to a file. By default,
  28. .IR patch
  29. shall read from the standard input.
  30. .P
  31. The
  32. .IR patch
  33. utility shall attempt to determine the type of the
  34. .IR diff
  35. listing, unless overruled by a
  36. .BR \-c ,
  37. .BR \-e ,
  38. .BR \-n ,
  39. or
  40. .BR \-u
  41. option.
  42. .P
  43. If the patch file contains more than one patch,
  44. .IR patch
  45. shall attempt to apply each of them as if they came from separate patch
  46. files. (In this case, the application shall ensure that the name of the
  47. patch file is determinable for each
  48. .IR diff
  49. listing.)
  50. .SH OPTIONS
  51. The
  52. .IR patch
  53. utility shall conform to the Base Definitions volume of POSIX.1\(hy2017,
  54. .IR "Section 12.2" ", " "Utility Syntax Guidelines".
  55. .P
  56. The following options shall be supported:
  57. .IP "\fB\-b\fP" 10
  58. Save a copy of the original contents of each modified file, before the
  59. differences are applied, in a file of the same name with the suffix
  60. .BR .orig
  61. appended to it. If the file already exists, it shall be overwritten;
  62. if multiple patches are applied to the same file, the
  63. .BR .orig
  64. file shall be written only for the first patch. When the
  65. .BR \-o
  66. .IR outfile
  67. option is also specified,
  68. .IR file \c
  69. .BR .orig
  70. shall not be created but, if
  71. .IR outfile
  72. already exists,
  73. .IR outfile \c
  74. .BR .orig
  75. shall be created.
  76. .IP "\fB\-c\fP" 10
  77. Interpret the patch file as a copied context difference (the output
  78. of the utility
  79. .IR diff
  80. when the
  81. .BR \-c
  82. or
  83. .BR \-C
  84. options are specified).
  85. .IP "\fB\-d\ \fIdir\fR" 10
  86. Change the current directory to
  87. .IR dir
  88. before processing as described in the EXTENDED DESCRIPTION section.
  89. .IP "\fB\-D\ \fIdefine\fR" 10
  90. Mark changes with one of the following C preprocessor constructs:
  91. .RS 10
  92. .sp
  93. .RS 4
  94. .nf
  95. #ifdef define
  96. \&...
  97. #endif
  98. .P
  99. #ifndef define
  100. \&...
  101. #endif
  102. .fi
  103. .P
  104. .RE
  105. .P
  106. optionally combined with the C preprocessor construct
  107. .BR #else .
  108. If the patched file is processed with the C preprocessor, where the
  109. macro
  110. .IR define
  111. is defined, the output shall contain the changes from the patch file;
  112. otherwise, the output shall not contain the patches specified in the
  113. patch file.
  114. .RE
  115. .IP "\fB\-e\fP" 10
  116. Interpret the patch file as an
  117. .IR ed
  118. script, rather than a
  119. .IR diff
  120. script.
  121. .IP "\fB\-i\ \fIpatchfile\fR" 10
  122. Read the patch information from the file named by the pathname
  123. .IR patchfile ,
  124. rather than the standard input.
  125. .IP "\fB\-l\fP" 10
  126. (The letter ell.) Cause any sequence of
  127. <blank>
  128. characters in the difference script to match any sequence of
  129. <blank>
  130. characters in the input file. Other characters shall be matched exactly.
  131. .IP "\fB\-n\fP" 10
  132. Interpret the script as a normal difference.
  133. .IP "\fB\-N\fP" 10
  134. Ignore patches where the differences have already been applied to the
  135. file; by default, already-applied patches shall be rejected.
  136. .IP "\fB\-o\ \fIoutfile\fR" 10
  137. Instead of modifying the files (specified by the
  138. .IR file
  139. operand or the difference listings) directly, write a copy of the file
  140. referenced by each patch, with the appropriate differences applied, to
  141. .IR outfile .
  142. Multiple patches for a single file shall be applied to the intermediate
  143. versions of the file created by any previous patches, and shall result
  144. in multiple, concatenated versions of the file being written to
  145. .IR outfile .
  146. .IP "\fB\-p\ \fInum\fR" 10
  147. For all pathnames in the patch file that indicate the names of files to
  148. be patched, delete
  149. .IR num
  150. pathname components from the beginning of each pathname. If the
  151. pathname in the patch file is absolute, any leading
  152. <slash>
  153. characters shall be considered the first component (that is,
  154. .BR "\-p\ 1"
  155. shall remove the leading
  156. <slash>
  157. characters). Specifying
  158. .BR "\-p\ 0"
  159. shall cause the full pathname to be used. If
  160. .BR \-p
  161. is not specified, only the basename (the final pathname component)
  162. shall be used.
  163. .IP "\fB\-R\fP" 10
  164. Reverse the sense of the patch script; that is, assume that the
  165. difference script was created from the new version to the old version.
  166. The
  167. .BR \-R
  168. option cannot be used with
  169. .IR ed
  170. scripts. The
  171. .IR patch
  172. utility shall attempt to reverse each portion of the script before
  173. applying it. Rejected differences shall be saved in swapped format. If
  174. this option is not specified, and until a portion of the patch file is
  175. successfully applied,
  176. .IR patch
  177. attempts to apply each portion in its reversed sense as well as in its
  178. normal sense. If the attempt is successful, the user shall be prompted
  179. to determine whether the
  180. .BR \-R
  181. option should be set.
  182. .IP "\fB\-r\ \fIrejectfile\fR" 10
  183. Override the default reject filename. In the default case, the reject
  184. file shall have the same name as the output file, with the suffix
  185. .BR .rej
  186. appended to it; see
  187. .IR "Patch Application".
  188. .IP "\fB\-u\fR" 10
  189. Interpret the patch file as a unified context difference (the output
  190. of the
  191. .IR diff
  192. utility when the
  193. .BR \-u
  194. or
  195. .BR \-U
  196. options are specified).
  197. .SH OPERANDS
  198. The following operand shall be supported:
  199. .IP "\fIfile\fR" 10
  200. A pathname of a file to patch.
  201. .SH STDIN
  202. See the INPUT FILES section.
  203. .SH "INPUT FILES"
  204. Input files shall be text files.
  205. .SH "ENVIRONMENT VARIABLES"
  206. The following environment variables shall affect the execution of
  207. .IR patch :
  208. .IP "\fILANG\fP" 10
  209. Provide a default value for the internationalization variables that are
  210. unset or null. (See the Base Definitions volume of POSIX.1\(hy2017,
  211. .IR "Section 8.2" ", " "Internationalization Variables"
  212. the precedence of internationalization variables used to determine the
  213. values of locale categories.)
  214. .IP "\fILC_ALL\fP" 10
  215. If set to a non-empty string value, override the values of all the
  216. other internationalization variables.
  217. .IP "\fILC_COLLATE\fP" 10
  218. .br
  219. Determine the locale for the behavior of ranges, equivalence classes,
  220. and multi-character collating elements used in the extended regular
  221. expression defined for the
  222. .BR yesexpr
  223. locale keyword in the
  224. .IR LC_MESSAGES
  225. category.
  226. .IP "\fILC_CTYPE\fP" 10
  227. Determine the locale for the interpretation of sequences of bytes of text
  228. data as characters (for example, single-byte as opposed to multi-byte
  229. characters in arguments and input files), and the behavior of character
  230. classes used in the extended regular expression defined for the
  231. .BR yesexpr
  232. locale keyword in the
  233. .IR LC_MESSAGES
  234. category.
  235. .IP "\fILC_MESSAGES\fP" 10
  236. .br
  237. Determine the locale used to process affirmative responses, and the
  238. locale used to affect the format and contents of diagnostic messages
  239. and prompts written to standard error.
  240. .IP "\fINLSPATH\fP" 10
  241. Determine the location of message catalogs for the processing of
  242. .IR LC_MESSAGES .
  243. .IP "\fILC_TIME\fP" 10
  244. Determine the locale for recognizing the format of file timestamps
  245. written by the
  246. .IR diff
  247. utility in a context-difference input file.
  248. .SH "ASYNCHRONOUS EVENTS"
  249. Default.
  250. .SH STDOUT
  251. Not used.
  252. .SH STDERR
  253. The standard error shall be used for diagnostic and informational
  254. messages.
  255. .SH "OUTPUT FILES"
  256. The output of the
  257. .IR patch
  258. utility, the save files (\c
  259. .BR .orig
  260. suffixes), and the reject files (\c
  261. .BR .rej
  262. suffixes) shall be text files.
  263. .SH "EXTENDED DESCRIPTION"
  264. A patch file may contain patching instructions for more than one file;
  265. filenames shall be determined as specified in
  266. .IR "Filename Determination".
  267. When the
  268. .BR \-b
  269. option is specified, for each patched file, the original shall be saved
  270. in a file of the same name with the suffix
  271. .BR .orig
  272. appended to it.
  273. .P
  274. For each patched file, a reject file may also be created as noted in
  275. .IR "Patch Application".
  276. In the absence of a
  277. .BR \-r
  278. option, the name of this file shall be formed by appending the suffix
  279. .BR .rej
  280. to the original filename.
  281. .SS "Patch File Format"
  282. .P
  283. The patch file shall contain zero or more lines of header information
  284. followed by one or more patches. Each patch shall contain zero or more
  285. lines of filename identification in the format produced by the
  286. .BR \-c ,
  287. .BR \-C ,
  288. .BR \-u ,
  289. or
  290. .BR \-U
  291. options of the
  292. .IR diff
  293. utility, and one or more sets of
  294. .IR diff
  295. output, which are customarily called \fIhunks\fP.
  296. .P
  297. The
  298. .IR patch
  299. utility shall recognize the following expression in the header
  300. information:
  301. .IP "\fBIndex:\ \fIpathname\fR" 6
  302. .br
  303. The file to be patched is named
  304. .IR pathname .
  305. .P
  306. If all lines (including headers) within a patch begin with the same
  307. leading sequence of
  308. <blank>
  309. characters, the
  310. .IR patch
  311. utility shall remove this sequence before proceeding. Within each
  312. patch, if the type of difference is common context, the
  313. .IR patch
  314. utility shall recognize the following expressions:
  315. .IP "***\ \fIfilename\ timestamp\fR" 6
  316. .br
  317. The patches arose from
  318. .IR filename .
  319. .IP "\-\|\-\|\-\ \fIfilename\ timestamp\fR" 6
  320. .br
  321. The patches should be applied to
  322. .IR filename .
  323. .P
  324. If the type of difference is unified context, the
  325. .IR patch
  326. utility shall recognize the following expressions:
  327. .IP "\-\|\-\|\-\ \fIfilename\ timestamp\fR" 6
  328. .br
  329. The patches arose from
  330. .IR filename .
  331. .IP "+\|+\|+\ \fIfilename\ timestamp\fR" 6
  332. .br
  333. The patches should be applied to
  334. .IR filename .
  335. .P
  336. Each hunk within a patch shall be the
  337. .IR diff
  338. output to change a line range within the original file. The line
  339. numbers for successive hunks within a patch shall occur in ascending
  340. order.
  341. .SS "Filename Determination"
  342. .P
  343. If no
  344. .IR file
  345. operand is specified,
  346. .IR patch
  347. shall perform the following steps to determine the filename to use:
  348. .IP " 1." 4
  349. If the type of
  350. .IR diff
  351. is context, the
  352. .IR patch
  353. utility shall delete pathname components (as specified by the
  354. .BR \-p
  355. option) from the filename on the line beginning with
  356. .BR \(dq***\(dq
  357. (if copied context) or
  358. .BR \(dq---\(dq
  359. (if unified context), then test for the existence of this file relative
  360. to the current directory (or the directory specified with the
  361. .BR \-d
  362. option). If the file exists, the
  363. .IR patch
  364. utility shall use this filename.
  365. .IP " 2." 4
  366. If the type of
  367. .IR diff
  368. is context, the
  369. .IR patch
  370. utility shall delete the pathname components (as specified by the
  371. .BR \-p
  372. option) from the filename on the line beginning with
  373. .BR \(dq---\(dq
  374. (if copied context) or
  375. .BR \(dq+\|+\|+\(dq
  376. (if unified context), then test for the existence of this file relative
  377. to the current directory (or the directory specified with the
  378. .BR \-d
  379. option). If the file exists, the
  380. .IR patch
  381. utility shall use this filename.
  382. .IP " 3." 4
  383. If the header information contains a line beginning with the string
  384. .BR Index: ,
  385. the
  386. .IR patch
  387. utility shall delete pathname components (as specified by the
  388. .BR \-p
  389. option) from this line, then test for the existence of this file
  390. relative to the current directory (or the directory specified with the
  391. .BR \-d
  392. option). If the file exists, the
  393. .IR patch
  394. utility shall use this filename.
  395. .IP " 4." 4
  396. If an
  397. .BR SCCS
  398. directory exists in the current directory,
  399. .IR patch
  400. shall attempt to perform a
  401. .IR get
  402. .BR \-e
  403. .BR SCCS/s. \c
  404. .IR filename
  405. command to retrieve an editable version of the file. If the file
  406. exists, the
  407. .IR patch
  408. utility shall use this filename.
  409. .IP " 5." 4
  410. The
  411. .IR patch
  412. utility shall write a prompt to standard output and request a filename
  413. interactively from the controlling terminal (for example,
  414. .BR /dev/tty ).
  415. .SS "Patch Application"
  416. .P
  417. If the
  418. .BR \-c ,
  419. .BR \-e ,
  420. .BR \-n ,
  421. or
  422. .BR \-u
  423. option is present, the
  424. .IR patch
  425. utility shall interpret information within each hunk as a copied context
  426. difference, an
  427. .IR ed
  428. difference, a normal difference, or a unified context difference,
  429. respectively. In the absence of any of these options, the
  430. .IR patch
  431. utility shall determine the type of difference based on the format of
  432. information within the hunk.
  433. .P
  434. For each hunk, the
  435. .IR patch
  436. utility shall begin to search for the place to apply the patch at the
  437. line number at the beginning of the hunk, plus or minus any offset used
  438. in applying the previous hunk. If lines matching the hunk context are
  439. not found,
  440. .IR patch
  441. shall scan both forwards and backwards at least 1\|000 bytes for a set
  442. of lines that match the hunk context.
  443. .P
  444. If no such place is found and it is a context difference, then another
  445. scan shall take place, ignoring the first and last line of context. If
  446. that fails, the first two and last two lines of context shall be
  447. ignored and another scan shall be made. Implementations may search
  448. more extensively for installation locations.
  449. .P
  450. If no location can be found, the
  451. .IR patch
  452. utility shall append the hunk to the reject file. A rejected hunk that
  453. is a copied context difference, an
  454. .IR ed
  455. difference, or a normal difference shall be written in
  456. copied-context-difference format regardless of the format of the patch
  457. file. It is implementation-defined whether a rejected hunk that is
  458. a unified context difference is written in copied-context-difference
  459. format or in unified-context-difference format.
  460. If the input was a normal or
  461. .IR ed -style
  462. difference, the reject file may contain differences with zero lines of
  463. context. The line numbers on the hunks in the reject file may be
  464. different from the line numbers in the patch file since they shall
  465. reflect the approximate locations for the failed hunks in the new file
  466. rather than the old one.
  467. .P
  468. If the type of patch is an
  469. .IR ed
  470. diff, the implementation may accomplish the patching by invoking the
  471. .IR ed
  472. utility.
  473. .SH "EXIT STATUS"
  474. The following exit values shall be returned:
  475. .IP "\00" 6
  476. Successful completion.
  477. .IP "\01" 6
  478. One or more lines were written to a reject file.
  479. .IP >1 6
  480. An error occurred.
  481. .SH "CONSEQUENCES OF ERRORS"
  482. Patches that cannot be correctly placed in the file shall be written to
  483. a reject file.
  484. .LP
  485. .IR "The following sections are informative."
  486. .SH "APPLICATION USAGE"
  487. The
  488. .BR \-R
  489. option does not work with
  490. .IR ed
  491. scripts because there is too little information to reconstruct the
  492. reverse operation.
  493. .P
  494. The
  495. .BR \-p
  496. option makes it possible to customize a patch file to local user
  497. directory structures without manually editing the patch file. For
  498. example, if the filename in the patch file was:
  499. .sp
  500. .RS 4
  501. .nf
  502. /curds/whey/src/blurfl/blurfl.c
  503. .fi
  504. .P
  505. .RE
  506. .P
  507. Setting
  508. .BR "\-p\ 0"
  509. gives the entire pathname unmodified;
  510. .BR "\-p\ 1"
  511. gives:
  512. .sp
  513. .RS 4
  514. .nf
  515. curds/whey/src/blurfl/blurfl.c
  516. .fi
  517. .P
  518. .RE
  519. .P
  520. without the leading
  521. <slash>,
  522. .BR "\-p\ 4"
  523. gives:
  524. .sp
  525. .RS 4
  526. .nf
  527. blurfl/blurfl.c
  528. .fi
  529. .P
  530. .RE
  531. .P
  532. and not specifying
  533. .BR \-p
  534. at all gives:
  535. .sp
  536. .RS 4
  537. .nf
  538. blurfl.c .
  539. .fi
  540. .P
  541. .RE
  542. .SH EXAMPLES
  543. None.
  544. .SH RATIONALE
  545. Some of the functionality in historical
  546. .IR patch
  547. implementations was not specified. The following documents those
  548. features present in historical implementations that have not been
  549. specified.
  550. .P
  551. A deleted piece of functionality was the
  552. .BR '\(pl'
  553. pseudo-option allowing an additional set of options and a patch file
  554. operand to be given. This was seen as being insufficiently useful to
  555. standardize.
  556. .P
  557. In historical implementations, if the string
  558. .BR \(dqPrereq:\(dq
  559. appeared in the header, the
  560. .IR patch
  561. utility would search for the corresponding version information (the
  562. string specified in the header, delimited by
  563. <blank>
  564. characters or the beginning or end of a line or the file) anywhere in
  565. the original file. This was deleted as too simplistic and insufficiently
  566. trustworthy a mechanism to standardize. For example, if:
  567. .sp
  568. .RS 4
  569. .nf
  570. Prereq: 1.2
  571. .fi
  572. .P
  573. .RE
  574. .P
  575. were in the header, the presence of a delimited 1.2 anywhere in the
  576. file would satisfy the prerequisite.
  577. .P
  578. The following options were dropped from historical implementations of
  579. .IR patch
  580. as insufficiently useful to standardize:
  581. .IP "\fB\-b\fP" 10
  582. The
  583. .BR \-b
  584. option historically provided a method for changing the name extension
  585. of the backup file from the default
  586. .BR .orig .
  587. This option has been modified and retained in this volume of POSIX.1\(hy2017.
  588. .IP "\fB\-F\fP" 10
  589. The
  590. .BR \-F
  591. option specified the number of lines of a context diff to ignore when
  592. searching for a place to install a patch.
  593. .IP "\fB\-f\fP" 10
  594. The
  595. .BR \-f
  596. option historically caused
  597. .IR patch
  598. not to request additional information from the user.
  599. .IP "\fB\-r\fP" 10
  600. The
  601. .BR \-r
  602. option historically provided a method of overriding the extension of
  603. the reject file from the default
  604. .BR .rej .
  605. .IP "\fB\-s\fP" 10
  606. The
  607. .BR \-s
  608. option historically caused
  609. .IR patch
  610. to work silently unless an error occurred.
  611. .IP "\fB\-x\fP" 10
  612. The
  613. .BR \-x
  614. option historically set internal debugging flags.
  615. .P
  616. In some file system implementations, the saving of a
  617. .BR .orig
  618. file may produce unwanted results. In the case of 12, 13, or
  619. 14-character filenames (on file systems supporting 14-character
  620. maximum filenames), the
  621. .BR .orig
  622. file overwrites the new file. The reject file may also exceed this
  623. filename limit. It was suggested, due to some historical practice,
  624. that a
  625. <tilde>
  626. (\c
  627. .BR '\(ti' )
  628. suffix be used instead of
  629. .BR .orig
  630. and some other character instead of the
  631. .BR .rej
  632. suffix. This was rejected because it is not obvious to the user which
  633. file is which. The suffixes
  634. .BR .orig
  635. and
  636. .BR .rej
  637. are clearer and more understandable.
  638. .P
  639. The
  640. .BR \-b
  641. option has the opposite sense in some historical implementations\(emdo
  642. not save the
  643. .BR .orig
  644. file. The default case here is not to save the files, making
  645. .IR patch
  646. behave more consistently with the other standard utilities.
  647. .P
  648. The
  649. .BR \-w
  650. option in early proposals was changed to
  651. .BR \-l
  652. to match historical practice.
  653. .P
  654. The
  655. .BR \-N
  656. option was included because without it, a non-interactive application
  657. cannot reject previously applied patches. For example, if a user is
  658. piping the output of
  659. .IR diff
  660. into the
  661. .IR patch
  662. utility, and the user only wants to patch a file to a newer version
  663. non-interactively, the
  664. .BR \-N
  665. option is required.
  666. .P
  667. Changes to the
  668. .BR \-l
  669. option description were proposed to allow matching across
  670. <newline>
  671. characters in addition to just
  672. <blank>
  673. characters. Since this is not historical practice, and since some
  674. ambiguities could result, it is suggested that future developments in
  675. this area utilize another option letter, such as
  676. .BR \-L .
  677. .P
  678. The
  679. .BR \-u
  680. option of GNU
  681. .IR patch
  682. has been added, along with support for unified context formats.
  683. .SH "FUTURE DIRECTIONS"
  684. None.
  685. .SH "SEE ALSO"
  686. .IR "\fIdiff\fR\^",
  687. .IR "\fIed\fR\^"
  688. .P
  689. The Base Definitions volume of POSIX.1\(hy2017,
  690. .IR "Chapter 8" ", " "Environment Variables",
  691. .IR "Section 12.2" ", " "Utility Syntax Guidelines"
  692. .\"
  693. .SH COPYRIGHT
  694. Portions of this text are reprinted and reproduced in electronic form
  695. from IEEE Std 1003.1-2017, Standard for Information Technology
  696. -- Portable Operating System Interface (POSIX), The Open Group Base
  697. Specifications Issue 7, 2018 Edition,
  698. Copyright (C) 2018 by the Institute of
  699. Electrical and Electronics Engineers, Inc and The Open Group.
  700. In the event of any discrepancy between this version and the original IEEE and
  701. The Open Group Standard, the original IEEE and The Open Group Standard
  702. is the referee document. The original Standard can be obtained online at
  703. http://www.opengroup.org/unix/online.html .
  704. .PP
  705. Any typographical or formatting errors that appear
  706. in this page are most likely
  707. to have been introduced during the conversion of the source files to
  708. man page format. To report such errors, see
  709. https://www.kernel.org/doc/man-pages/reporting_bugs.html .