|
|
Subscribe / Log in / New account

strncpy

strncpy

Posted Aug 25, 2022 22:03 UTC (Thu) by tialaramex (subscriber, #21167)
In reply to: Ushering out strlcpy() by Sesse
Parent article: Ushering out strlcpy()

As I understand it, this function exists because it's how you do exactly this operation (copy a C-style string into some fixed width buffer) somewhere in early Unix, maybe the filesystem. Its authors knew exactly what they were doing, and this function makes sense for their intended application, but as you say the name suggests somebody might find it useful in very different circumstances.

But, on the other hand notice the newer APIs are still awful. The language just doesn't give us much to work with by having this terrible string type. I think we might have been better off if C hadn't admitted to a string type at all (ie there are no string functions, and no "" literal syntax) and then presumably C89 might have introduced one but there would have been a war to decide how that works (since C89 mostly codifies popular real world C implementations) and I can't believe that 0-terminated wins such a war, even if Pascal-style (length-prefixed) wins that's a less awful world than our world.


to post comments

strncpy

Posted Aug 26, 2022 0:46 UTC (Fri) by NYKevin (subscriber, #129325) [Link]

Raymond Chen reports that this was the case at least as far back as System V (and yes, it was in the filesystem): https://devblogs.microsoft.com/oldnewthing/20050107-00/?p...


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