/* 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
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;
}
return mp;
}
-INTDEF(__getmntent_r)
+libc_hidden_def (__getmntent_r)
weak_alias (__getmntent_r, getmntent_r)