/* Utilities for reading/writing fstab, mtab, etc.
- Copyright (C) 1995-2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1995-2019 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
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
__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)
return result;
}
-INTDEF(__setmntent)
+libc_hidden_def (__setmntent)
weak_alias (__setmntent, setmntent)
fclose (stream);
return 1; /* SunOS 4.x says to always return 1 */
}
-INTDEF(__endmntent)
+libc_hidden_def (__endmntent)
weak_alias (__endmntent, endmntent)
{
char *end_ptr;
- if (fgets_unlocked (buffer, bufsiz, stream) == NULL)
+ if (__fgets_unlocked (buffer, bufsiz, stream) == NULL)
{
funlockfile (stream);
return NULL;
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;
}
{
case 0:
mp->mnt_freq = 0;
+ /* Fall through. */
case 1:
mp->mnt_passno = 0;
+ /* Fall through. */
case 2:
break;
}
return mp;
}
-INTDEF(__getmntent_r)
+libc_hidden_def (__getmntent_r)
weak_alias (__getmntent_r, getmntent_r)
const char *rp = name; \
\
while (*rp != '\0') \
- if (*rp == ' ' || *rp == '\t' || *rp == '\\') \
+ if (*rp == ' ' || *rp == '\t' || *rp == '\n' || *rp == '\\') \
break; \
else \
++rp; \
if (*rp != '\0') \
{ \
/* In the worst case the length of the string can increase to \
- founr times the current length. */ \
+ four times the current length. */ \
char *wp; \
\
rp = name; \
mntcopy.mnt_type,
mntcopy.mnt_opts,
mntcopy.mnt_freq,
- mntcopy.mnt_passno)
- < 0 ? 1 : 0);
+ mntcopy.mnt_passno) < 0
+ || fflush (stream) != 0);
}
weak_alias (__addmntent, addmntent)
while ((p = strstr (rest, opt)) != NULL)
{
- if (p == rest
- || (p[-1] == ','
- && (p[optlen] == '\0' ||
- p[optlen] == '=' ||
- p[optlen] == ',')))
+ if ((p == rest || p[-1] == ',')
+ && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ','))
return p;
- rest = strchr (rest, ',');
+ rest = strchr (p, ',');
if (rest == NULL)
break;
++rest;
return NULL;
}
+libc_hidden_def (__hasmntopt)
weak_alias (__hasmntopt, hasmntopt)