2 ms·
or use safe libraries, strncpy rather than strcpy, and so on?
by jjtheblunt 5y ago
or use safe libraries, strncpy rather than strcpy, and so on?
- saagarjha 5y agostrncpy is not a really meant to be a “safe” function.
- tialaramex 5y agoIn a sense strncpy() is exactly the sort of unsafe nonsense that got C into trouble. C's strings are zero byte terminated, but the strings strncpy() is intended to target are not, they're file names in a fixed length buffer. So, it's fine to fill the entire buffer with text and no terminator, or to write a single byte of text, and fill the rest with zero bytes. If that's the exact problem you have, strncpy() is the exact feature you wanted. Otherwise it isn't. If you aren't aware of why Unix wanted this feature it's a very strange thing to find in C's small standard library.