Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!usc!brutus.cs.uiuc.edu!wuarchive!decwrl!shelby!csli!poser From: poser@csli.Stanford.EDU (Bill Poser) Newsgroups: comp.lang.c Subject: strncpy Keywords: strncpy null termination Message-ID: <11509@csli.Stanford.EDU> Date: 21 Dec 89 10:09:27 GMT Sender: poser@csli.Stanford.EDU (Bill Poser) Organization: Center for the Study of Language and Information, Stanford U. Lines: 19 Why is it that strncpy(3) does not null terminate the string if the length of the source string is greater than or equal to the length of the target buffer? I cannot think of any circumstances in which this behaviour is desirable, and always end up null terminating it myself. The only case in which a non-null-terminated string might be useful would be one in which a different representation for strings (e.g. descriptors) is used, in which case the use of str(n)cpy would not be appropriate anyhow. It seems to me that the behaviour of strncpy provides: (a) a source of bugs for people who don't bother to arrange null-termination themselves; (b) extra work for those who take care; or, (c) just enough of a pain to be unsafe and use strcpy(3). So I claim that strncpy is mis-designed and should null-terminate. Any comments? Bill