[TUHS] History of strncpy
wkt at tuhs.org
Wed Jan 23 14:41:08 AEST 2013
On Tue, Jan 22, 2013 at 10:03:54PM -0600, Nevin Liber wrote:
> The original reason for strncpy() was when directory names were limited to
> 14 chars. The other two bytes contained the inode number. For that
> particular case, strncpy() worked quite well.
> Is that really the reason it came into being?
strncpy() was introduced in 7th Edition Unix. From a quick perusal through
the V7 source code, these files used strncpy():
usr/src/cmd/ranlib.c strncpy(firstname, arp.ar_name, 14);
usr/src/cmd/login.c #define SCPYN(a, b) strncpy(a, b, sizeof(a))
usr/src/cmd/expr.y strncpy(Mstring, p, num);
usr/src/cmd/atrun.c strncpy(file, dirent.d_name, DIRSIZ);
usr/src/cmd/ed.c strncpy(buf, keyp, 8);
usr/src/cmd/mkdir.c strncpy(pname, d, slash);
usr/src/cmd/xsend/lib.c strncpy(buf, s, 10);
usr/src/cmd/crypt.c strncpy(buf, pw, 8);
Only two of these (ranlib.c and atrun.c) appear to be specifically related
to the 14-byte filename limit in V7. So I'd say that strncpy() wasn't
introduced solely to deal with 14-byte filenames.
More information about the TUHS