From: viro@parcelfarce.linux.theplanet.co.uk
To: Adrian Reber <adrian@lisas.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: vsnprintf patch
Date: Wed, 13 Aug 2003 13:19:35 +0100 [thread overview]
Message-ID: <20030813121935.GC454@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <20030813115212.GA28066@lisas.de>
On Wed, Aug 13, 2003 at 01:52:12PM +0200, Adrian Reber wrote:
>
> When using the snprintf function from the kernel the length returned is
> not the length written:
>
> len = snprintf(test,1,"BLA 1");
>
> len is 5 although test is "B"
>
> the patch below fixes the symptom, but I am not sure if this is the real
> solution for this problem.
For what problem? In the example above, 5 is correct return value.
7.19.6.5 The snprintf function
Synopsis
#include <stdio.h>
int snprintf(char * restrict s, size_t n, const char * restrict format, ...);
Description
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
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.
next prev parent reply other threads:[~2003-08-13 12:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-13 11:52 vsnprintf patch Adrian Reber
2003-08-13 12:16 ` Andreas Schwab
2003-08-13 12:19 ` viro [this message]
2003-08-13 12:21 ` Bernd Petrovitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030813121935.GC454@parcelfarce.linux.theplanet.co.uk \
--to=viro@parcelfarce.linux.theplanet.co.uk \
--cc=adrian@lisas.de \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox