1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19: #include <errno.h>
20: #include <stdio.h>
21: #include <grp.h>
22:
23: #ifdef USE_IN_LIBIO
24: # define flockfile(s) _IO_flockfile (s)
25: # define funlockfile(s) _IO_funlockfile (s)
26: #endif
27:
28: #define _S(x) x ? x : ""
29:
30:
31:
32: int
33: putgrent (gr, stream)
34: const struct group *gr;
35: FILE *stream;
36: {
37: int retval;
38:
39: if (__builtin_expect (gr == NULL, 0) || __builtin_expect (stream == NULL, 0))
40: {
41: __set_errno (EINVAL);
42: return -1;
43: }
44:
45: flockfile (stream);
46:
47: if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
48: retval = fprintf (stream, "%s:%s::",
49: gr->gr_name, _S (gr->gr_passwd));
50: else
51: retval = fprintf (stream, "%s:%s:%lu:",
52: gr->gr_name, _S (gr->gr_passwd),
53: (unsigned long int) gr->gr_gid);
54: if (__builtin_expect (retval, 0) < 0)
55: {
56: funlockfile (stream);
57: return -1;
58: }
59:
60: if (gr->gr_mem != NULL)
61: {
62: int i;
63:
64: for (i = 0 ; gr->gr_mem[i] != NULL; i++)
65: if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
66: {
67:
68: funlockfile (stream);
69: return -1;
70: }
71: }
72:
73: retval = fputc_unlocked ('\n', stream);
74:
75: funlockfile (stream);
76:
77: return retval < 0 ? -1 : 0;
78: }