Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Mar 2002 19:50:07 -0800 (PST)
From:      "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To:        freebsd-standards@FreeBSD.org
Subject:   Re: standards/36191: P1003.1-2001 csplit utility
Message-ID:  <200203230350.g2N3o7933719@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR standards/36191; it has been noted by GNATS.

From: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To: "Brian F. Feldman" <green@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: standards/36191: P1003.1-2001 csplit utility
Date: Sat, 23 Mar 2002 14:41:04 +1100

 On Fri, Mar 22, 2002 at 09:49:36AM -0500, Brian F. Feldman wrote:
 
 > "Tim J. Robbins" <tim@robbins.dropbear.id.au> wrote:
 > > X	sprintf(fmt, "%%s%%0%ldld", sufflen);
 > > X	sprintf(currfile, fmt, prefix, nfiles);
 > 
 > This is a bit of a strange construct.  You should probably be using 
 > something like:
 > 	snprintf(currfile, sizeof(currfile), "%s%*ld", prefix, sufflen, nfiles);
 
 Thanks for your suggestion - that way is indeed much cleaner.
 
 --- csplit.c	2002/03/22 07:39:55	1.17
 +++ csplit.c	2002/03/23 03:36:26	1.18
 @@ -44,7 +44,7 @@
  
  #include <sys/cdefs.h>
  __FBSDID("$FreeBSD$");
 -__RCSID("$Id: csplit.c,v 1.17 2002/03/22 07:39:55 tim Exp $");
 +__RCSID("$Id: csplit.c,v 1.18 2002/03/23 03:36:26 tim Exp $");
  
  #include <sys/types.h>
  
 @@ -91,11 +91,10 @@
  FILE *
  newfile(void)
  {
 -	char fmt[20];
  	FILE *fp;
  
 -	sprintf(fmt, "%%s%%0%ldld", sufflen);
 -	sprintf(currfile, fmt, prefix, nfiles);
 +	snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix, sufflen,
 +	    nfiles);
  	if ((fp = fopen(currfile, "w+")) == NULL)
  		err(1, "%s", currfile);
  	nfiles++;
 @@ -107,15 +106,14 @@
  void
  cleanup(void)
  {
 -	char fmt[20], fnbuf[PATH_MAX];
 +	char fnbuf[PATH_MAX];
  	long i;
  
  	if (!doclean)
  		return;
  
  	for (i = 0; i < nfiles; i++) {
 -		sprintf(fmt, "%%s%%0%ldld", sufflen);
 -		sprintf(fnbuf, fmt, prefix, i);
 +		snprintf(fnbuf, sizeof(fnbuf), "%s%0*ld", prefix, sufflen, i);
  		unlink(fnbuf);
  	}
  }
 
 
 
 Tim

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203230350.g2N3o7933719>