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

I'm going to give it my best guess- it will copy up to n bytes, including the null byte if present in n, but not adding a null if the nth byte isn't a null, requiring you to set the last byte to 0 manually, whether that's allocating n+1 bytes or truncating the nth.


Even if you're right, you said you were guessing, meaning you'd have to look it up.

To add insult to injury, snprintf does it differently.


Yes, it's the most obnoxious behavior I could think up - Which meant I was sure it was correct, but not the kind of sure I'd want to rely on.

I also refreshed myself on snprintf, and as un-ergonomic interfaces go, they did a good job with what they had... But I will gladly take my golang multiple return values, now that I have them.

    So, only when the returned value is non-negative and less than ā€˜n’, the string has been completely written as expected.




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

Search: