Back to index

glibc  2.9
fgetspent_r.c
Go to the documentation of this file.
00001 /* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <ctype.h>
00020 #include <errno.h>
00021 #include <shadow.h>
00022 #include <stdio.h>
00023 
00024 #ifdef USE_IN_LIBIO
00025 # define flockfile(s) _IO_flockfile (s)
00026 # define funlockfile(s) _IO_funlockfile (s)
00027 #endif
00028 
00029 /* Define a line parsing function using the common code
00030    used in the nss_files module.  */
00031 
00032 #define STRUCTURE    spwd
00033 #define ENTNAME             spent
00034 #define       EXTERN_PARSER 1
00035 struct spent_data {};
00036 
00037 #include <nss/nss_files/files-parse.c>
00038 
00039 
00040 /* Read one shadow entry from the given stream.  */
00041 int
00042 __fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
00043               struct spwd **result)
00044 {
00045   char *p;
00046 
00047   flockfile (stream);
00048   do
00049     {
00050       buffer[buflen - 1] = '\xff';
00051       p = fgets_unlocked (buffer, buflen, stream);
00052       if (p == NULL && feof_unlocked (stream))
00053        {
00054          funlockfile (stream);
00055          *result = NULL;
00056          __set_errno (ENOENT);
00057          return errno;
00058        }
00059       if (p == NULL || buffer[buflen - 1] != '\xff')
00060        {
00061          funlockfile (stream);
00062          *result = NULL;
00063          __set_errno (ERANGE);
00064          return errno;
00065        }
00066 
00067       /* Skip leading blanks.  */
00068       while (isspace (*p))
00069        ++p;
00070     } while (*p == '\0' || *p == '#' ||   /* Ignore empty and comment lines.  */
00071             /* Parse the line.  If it is invalid, loop to
00072               get the next line of the file to parse.  */
00073             ! parse_line (buffer, (void *) resbuf, NULL, 0, &errno));
00074 
00075   funlockfile (stream);
00076 
00077   *result = resbuf;
00078   return 0;
00079 }
00080 weak_alias (__fgetspent_r, fgetspent_r)