Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!hp4nl!charon!dik From: dik@cwi.nl (Dik T. Winter) Newsgroups: comp.std.c Subject: Re: strncat is insufficient Message-ID: <2010@charon.cwi.nl> Date: 26 Aug 90 01:21:21 GMT References: <1990Aug23.132400.3654@zorch.SF-Bay.ORG> <587@array.UUCP> <620.26d6d0cd@iccgcc.decnet.ab.com> Sender: news@cwi.nl Organization: CWI, Amsterdam Lines: 20 In article <620.26d6d0cd@iccgcc.decnet.ab.com> browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes: > In article <587@array.UUCP>, colin@array.UUCP (Colin Plumb) writes: > > char *strlimcat(char *dst, char const *src, int maxlen) .... > > strncpy(dst+len, src, maxlen-len); .... I would say that strncat is better here. Consider when maxlen-len is very large while strlen(src) is very small. strncpy will do all that zero-filling! > > Caution: This will not necessarily put a '\0' at the end of the string. True. > > Can Karl, or someone else who knows, explain why strncpy was standardized > to copy n characters even at the expense of a zero byte; or why no > alternative that always terminates the string was provided. I would not gripe against strncpy, because it truncates or zero fills, whatever is needed. In my opinion the gripe is against strncat. -- dik t. winter, cwi, amsterdam, nederland dik@cwi.nl