shadow: Implement putspent
authorMichael Forney <mforney@mforney.org>
Sun, 24 Nov 2013 06:10:10 +0000 (22:10 -0800)
committerRich Felker <dalias@aerifal.cx>
Sun, 24 Nov 2013 14:36:28 +0000 (09:36 -0500)
src/passwd/fgetspent.c
src/passwd/putspent.c [new file with mode: 0644]

index a9a3c97..3dda784 100644 (file)
@@ -4,8 +4,3 @@ struct spwd *fgetspent(FILE *f)
 {
        return 0;
 }
-
-int putspent(const struct spwd *sp, FILE *f)
-{
-       return -1;
-}
diff --git a/src/passwd/putspent.c b/src/passwd/putspent.c
new file mode 100644 (file)
index 0000000..55c41bb
--- /dev/null
@@ -0,0 +1,13 @@
+#include <shadow.h>
+#include <stdio.h>
+
+#define NUM(n) ((n) == -1 ? 0 : -1), ((n) == -1 ? 0 : (n))
+#define STR(s) ((s) ? (s) : "")
+
+int putspent(const struct spwd *sp, FILE *f)
+{
+       return fprintf(f, "%s:%s:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*lu\n",
+               STR(sp->sp_namp), STR(sp->sp_pwdp), NUM(sp->sp_lstchg),
+               NUM(sp->sp_min), NUM(sp->sp_max), NUM(sp->sp_warn),
+               NUM(sp->sp_inact), NUM(sp->sp_expire), NUM(sp->sp_flag)) < 0 ? -1 : 0;
+}