]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - misc/mntent_r.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / misc / mntent_r.c
index 6959f0e21d53f62cc048f66997ee7c62704fd8da..4ca42e6dbc64eef048d6f1eb1433fb74b2d3526c 100644 (file)
@@ -1,6 +1,5 @@
 /* Utilities for reading/writing fstab, mtab, etc.
-   Copyright (C) 1995-2000, 2001, 2002, 2003, 2006, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1995-2016 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -14,9 +13,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <alloca.h>
 #include <mntent.h>
 #include <string.h>
 #include <sys/types.h>
 
-#ifdef USE_IN_LIBIO
-# define flockfile(s) _IO_flockfile (s)
-# define funlockfile(s) _IO_funlockfile (s)
-#endif
+#define flockfile(s) _IO_flockfile (s)
+#define funlockfile(s) _IO_funlockfile (s)
 
 #undef __setmntent
 #undef __endmntent
@@ -40,10 +36,10 @@ FILE *
 __setmntent (const char *file, const char *mode)
 {
   /* Extend the mode parameter with "c" to disable cancellation in the
-     I/O functions.  */
+     I/O functions and "e" to set FD_CLOEXEC.  */
   size_t modelen = strlen (mode);
-  char newmode[modelen + 2];
-  memcpy (mempcpy (newmode, mode, modelen), "c", 2);
+  char newmode[modelen + 3];
+  memcpy (mempcpy (newmode, mode, modelen), "ce", 3);
   FILE *result = fopen (file, newmode);
 
   if (result != NULL)
@@ -52,7 +48,7 @@ __setmntent (const char *file, const char *mode)
 
   return result;
 }
-INTDEF(__setmntent)
+libc_hidden_def (__setmntent)
 weak_alias (__setmntent, setmntent)
 
 
@@ -64,7 +60,7 @@ __endmntent (FILE *stream)
     fclose (stream);
   return 1;            /* SunOS 4.x says to always return 1 */
 }
-INTDEF(__endmntent)
+libc_hidden_def (__endmntent)
 weak_alias (__endmntent, endmntent)
 
 
@@ -131,7 +127,7 @@ __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
     {
       char *end_ptr;
 
-      if (fgets_unlocked (buffer, bufsiz, stream) == NULL)
+      if (__fgets_unlocked (buffer, bufsiz, stream) == NULL)
        {
          funlockfile (stream);
          return NULL;
@@ -139,12 +135,18 @@ __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
 
       end_ptr = strchr (buffer, '\n');
       if (end_ptr != NULL)     /* chop newline */
-       *end_ptr = '\0';
+       {
+         /* Do not walk past the start of buffer if it's all whitespace.  */
+         while (end_ptr != buffer
+                && (end_ptr[-1] == ' ' || end_ptr[-1] == '\t'))
+            end_ptr--;
+         *end_ptr = '\0';
+       }
       else
        {
          /* Not the whole line was read.  Do it now but forget it.  */
          char tmp[1024];
-         while (fgets_unlocked (tmp, sizeof tmp, stream) != NULL)
+         while (__fgets_unlocked (tmp, sizeof tmp, stream) != NULL)
            if (strchr (tmp, '\n') != NULL)
              break;
        }
@@ -181,7 +183,7 @@ __getmntent_r (FILE *stream, struct mntent *mp, char *buffer, int bufsiz)
 
   return mp;
 }
-INTDEF(__getmntent_r)
+libc_hidden_def (__getmntent_r)
 weak_alias (__getmntent_r, getmntent_r)