From mboxrd@z Thu Jan 1 00:00:00 1970 From: wkt@tuhs.org (Warren Toomey) Date: Wed, 23 Jan 2013 14:41:08 +1000 Subject: [TUHS] History of strncpy In-Reply-To: References: Message-ID: <20130123044108.GA2871@neddie.local.net> 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[0], 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. Cheers, Warren