Date: Fri, 05 Jan 2001 12:37:29 -0700 From: Warner Losh <imp@harmony.village.org> To: Matt Dillon <dillon@earth.backplane.com> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/usr.bin/apply apply.c Message-ID: <200101051937.f05JbTb56229@harmony.village.org> In-Reply-To: Your message of "Fri, 05 Jan 2001 11:18:23 PST." <200101051918.f05JINQ02516@earth.backplane.com> References: <200101051918.f05JINQ02516@earth.backplane.com> <jedgar@fxp.org> <200101050206.f0526rB87964@hak.lan.Awfulhak.org> <20010105162917.K85794@strontium.scientia.demon.co.uk> <20010105120633.B66833@peitho.fxp.org> <20010105184921.M85794@strontium.scientia.demon.co.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <200101051918.f05JINQ02516@earth.backplane.com> Matt Dillon writes: : Yes, but not portably. The ANSI standard tried to standardize it but : the reality is that only snprintf()'s return value is portable. If you : try to use the return value from other functions as a count, your code : won't be portable. asprintf() *might* be portable too, but nothing else. At least ANSI-99 C (well, this is the publicly available last draft before the standard) is fairly clear about snprintf (to answer an earlier request in this thread): 7.19.6.5 The snprintf function Synopsis [#1] #include <stdio.h> int snprintf(char * restrict s, size_t n, const char * restrict format, ...); Description [#2] The snprintf function is equivalent to fprintf, except that the output is written into an array (specified by argument s) rather than to a stream. If n is zero, nothing is written, and s may be a null pointer. Otherwise, output characters beyond the n-1st are discarded rather than being written to the array, and a null character is written at the end of the characters actually written into the array. If copying takes place between objects that overlap, the behavior is undefined. Returns [#3] The snprintf function returns the number of characters that would have been written had n been sufficiently large, not counting the terminating null character, or a negative value if an encoding error occurred. Thus, the null- terminated output has been completely written if and only if the returned value is nonnegative and less than n. There is enough verbage in the C99 standard that defines the return value of printf, et al, as the number of characters "transmitted" for it to become portable in the coming years. However, I've never much found a use for this information, which is likely why it has taken so long to get it good and standardized. Warner 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?200101051937.f05JbTb56229>