Update Russian translations
[glibc.git] / shadow / putspent.c
bloba6ab4a947991aed4f8f9f6a27d9a18812c81de7d
1 /* Copyright (C) 1991-2014 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, see
16 <http://www.gnu.org/licenses/>. */
18 #include <stdio.h>
19 #include <shadow.h>
21 #define flockfile(s) _IO_flockfile (s)
22 #define funlockfile(s) _IO_funlockfile (s)
24 #define _S(x) x ? x : ""
27 /* Write an entry to the given stream.
28 This must know the format of the password file. */
29 int
30 putspent (const struct spwd *p, FILE *stream)
32 int errors = 0;
34 flockfile (stream);
36 if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
37 ++errors;
39 if ((p->sp_lstchg != (long int) -1
40 && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
41 || (p->sp_lstchg == (long int) -1
42 && putc_unlocked (':', stream) == EOF))
43 ++errors;
45 if ((p->sp_min != (long int) -1
46 && fprintf (stream, "%ld:", p->sp_min) < 0)
47 || (p->sp_min == (long int) -1
48 && putc_unlocked (':', stream) == EOF))
49 ++errors;
51 if ((p->sp_max != (long int) -1
52 && fprintf (stream, "%ld:", p->sp_max) < 0)
53 || (p->sp_max == (long int) -1
54 && putc_unlocked (':', stream) == EOF))
55 ++errors;
57 if ((p->sp_warn != (long int) -1
58 && fprintf (stream, "%ld:", p->sp_warn) < 0)
59 || (p->sp_warn == (long int) -1
60 && putc_unlocked (':', stream) == EOF))
61 ++errors;
63 if ((p->sp_inact != (long int) -1
64 && fprintf (stream, "%ld:", p->sp_inact) < 0)
65 || (p->sp_inact == (long int) -1
66 && putc_unlocked (':', stream) == EOF))
67 ++errors;
69 if ((p->sp_expire != (long int) -1
70 && fprintf (stream, "%ld:", p->sp_expire) < 0)
71 || (p->sp_expire == (long int) -1
72 && putc_unlocked (':', stream) == EOF))
73 ++errors;
75 if (p->sp_flag != ~0ul
76 && fprintf (stream, "%ld", p->sp_flag) < 0)
77 ++errors;
79 if (putc_unlocked ('\n', stream) == EOF)
80 ++errors;
82 funlockfile (stream);
84 return errors ? -1 : 0;