stanonik%nprdc@sri-unix.UUCP (02/23/84)
From: Ron Stanonik <stanonik@nprdc> Why did "they" write strncpy(s1, s2, n) such that s1 is not null terminated if the length of s2 is n or more? Has anyone changed this and lived to tell about it? Thanks, Ron Stanonik stanonik@nprdc
jackm%ardc@sri-unix.UUCP (02/23/84)
From: Jack Moskowitz (PAD) <jackm@ardc> Strncpy may be used to manipulate characters within strings rather than the whole string. Eg. changing the string abcdef to abxxef. You would not want to null terminate after the xx in this case.
gwyn%brl-vld@sri-unix.UUCP (02/23/84)
From: Doug Gwyn (VLD/VMB) <gwyn@brl-vld> "Strncpy copies exactly n characters, truncating s2 or adding null characters to s1 if necessary. The result will not be null-terminated if the length of s2 is n or more." Do NOT change it.
phil%rice@sri-unix.UUCP (02/24/84)
From: William LeFebvre <phil@rice> "strncpy" copies EXACTLY n characters, regardless of the length of either string. Some programs rely on this particular (some would say peculiar) heuristic of "strncpy". To change it would invite disaster. If you need a function that does a "strncpy" but insures that "s1" is null terminated, I suggest that you write your own and call it something besides "strncpy". All the functions in the str* family are easy to duplicate. Personally, I have frequently added a function called "strecpy" which performs the same function as "strcpy" except that it returns a pointer to the null byte in "s1" rather than the beginning. I found this handy when I wanted to do a bunch of strcats in a row. William LeFebvre Department of Mathematical Sciences Rice University <phil@rice>