]> git.ipfire.org Git - thirdparty/glibc.git/blame - shadow/fgetspent_r.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / shadow / fgetspent_r.c
CommitLineData
d4697bc9 1/* Copyright (C) 1996-2014 Free Software Foundation, Inc.
19361cb7
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
19361cb7
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
19361cb7 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
267ca16a
UD
17
18#include <ctype.h>
d71b808a 19#include <errno.h>
267ca16a
UD
20#include <shadow.h>
21#include <stdio.h>
22
3ce1f295
UD
23#define flockfile(s) _IO_flockfile (s)
24#define funlockfile(s) _IO_funlockfile (s)
50304ef0 25
267ca16a
UD
26/* Define a line parsing function using the common code
27 used in the nss_files module. */
28
29#define STRUCTURE spwd
30#define ENTNAME spent
31#define EXTERN_PARSER 1
32struct spent_data {};
33
d71b808a 34#include <nss/nss_files/files-parse.c>
267ca16a
UD
35
36
37/* Read one shadow entry from the given stream. */
ba1ffaa1
UD
38int
39__fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
40 struct spwd **result)
267ca16a
UD
41{
42 char *p;
43
50304ef0 44 flockfile (stream);
267ca16a
UD
45 do
46 {
31f7410f 47 buffer[buflen - 1] = '\xff';
50304ef0
UD
48 p = fgets_unlocked (buffer, buflen, stream);
49 if (p == NULL && feof_unlocked (stream))
b4012b75 50 {
50304ef0 51 funlockfile (stream);
b4012b75 52 *result = NULL;
26cee9a4 53 __set_errno (ENOENT);
b4012b75
UD
54 return errno;
55 }
31f7410f 56 if (p == NULL || buffer[buflen - 1] != '\xff')
af69217f 57 {
50304ef0 58 funlockfile (stream);
af69217f 59 *result = NULL;
e1c6ee83
UD
60 __set_errno (ERANGE);
61 return errno;
af69217f 62 }
267ca16a
UD
63
64 /* Skip leading blanks. */
65 while (isspace (*p))
66 ++p;
67 } while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
68 /* Parse the line. If it is invalid, loop to
69 get the next line of the file to parse. */
7ba4fcfc 70 ! parse_line (buffer, (void *) resbuf, NULL, 0, &errno));
267ca16a 71
50304ef0
UD
72 funlockfile (stream);
73
ba1ffaa1
UD
74 *result = resbuf;
75 return 0;
267ca16a
UD
76}
77weak_alias (__fgetspent_r, fgetspent_r)