Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I’m sure you meant something more along the lines of “strncpy is better than strcpy”.


Nah, strncpy is pretty bad and doesn't do something anyone really expects to want.

(strncpy doesn't 0-terminate when it hit max length, nor stop when it sees its first 0 in the source buffer; it acts almost entirely like memcpy except that it writes zeroes to the full length of the destination upon seeing a zero in the source. This is allegedly useful for populating fixed-sized buffers in historical Unix, and can plausibly be useful for writing out tar headers, but in practice very little code in the wild does anything observably different if you #define strncpy memcpy.)


memcpy is better than strncpy and strcpy ;)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: