From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4190 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] shadow: Implement putspent Date: Tue, 5 Nov 2013 14:24:16 -0500 Message-ID: <20131105192416.GE24286@brightrain.aerifal.cx> References: <1383637660-7768-1-git-send-email-mforney@mforney.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1383679469 3942 80.91.229.3 (5 Nov 2013 19:24:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 5 Nov 2013 19:24:29 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4194-gllmg-musl=m.gmane.org@lists.openwall.com Tue Nov 05 20:24:34 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 1VdmEn-0003Kb-Jv for gllmg-musl@plane.gmane.org; Tue, 05 Nov 2013 20:24:29 +0100 Original-Received: (qmail 7561 invoked by uid 550); 5 Nov 2013 19:24:28 -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 7550 invoked from network); 5 Nov 2013 19:24:28 -0000 Content-Disposition: inline In-Reply-To: <1383637660-7768-1-git-send-email-mforney@mforney.org> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4190 Archived-At: On Mon, Nov 04, 2013 at 11:47:40PM -0800, Michael Forney wrote: > --- > 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 > +#include > + > +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; Is there a reason for all this logic instead of a single call to fprintf with a proper format string? Writing the value -1 as an empty slot can be handled with a simple macro that expands to 0,0 for an argument of -1 and -1,val for other values, along with a %.*d format. Rich