xref: /illumos-gate/usr/src/lib/libc/port/gen/putspent.c (revision 711890bc9379ceea66272dc8d4981812224ea86e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 /*
34  * format a shadow file entry
35  *
36  * This code used to live in getspent.c
37  */
38 
39 #pragma weak putspent = _putspent
40 
41 #include "synonyms.h"
42 #include <stdio.h>
43 #include <shadow.h>
44 
45 int
46 putspent(const struct spwd *p, FILE *f)
47 {
48 	(void) fprintf(f, "%s:%s:", p->sp_namp,
49 		p->sp_pwdp ? p->sp_pwdp : "");
50 		/* pwdp could be null for +/- entries */
51 	if (p->sp_lstchg >= 0)
52 		(void) fprintf(f, "%d:", p->sp_lstchg);
53 	else
54 		(void) fprintf(f, ":");
55 	if (p->sp_min >= 0)
56 		(void) fprintf(f, "%d:", p->sp_min);
57 	else
58 		(void) fprintf(f, ":");
59 	if (p->sp_max >= 0)
60 		(void) fprintf(f, "%d:", p->sp_max);
61 	else
62 		(void) fprintf(f, ":");
63 	if (p->sp_warn > 0)
64 		(void) fprintf(f, "%d:", p->sp_warn);
65 	else
66 		(void) fprintf(f, ":");
67 	if (p->sp_inact > 0)
68 		(void) fprintf(f, "%d:", p->sp_inact);
69 	else
70 		(void) fprintf(f, ":");
71 	if (p->sp_expire > 0)
72 		(void) fprintf(f, "%d:", p->sp_expire);
73 	else
74 		(void) fprintf(f, ":");
75 	if (p->sp_flag != 0)
76 		(void) fprintf(f, "%d\n", p->sp_flag);
77 	else
78 		(void) fprintf(f, "\n");
79 
80 	(void) fflush(f);
81 	return (ferror(f));
82 }
83