[PATCH v4] Implement strlcpy [BZ #178]

Paul Eggert eggert@cs.ucla.edu
Wed Nov 4 02:50:00 GMT 2015


Rich Felker wrote:
> the fact that it's wrong is actually essential to
> some usage patterns like using fgets to read files that may contain
> embedded nuls.

Thanks, that's a usage pattern I wasn't familiar with.  However, among other 
things the glibc manual explicitly says that fgets shouldn't be used in that 
situation, which suggests the ice is quite thin here.  So even if POSIX says 
what you are asserting (I haven't seen specific citations, so I'm still 
skeptical), as a practical matter applications should not assume that irrelevant 
bytes in output buffers are preserved.

As far as strlcpy goes perhaps the manual should merely say that it's 
unspecified what happens to destination bytes after the trailing NUL.  We can 
always specify it later, should POSIX make things clear.  I doubt whether 
applications care much one way or another.



More information about the Libc-alpha mailing list