> Any comments, suggestions, swears concerning adding a new function, 
> strndup(), to libc?

Many very good programmers I know carry around a library of
useful functions (and usually don't bother about inclusion in
libc).  So I would suggest first you should keep this
function in your own library for a few years and *only* then,
and only if from experience you truly think it to be
generally useful should you propose it for inclusion in a
standard library.  And *when* you do that you should
a) present a correct version of the function (not a buggy one
   as you did here)
and, more importantly
b) a clear explanation of its function including how boundary
   conditions are handled.
For your own library you don't have to jump through these
hoops; this is necessary only when you want to let loose one
of your favorite functions on unsuspecting libc users!  Then
the function behavior must be fully and carefully specified.

Even for your own use, as was suggested by Valentin Nechayev,
the strangely named function "strnlen(str, max)" is a better
lower level function since it guarantees "str" won't be
traversed beyond "max" chars and it is likely to be useful in
more situations.  As suggested by Terry Lambert, `asnprintf'
would be another alternative.

<meta-comment>
Though IMHO these string functions have sprouted like weeds,
for very little added functionality.  The fact str[a-z]* is
reserved namespace should tell you how bad the situation is.
What is needed is a decent unicode string library, derived
from the collective experience with perl scripts.  Unicode
strings should be counted instead of null terminated so we
are talking about a brand new set of functions.  May be such
a library can be standardized in a future standards effort
after some experience with it.
</meta comment>

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to