]> Savannah Git Hosting - gnulib.git/commitdiff
Update comments that refer to POSIX.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Sep 2019 15:46:43 +0000 (17:46 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Sep 2019 15:46:43 +0000 (17:46 +0200)
* lib/creat.c, lib/fopen.c, lib/open.c, lib/openat.c: Cite the relevant
sentence about trailing slashes.
* lib/fflush.c: Clarify the reasoning.
* tests/test-fflush2.c: Cite the relevant sentence.

ChangeLog
lib/creat.c
lib/fflush.c
lib/fopen.c
lib/open.c
lib/openat.c
tests/test-fflush2.c

index cde7792e1a9e7bbc42ef7a772af554f192746731..51812c5650c8ab98edefb7ad129daf77ed30df57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-09-28  Bruno Haible  <bruno@clisp.org>
+
+       Update comments that refer to POSIX.
+       * lib/creat.c, lib/fopen.c, lib/open.c, lib/openat.c: Cite the relevant
+       sentence about trailing slashes.
+       * lib/fflush.c: Clarify the reasoning.
+       * tests/test-fflush2.c: Cite the relevant sentence.
+
 2019-09-28  Bruno Haible  <bruno@clisp.org>
 
        access: Document limitations on Windows.
index e63b21957642aa4b718d711c7b9c1a355fa2aa67..4b075e12c1697a01467a2301db661905c7b351b2 100644 (file)
@@ -46,7 +46,11 @@ creat (const char *filename, mode_t mode)
 #if OPEN_TRAILING_SLASH_BUG
   /* Fail if the filename ends in a slash,
      as POSIX says such a filename must name a directory
-     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>.
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      creat() is defined as being equivalent to open() with flags
      O_CREAT | O_TRUNC | O_WRONLY.  Therefore:
      If the named file already exists as a directory, then creat() must fail
index 63862be19e5060f57fe12fca46b2b8fecb31bcb3..d5d9f305b0a2cd85e0dc1e1f9544da1cf3c94c20 100644 (file)
@@ -159,8 +159,9 @@ rpl_fflush (FILE *stream)
 
 #else
   {
-    /* Notes about the file-position indicator:
-       1) The file position indicator is incremented by fgetc() and decremented
+    /* What POSIX says:
+       1) About the file-position indicator (-> fseeko, ftello):
+          The file position indicator is incremented by fgetc() and decremented
           by ungetc():
           <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fgetc.html>
             "... the fgetc() function shall ... advance the associated file
@@ -172,8 +173,14 @@ rpl_fflush (FILE *stream)
           <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>
             "...any characters pushed back onto the stream by ungetc()
              or ungetwc() that have not subsequently been read from the
-             stream shall be discarded (without further changing the
-             file offset)."  */
+             stream shall be discarded..."
+          This implies implicitly: fflush does not change the file position
+          indicator.
+       3) Effects on the file descriptor, if the file descriptor is capable of
+          seeking:
+          <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>
+            "...the file offset of the underlying open file description shall
+             be set to the file position of the stream..."  */
 
     /* POSIX does not specify fflush behavior for non-seekable input
        streams.  Some implementations purge unread data, some return
index 07e38917965ac285e8c48738e09eacf34450bc1d..69ba5b968c5548b32c2cb6e2f14553c5759e5e96 100644 (file)
@@ -55,7 +55,11 @@ rpl_fopen (const char *filename, const char *mode)
 #if FOPEN_TRAILING_SLASH_BUG
   /* Fail if the mode requires write access and the filename ends in a slash,
      as POSIX says such a filename must name a directory
-     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>.
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      If the named file already exists as a directory, then if a mode that
      requires write access is specified, fopen() must fail because POSIX
      <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html>
index 0623d381a2bddc5f92784d058f024b3e7fe00b68..0c2742bbda62c5026513cb8a82b0d8d79b2cb475 100644 (file)
@@ -94,7 +94,11 @@ open (const char *filename, int flags, ...)
 #if OPEN_TRAILING_SLASH_BUG
   /* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename
      ends in a slash, as POSIX says such a filename must name a directory
-     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>.
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      If the named file already exists as a directory, then
        - if O_CREAT is specified, open() must fail because of the semantics
          of O_CREAT,
@@ -164,6 +168,12 @@ open (const char *filename, int flags, ...)
 #if OPEN_TRAILING_SLASH_BUG
   /* If the filename ends in a slash and fd does not refer to a directory,
      then fail.
+     Rationale: POSIX says such a filename must name a directory
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      If the named file without the slash is not a directory, open() must fail
      with ENOTDIR.  */
   if (fd >= 0)
index 25ffd770e0047f8c47c259231f2c88a398cae3ba..8aaee49fd131b9ec9a4462ca614cf3fdfdfa5434 100644 (file)
@@ -84,7 +84,11 @@ rpl_openat (int dfd, char const *filename, int flags, ...)
 # if OPEN_TRAILING_SLASH_BUG
   /* Fail if one of O_CREAT, O_WRONLY, O_RDWR is specified and the filename
      ends in a slash, as POSIX says such a filename must name a directory
-     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>.
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      If the named file already exists as a directory, then
        - if O_CREAT is specified, open() must fail because of the semantics
          of O_CREAT,
@@ -130,6 +134,12 @@ rpl_openat (int dfd, char const *filename, int flags, ...)
 # if OPEN_TRAILING_SLASH_BUG
   /* If the filename ends in a slash and fd does not refer to a directory,
      then fail.
+     Rationale: POSIX says such a filename must name a directory
+     <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13>:
+       "A pathname that contains at least one non-<slash> character and that
+        ends with one or more trailing <slash> characters shall not be resolved
+        successfully unless the last pathname component before the trailing
+        <slash> characters names an existing directory"
      If the named file without the slash is not a directory, open() must fail
      with ENOTDIR.  */
   if (fd >= 0)
index e7bfa654d8b8e88a5a5f0bf076360c7b3aec01bd..4caf868a0eecd1be75fbfd7c574e6c0dea382496 100644 (file)
@@ -69,7 +69,10 @@ main (int argc, char **argv)
            according to the Austin Group's resolution on 2009-01-08.  */
         /* Check that fflush after a non-backup ungetc() call discards the
            ungetc buffer.  This is mandated by POSIX
-           <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>  */
+           <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fflush.html>:
+             "...any characters pushed back onto the stream by ungetc()
+              or ungetwc() that have not subsequently been read from the
+              stream shall be discarded..."  */
 
         c = fgetc (stdin);
         ASSERT (c == '#');