News for hackers. Stuff that matters.
Re:Beware of strncpy and strncat by akkartik on Wednesday June 06, 2018 @12:51PM (#17248747)
How is returning a different value "silent"? It's informing the caller just fine.

This is C we're talking about. Always be checking return values. (And errno! And errno! And errno!)

Re:Beware of strncpy and strncat by bripeace on Wednesday June 06, 2018 @01:58PM (#17249417)
Careful! Errno can be set even when there is not an error.it's value is only relevant when the return value of the function indicates an error.

That said there are some functions where the possible return values can't indicate an error. In those cases errno should be set to zero before the function call and then a change during will alert you to an error.

Why it's like this I have no idea but it's pretty annoying.

Re:Beware of strncpy and strncat by nothrabannosir on Wednesday June 06, 2018 @02:23PM (#17249637)
> Why it's like this I have no idea but it's pretty annoying.

The bit about errno possibly being non-zero but not indicating error unless the function does? I guess because the called function can itself call functions / libs which set errno and properly handle those (or just not care). Without the "errno only has meaning if the function returns error" guard, every single function needs to always reset errno to zero before returning, which is annoying and will almost certainly not happen in the majority of cases.

When the function has no way to communicate error, there is no other option but to use errno. But it's good that it's the exception, I imagine.