tech-userlevel archive

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

Re: RFC - add snscanf(3) to stdio

On Aug 31, 2008, at 7:57 PM, ITOH Yasufumi wrote:

In article <> writes:

Thus I'd like to introduce the following:
int snscanf(const char *str, const size_t buflen, const char *format, ...); int vsnscanf(const char *str, const size_t buflen, const char *format,
va_list ap);

The result would be the above code changed to look like this:

line = fgetln(fp, &lsize)
if (line != NULL && lsize > 0)
    snscanf(line, lsize, "%d", &integer);

and there would be no need for a gratutious \0 to be added.

What does the first 's' stand for?
A string in C is defined as a nul-terminated array of char,
and an array of char without nul-termination is not a string.

s{scan,print} = version that operates on strings

sscanf -> snscanf is analogous to sprintf -> snprintf

However, passing in a non-NULL terminated string is a bug.  And
I don't think we are going to add n version of the rest of stdio
or string functions.

So, I agree with the above, pass in a NUL terminated string.

Home | Main Index | Thread Index | Old Index