Remove support in configure for unsupported architectures
[glibc.git] / grp / putgrent.c
blob6d7dce9d739025664a9214ff1c7e883bb85a2e44
1 /* Copyright (C) 1991,92,96,98,99,2000,2005,2011 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
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.
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
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <stdio.h>
21 #include <grp.h>
23 #define flockfile(s) _IO_flockfile (s)
24 #define funlockfile(s) _IO_funlockfile (s)
26 #define _S(x) x ? x : ""
28 /* Write an entry to the given stream.
29 This must know the format of the group file. */
30 int
31 putgrent (gr, stream)
32 const struct group *gr;
33 FILE *stream;
35 int retval;
37 if (__builtin_expect (gr == NULL, 0) || __builtin_expect (stream == NULL, 0))
39 __set_errno (EINVAL);
40 return -1;
43 flockfile (stream);
45 if (gr->gr_name[0] == '+' || gr->gr_name[0] == '-')
46 retval = fprintf (stream, "%s:%s::",
47 gr->gr_name, _S (gr->gr_passwd));
48 else
49 retval = fprintf (stream, "%s:%s:%lu:",
50 gr->gr_name, _S (gr->gr_passwd),
51 (unsigned long int) gr->gr_gid);
52 if (__builtin_expect (retval, 0) < 0)
54 funlockfile (stream);
55 return -1;
58 if (gr->gr_mem != NULL)
60 int i;
62 for (i = 0 ; gr->gr_mem[i] != NULL; i++)
63 if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
65 /* What else can we do? */
66 funlockfile (stream);
67 return -1;
71 retval = fputc_unlocked ('\n', stream);
73 funlockfile (stream);
75 return retval < 0 ? -1 : 0;