]> git.ipfire.org Git - thirdparty/glibc.git/blame - grp/putgrent.c
Update.
[thirdparty/glibc.git] / grp / putgrent.c
CommitLineData
a711dd4b 1/* Copyright (C) 1991, 92, 96, 98, 99, 2000 Free Software Foundation, Inc.
7ce241a0
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
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
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/* Write an entry to the given stream.
31 This must know the format of the group file. */
32int
33putgrent (gr, stream)
34 const struct group *gr;
35 FILE *stream;
36{
37 int retval;
38
a711dd4b 39 if (__builtin_expect (gr == NULL, 0) || __builtin_expect (stream == NULL, 0))
7ce241a0
UD
40 {
41 __set_errno (EINVAL);
42 return -1;
43 }
44
45 flockfile (stream);
46
47 retval = fprintf (stream, "%s:%s:%u:",
48 gr->gr_name, _S (gr->gr_passwd), gr->gr_gid);
a711dd4b
UD
49 if (__builtin_expect (retval, 0) < 0)
50 {
51 funlockfile (stream);
52 return -1;
53 }
7ce241a0
UD
54
55 if (gr->gr_mem != NULL)
56 {
57 int i;
58
59 for (i = 0 ; gr->gr_mem[i] != NULL; i++)
8ba3c7d9 60 if (fprintf (stream, i == 0 ? "%s" : ",%s", gr->gr_mem[i]) < 0)
7ce241a0
UD
61 {
62 /* What else can we do? */
63 funlockfile (stream);
64 return -1;
65 }
66 }
67
68 retval = fputc_unlocked ('\n', stream);
69
70 funlockfile (stream);
71
72 return retval < 0 ? -1 : 0;
73}