[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: snprintf

From: Andreas Schwab
Subject: Re: snprintf
Date: 29 Nov 2001 11:20:07 +0100
User-agent: Gnus/5.090003 (Oort Gnus v0.03) Emacs/21.1.30

James Morrison <rocketmail_com@rocketmail.com> writes:

|>  Hello,
|>         I've noticed that on GNU/Hurd snprintf doesn't work if
|> the expanded template exceeds the size given.
|> eg
|>         char limited[5];
|>         snprintf(limited,5,"12345");
|> On GNU/Linux with libio snprintf sets limited to "1234" and returns
|> 5.

This is correct: The snprintf function

        [#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.


        [#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 neg ative 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.


Andreas Schwab                                  "And now for something
Andreas.Schwab@suse.de                          completely different."
SuSE Labs, SuSE GmbH, Schanzäckerstr. 10, D-90443 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5

reply via email to

[Prev in Thread] Current Thread [Next in Thread]