The Wayback Machine - https://web.archive.org/web/20231209162006/https://lwn.net/Articles/723722/
| |
Subscribe / Log in / New account

strncpy() history

strncpy() history

Posted May 25, 2017 1:36 UTC (Thu) by rlhamil (guest, #6472)
In reply to: strncpy() history by danscox
Parent article: The ups and downs of strlcpy()

I thought that was the case too (14 character filenames in a directory entry only null-terminated if shorter than that), but looking through the v7 code, I didn't really see much in the way of examples of that, certainly not in the kernel. Here's everything I found (this is running on v7 on an emulated PDP-11 that is so much faster than the real thing that it reminds me how painfully slow they were by comparison):

unixv7# time find /usr/src /usr/sys -type f -name '*.[ch]' -exec grep strncpy /dev/null {} \;
/usr/src/libc/gen/strncpy.c:strncpy(s1, s2, n)
/usr/src/cmd/crypt.c: strncpy(buf, pw, 8);
/usr/src/cmd/ed.c: strncpy(buf, keyp, 8);
/usr/src/cmd/login.c:#define SCPYN(a, b) strncpy(a, b, sizeof(a))
/usr/src/cmd/mkdir.c: strncpy(pname, d, slash);
/usr/src/cmd/atrun.c: strncpy(file, dirent.d_name, DIRSIZ);
/usr/src/cmd/xsend/lib.c: strncpy(buf, s, 10);
/usr/src/cmd/ranlib.c: strncpy(firstname, arp.ar_name, 14);

real 7.0
user 2.0
sys 4.5

Without looking further, three appear to deal with pathname components, three deal with other things, one is a macro (turns out it was for a not-necessarily-terminated utmp.ut_name field), and one is the definition of strlcpy.


(Log in to post comments)


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