]> git.ipfire.org Git - thirdparty/glibc.git/blame - shadow/putspent.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / shadow / putspent.c
CommitLineData
d4697bc9 1/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
19361cb7
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
41bdb6e2
AJ
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.
19361cb7
UD
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
41bdb6e2 12 Lesser General Public License for more details.
19361cb7 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
267ca16a 17
267ca16a
UD
18#include <stdio.h>
19#include <shadow.h>
20
3ce1f295
UD
21#define flockfile(s) _IO_flockfile (s)
22#define funlockfile(s) _IO_funlockfile (s)
7ce241a0
UD
23
24#define _S(x) x ? x : ""
25
267ca16a
UD
26
27/* Write an entry to the given stream.
28 This must know the format of the password file. */
29int
30putspent (const struct spwd *p, FILE *stream)
31{
32 int errors = 0;
33
7ce241a0
UD
34 flockfile (stream);
35
36 if (fprintf (stream, "%s:%s:", p->sp_namp, _S (p->sp_pwdp)) < 0)
267ca16a
UD
37 ++errors;
38
c4029823 39 if ((p->sp_lstchg != (long int) -1
569c558c 40 && fprintf (stream, "%ld:", p->sp_lstchg) < 0)
c4029823 41 || (p->sp_lstchg == (long int) -1
7ce241a0 42 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
43 ++errors;
44
c4029823 45 if ((p->sp_min != (long int) -1
569c558c 46 && fprintf (stream, "%ld:", p->sp_min) < 0)
c4029823 47 || (p->sp_min == (long int) -1
7ce241a0 48 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
49 ++errors;
50
c4029823 51 if ((p->sp_max != (long int) -1
569c558c 52 && fprintf (stream, "%ld:", p->sp_max) < 0)
c4029823 53 || (p->sp_max == (long int) -1
7ce241a0 54 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
55 ++errors;
56
c4029823 57 if ((p->sp_warn != (long int) -1
569c558c 58 && fprintf (stream, "%ld:", p->sp_warn) < 0)
c4029823 59 || (p->sp_warn == (long int) -1
7ce241a0 60 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
61 ++errors;
62
c4029823 63 if ((p->sp_inact != (long int) -1
569c558c 64 && fprintf (stream, "%ld:", p->sp_inact) < 0)
c4029823 65 || (p->sp_inact == (long int) -1
7ce241a0 66 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
67 ++errors;
68
c4029823 69 if ((p->sp_expire != (long int) -1
569c558c 70 && fprintf (stream, "%ld:", p->sp_expire) < 0)
c4029823 71 || (p->sp_expire == (long int) -1
7ce241a0 72 && putc_unlocked (':', stream) == EOF))
267ca16a
UD
73 ++errors;
74
11336c16
UD
75 if (p->sp_flag != ~0ul
76 && fprintf (stream, "%ld", p->sp_flag) < 0)
267ca16a
UD
77 ++errors;
78
7ce241a0 79 if (putc_unlocked ('\n', stream) == EOF)
267ca16a
UD
80 ++errors;
81
7ce241a0
UD
82 funlockfile (stream);
83
267ca16a
UD
84 return errors ? -1 : 0;
85}