Date: Fri, 5 Jan 2001 12:06:33 -0500 From: Chris Faulhaber <jedgar@fxp.org> To: Ben Smithurst <ben@FreeBSD.org> Cc: Brian Somers <brian@Awfulhak.org>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/apply apply.c Message-ID: <20010105120633.B66833@peitho.fxp.org> In-Reply-To: <20010105162917.K85794@strontium.scientia.demon.co.uk>; from ben@FreeBSD.org on Fri, Jan 05, 2001 at 04:29:17PM %2B0000 References: <jedgar@fxp.org> <200101050206.f0526rB87964@hak.lan.Awfulhak.org> <20010105162917.K85794@strontium.scientia.demon.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 05, 2001 at 04:29:17PM +0000, Ben Smithurst wrote: > Would this change make you feel better? > > change this: > > Snprintf() and vsnprintf() will write at most size-1 of the characters > printed into the output string (the size'th character then gets the ter- > minating `\0'); if the return value is greater than or equal to the size > argument, the string was too short and some of the printed characters > were discarded. > > to this: > > Snprintf() and vsnprintf() will write at most size-1 of the characters > printed into the output string (the size'th character then gets the ter- > minating `\0'), and return the number of characters written to the > buffer, excluding the terminating `\0'. This value may be less than the > number of characters which would have been written, had the buffer been > large enough; if the return value is greater than or equal to the size > argument, the string was too short and some of the printed characters > were discarded. > This change makes sense. However, I think that These functions return the number of characters printed (not including the trailing `\0' used to end output to strings). should be associated only with the appropriate functions (sprintf(), vsprintf()) especially since those it does not apply to already mention their return values. The following patch (mdoc-nits aside) combine both ideas. -- Chris D. Faulhaber - jedgar@fxp.org - jedgar@FreeBSD.org -------------------------------------------------------- FreeBSD: The Power To Serve - http://www.FreeBSD.org Index: printf.3 =================================================================== RCS file: /home/ncvs/src/lib/libc/stdio/printf.3,v retrieving revision 1.21 diff -u -r1.21 printf.3 --- printf.3 2001/01/01 05:19:52 1.21 +++ printf.3 2001/01/05 17:04:17 @@ -114,12 +114,6 @@ .Xr stdarg 3 ) are converted for output. .Pp -These functions return -the number of characters printed -(not including the trailing -.Ql \e0 -used to end output to strings). -.Pp .Fn Asprintf and .Fn vasprintf @@ -146,15 +140,23 @@ (the .Fa size Ns 'th character then gets the terminating -.Ql \e0 ) ; -if the return value is greater than or equal to the -.Fa size -argument, the string was too short +.Ql \e0 ) , +and return the number of characters written to the +buffer, excluding the terminating +.Ql \e0 . +This value may be less than the number of characters +which would have been written, had the buffer been +large enough; if the return value is greater than or +equal to the size argument, the string was too short and some of the printed characters were discarded. .Pp .Fn Sprintf and .Fn vsprintf +return the number of characters printed +(not including the trailing +.Ql \e0 +used to end output to strings). Beware, these functions effectively assume an infinite .Fa size . .Pp To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010105120633.B66833>