From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4191 Path: news.gmane.org!not-for-mail From: Michael Forney Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH v2] shadow: Implement putspent Date: Tue, 5 Nov 2013 14:30:00 -0800 Message-ID: <1383690600-24170-1-git-send-email-mforney@mforney.org> References: <20131105192416.GE24286@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1383690620 6265 80.91.229.3 (5 Nov 2013 22:30:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Nov 2013 22:30:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4195-gllmg-musl=m.gmane.org@lists.openwall.com Tue Nov 05 23:30:25 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Vdp8d-0006Sj-Ji for gllmg-musl@plane.gmane.org; Tue, 05 Nov 2013 23:30:19 +0100 Original-Received: (qmail 7558 invoked by uid 550); 5 Nov 2013 22:30:18 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 7547 invoked from network); 5 Nov 2013 22:30:18 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=jNlUXL8VSwTD4Z6897aodbp8wl821lZxpVmGaqdWE0I=; b=clkIgVeXWkm0J9tRvwoJf1ky176O9gk68F4qnxX1QNSTMZugMa3lIhmad2AHWzuMKC x81HAkP29AompidbHeO/o/sTiRJB8/YjqL8mXDd3YqDecgsueRZ8lQ53I9ySk96JN5l0 mnYoGCZX+XJfUz/eYMQww1iH8X0aXaQOm1+dzTZinCmRuOjP38SwP+jvZ+u1L7QY7+xL lqLZVWoIfIakjgnfZp2hxw0Tc3BksyqQEyrLkWEYkmnWR3oU9g6DuUrHMxrgUU/0Ha0E 0oLf4Vhqfg3WT2d/1WiPEQav3ArGvdpINJYeaYiUPhC9xA2UOhDCxIrAbkuQUnHYxclT i/SQ== X-Gm-Message-State: ALoCoQlmUWPOwt3QQ3tDq3yGlaRgtR7uvvEpflbEzIpYd5vd61zXgLbLQKSMTEznDWPY9nZnQE6h X-Received: by 10.68.255.229 with SMTP id at5mr13783317pbd.130.1383690605613; Tue, 05 Nov 2013 14:30:05 -0800 (PST) X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <20131105192416.GE24286@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:4191 Archived-At: --- Thanks Rich, I didn't know about negative and zero precision specifiers. This turned out much cleaner. I've also changed the fields to use %ld because they are longs, and changed the last field to %lu because it is unsigned (though unused). src/passwd/fgetspent.c | 5 ----- src/passwd/putspent.c | 13 +++++++++++++ 2 files changed, 13 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..fbf4278 --- /dev/null +++ b/src/passwd/putspent.c @@ -0,0 +1,13 @@ +#include +#include + +#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; +} -- 1.8.4.2