mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] shadow: Implement putspent
@ 2013-11-05  7:47 Michael Forney
  2013-11-05 19:24 ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Forney @ 2013-11-05  7:47 UTC (permalink / raw)
  To: musl

---
When I brought up implementing the shadow.h functions on IRC, several concerns
were raised. However, it turns out that the shadow package only requires
putspent. I didn't understand the concerns on IRC, so if there is an issue with
the implementation of this function, please let me know and hopefully I'll be
able to address it.

 src/passwd/fgetspent.c |  5 -----
 src/passwd/putspent.c  | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 5 deletions(-)
 create mode 100644 src/passwd/putspent.c

diff --git a/src/passwd/fgetspent.c b/src/passwd/fgetspent.c
index a9a3c97..3dda784 100644
--- a/src/passwd/fgetspent.c
+++ b/src/passwd/fgetspent.c
@@ -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
index 0000000..bb0a410
--- /dev/null
+++ b/src/passwd/putspent.c
@@ -0,0 +1,30 @@
+#include <shadow.h>
+#include <stdio.h>
+
+int putspent(const struct spwd *sp, FILE *f)
+{
+	flockfile(f);
+	if (sp->sp_namp && fputs(sp->sp_namp, f) == EOF) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_pwdp && fputs(sp->sp_pwdp, f) == EOF) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_lstchg != -1 && fprintf(f, "%d", sp->sp_lstchg) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_min != -1 && fprintf(f, "%d", sp->sp_min) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_max != -1 && fprintf(f, "%d", sp->sp_max) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_warn != -1 && fprintf(f, "%d", sp->sp_warn) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_inact != -1 && fprintf(f, "%d", sp->sp_inact) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_expire != -1 && fprintf(f, "%d", sp->sp_expire) < 0) goto fail;
+	if (fputc(':', f) == EOF) goto fail;
+	if (sp->sp_flag != -1 && fprintf(f, "%d", sp->sp_flag) < 0) goto fail;
+	if (fputc('\n', f) == EOF) goto fail;
+	funlockfile(f);
+	return 0;
+fail:
+	funlockfile(f);
+	return -1;
+}
-- 
1.8.4.2



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-11-24  6:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-05  7:47 [PATCH] shadow: Implement putspent Michael Forney
2013-11-05 19:24 ` Rich Felker
2013-11-05 22:30   ` [PATCH v2] " Michael Forney
2013-11-05 23:31     ` Rich Felker
2013-11-06 13:20       ` Jens Gustedt
2013-11-06 16:36         ` Rich Felker
2013-11-07 22:35           ` Jens Gustedt
2013-11-08  0:37             ` Szabolcs Nagy
2013-11-24  6:10       ` [PATCH v3] " Michael Forney

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).