From owner-cvs-all Fri Jan 5 11:37:41 2001 From owner-cvs-all@FreeBSD.ORG Fri Jan 5 11:37:36 2001 Return-Path: Delivered-To: cvs-all@freebsd.org Received: from harmony.village.org (unknown [204.144.255.66]) by hub.freebsd.org (Postfix) with ESMTP id 0943337B400; Fri, 5 Jan 2001 11:37:34 -0800 (PST) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.11.1/8.11.1) with ESMTP id f05JbTb56229; Fri, 5 Jan 2001 12:37:30 -0700 (MST) (envelope-from imp@harmony.village.org) Message-Id: <200101051937.f05JbTb56229@harmony.village.org> To: Matt Dillon Subject: Re: cvs commit: src/usr.bin/apply apply.c Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.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> <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> Date: Fri, 05 Jan 2001 12:37:29 -0700 From: Warner Losh Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 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