User: Password:
Subscribe / Log in / New account

strncpy() history

strncpy() history

Posted Jul 19, 2012 12:33 UTC (Thu) by Yorick (subscriber, #19241)
In reply to: strncpy() history by akanaber
Parent article: The ups and downs of strlcpy()

I agree that strncpy() is badly named, and that this has led people to misunderstand its function and purpose. It is still useful for (mostly legacy) wire protocols and on-disk formats where, in addition to the fixed record size, the null byte padding is important (in order not to leak any information).

By the way, strncpy() does not seem to have an obvious inverse in the C library. Perhaps sscanf can be used, but it feels a little hacky and not what I would use in code that needs to go fast.

(Log in to post comments)

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds