[Top][All Lists]

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

Re: [Bug-gnulib] strint.h implementation, xasprintf

From: Bruno Haible
Subject: Re: [Bug-gnulib] strint.h implementation, xasprintf
Date: Sat, 4 Sep 2004 17:05:38 +0200
User-agent: KMail/1.5

Oskar Liljeblad wrote:
> Is there any chance a patch adding a module providing strint.h
> would be accepted?

What is strint.h? What functionality shall it implement?

> Also, what's the status regarding the addition of the xasprintf
> module I submitted some time ago?

Oops, now I see that your two 2004-08-26 replies didn't reach me; maybe some
spam filter in effect.

Anyway, Simon and I expressed the wish to have the allocated 'char *' as
return value. His two arguments in favour of a returning 'int' are not

> the function
> would have the same C fingerprint as printf, so you could use it as a
> drop in replacement.

printf has a different signature: it does not have a 'char **' argument.

> you might want the length without
> doing strlen; and if x*printf support it, you could have '\0x00'
> inside the string, so using strlen wouldn't even be correct.

But all the C string functions assume no NUL characters inside strings.
If you want to handle strings with embedded NUL characters you cannot
use the usual C strings functions, including printf, anyway.

> Maybe the xasprintf in gettext could be added as well, but with
> a different name?

But if we have an xasprintf() function which returns 'int', and the
other one which returns 'char *', what's the purpose of the first one?
Can you show sample code that uses it and that couldn't use the second one?

> asnprintf and vasnprintf in gnulib suffer from the same problem
> as xasprintf in gettext though - there's no way of knowing
> exactly how many characters were written...

Use mbslen(*) to know the number of characters in the string (or strlen if you
are interested in the number of bytes). As said above, strings with
embedded NULs are outside the scope anyway.

(*) mbslen could be written similar to mbswidth, but hasn't been added to
gnulib so far because it's rarely useful.


reply via email to

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