[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GNU patch not completely posix compliant in --posix mode
From: |
Adrian Bunk |
Subject: |
GNU patch not completely posix compliant in --posix mode |
Date: |
Fri, 30 Nov 2001 20:12:54 +0100 (CET) |
Hi Paul,
Peter Maydell <address@hidden> sent the following report:
<-- snip -->
The POSIX specs for the patch utility say:
(POSIX 2, page 588, section 5.22.7.2, part (1))
# If the patch contains the strings *** and ---, the patch utility shall
# strip components from the beginning of each pathname (depending on the
# presence or value of the -p option), then test for the existence of
# both files in the current directory (or the directory specified by
# the -d option). If both files exist, the patch utility shall assume
# that no pathname can be obtained from this step.
However, GNU patch (with --posix specified) will use the --- (OLD)
name even if both old and new files exist; that is, it's not following
the last sentence of the quoted paragraph.
Here's a patch against 2.5.4 which fixes this. It doesn't attempt
to modify the non-posix mode behaviour at all (which I think is
perverse, but hey (see also PR 49481).
hope this helps
Peter Maydell
===begin===
--- pch.c.orig Thu Nov 29 16:19:02 2001
+++ pch.c Thu Nov 29 16:29:13 2001
@@ -497,6 +497,8 @@
Consider the file names to be in the order (old, new, index).
- If some named files exist, use the first one if posixly_correct
is nonzero, the best one otherwise.
+ - Exception: if posixly_correct and both old and new files exist
+ then they should both be ignored
- If patch_get is nonzero, and no named files exist,
but an RCS or SCCS master file exists,
use the first named file with an RCS or SCCS master.
@@ -532,13 +534,25 @@
else if (stat (name[i], &st[i]) != 0)
stat_errno[i] = errno;
else
- {
- stat_errno[i] = 0;
- if (posixly_correct)
- break;
- }
+ stat_errno[i] = 0;
+
i0 = i;
}
+
+ if (posixly_correct)
+ {
+ /* Take the first existing entry in (old, new, index), with the
+ * exception that if old and new both specify files which exist
+ * then we should assume that no pathnames were given for old
+ * and new. [See IEEE Std. 1003.2-1992 section 5.22.7.2 part (1)]
+ */
+ i = OLD;
+ if (name[OLD] && name[NEW] && !stat_errno[OLD] && !stat_errno[NEW])
+ i = INDEX;
+ for ( ; i <= INDEX; i++)
+ if (name[i] && !stat_errno[i])
+ break;
+ }
if (! posixly_correct)
{
===endit===
===begin===
--- patch.man.orig Thu Nov 29 16:47:01 2001
+++ patch.man Thu Nov 29 16:53:01 2001
@@ -177,9 +177,17 @@
selects a file name from the candidate list as follows:
.TP 3
.B " \(bu"
+If
+.B patch
+is conforming to \s-1POSIX\s0,
+and the old and new names both name files which exist,
+then patch will ignore both old and new names (as if
+the patch file had never specified them).
+.TP
+.B " \(bu"
If some of the named files exist,
.B patch
-selects the first name if conforming to \s-1POSIX\s0,
+selects the first existing name if conforming to \s-1POSIX\s0,
and the best name otherwise.
.TP
.B " \(bu"
===endit===
<-- snip -->
cu
Adrian
--
Get my GPG key: finger address@hidden | gpg --import
Fingerprint: B29C E71E FE19 6755 5C8A 84D4 99FC EA98 4F12 B400
- GNU patch not completely posix compliant in --posix mode,
Adrian Bunk <=