OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / pwd_grp / pwd_grp_internal.c
1 /*
2  * Copyright (C) 2003     Manuel Novoa III
3  *
4  * Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
5  */
6
7 /*  Nov 6, 2003  Initial version.
8  *
9  *  NOTE: This implementation is quite strict about requiring all
10  *    field seperators.  It also does not allow leading whitespace
11  *    except when processing the numeric fields.  glibc is more
12  *    lenient.  See the various glibc difference comments below.
13  *
14  *  TODO:
15  *    Move to dynamic allocation of (currently staticly allocated)
16  *      buffers; especially for the group-related functions since
17  *      large group member lists will cause error returns.
18  *
19  */
20
21 #define _GNU_SOURCE
22 #include <features.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <stddef.h>
28 #include <errno.h>
29 #include <assert.h>
30 #include <ctype.h>
31 #include <pwd.h>
32 #include <grp.h>
33 #include <paths.h>
34 #ifdef __HAS_SHADOW__
35 #include <shadow.h>
36 #endif
37 #ifdef __UCLIBC_HAS_THREADS__
38 #include <pthread.h>
39 #endif
40
41 /**********************************************************************/
42 /* Sizes for staticly allocated buffers. */
43
44 /* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
45  * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
46 #define PWD_BUFFER_SIZE 256
47 #define GRP_BUFFER_SIZE 256
48
49 /**********************************************************************/
50 /* Prototypes for internal functions. */
51
52 #ifndef GETXXKEY_R_FUNC
53 #error GETXXKEY_R_FUNC is not defined!
54 #endif
55 /**********************************************************************/
56 #ifdef GETXXKEY_R_FUNC
57
58 int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
59                                         GETXXKEY_R_ENTTYPE *__restrict resultbuf,
60                                         char *__restrict buffer, size_t buflen,
61                                         GETXXKEY_R_ENTTYPE **__restrict result)
62 {
63         FILE *stream;
64         int rv;
65
66         *result = NULL;
67
68         if (!(stream = fopen(DO_GETXXKEY_R_PATHNAME, "r"))) {
69                 rv = errno;
70         } else {
71                 __STDIO_SET_USER_LOCKING(stream);
72                 do {
73                         if (!(rv = __pgsreader(GETXXKEY_R_PARSER, resultbuf,
74                                                                    buffer, buflen, stream))
75                                 ) {
76                                 if (GETXXKEY_R_TEST(resultbuf)) { /* Found key? */
77                                         *result = resultbuf;
78                                         break;
79                                 }
80                         } else {
81                                 if (rv == ENOENT) {     /* end-of-file encountered. */
82                                         rv = 0;
83                                 }
84                                 break;
85                         }
86                 } while (1);
87                 fclose(stream);
88         }
89
90         return rv;
91 }
92 libc_hidden_proto(GETXXKEY_R_FUNC)
93 libc_hidden_def(GETXXKEY_R_FUNC)
94
95 #endif
96 /**********************************************************************/
97 #undef GETXXKEY_R_FUNC_HIDDEN
98 #undef GETXXKEY_R_FUNC
99 #undef GETXXKEY_R_PARSER
100 #undef GETXXKEY_R_ENTTYPE
101 #undef GETXXKEY_R_TEST
102 #undef DO_GETXXKEY_R_KEYTYPE
103 #undef DO_GETXXKEY_R_PATHNAME