(Note followups, this has stopped being very Pythony.)

On 2010-11-11, Lawrence D'Oliveiro <l...@geek-central.gen.new_zealand> wrote:
> Another function that should be deprecated is strncat???I myself was caught 
> out misunderstanding it recently. What purpose does it serve?

I'm wondering if you're thinking of strncpy(), which is the famously bogus
one.  strncat() just has a fencepost error -- given a limit N, it will
write at most N+1 characters.  strncpy(), however, pads with null bytes
if the source string isn't long enough, and does not null terminate if there
isn't room to.

This behavior is nearly always undesireable.  However, if you were building
a filesystem in which file path names were given exactly sixteen bytes of
space in the directory entry, and you didn't want to truncate them to 15
bytes, you might write precisely this behavior.  So that's what we got.

I don't know whether anyone's gotten buy-in from the standards people
for strlcpy()/strlcat(), but I really hope so.  Me, I just use
snprintf with a %s format instead of str*cpy().

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to