Path: utzoo!mnetor!uunet!husc6!uwvax!oddjob!gargoyle!att-ih!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.c Subject: Re: strcpy Message-ID: <4263@ihlpf.ATT.COM> Date: 4 Apr 88 21:40:42 GMT References: <793@cresswell.quintus.UUCP> <545@anuck.UUCP> <4190@ihlpf.ATT.COM> <836@cresswell.quintus.UUCP> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 41 In article <836@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: >Questions like "what happens to the rest of the destination" and "what >happens if the two areas overlap" are so important that the answers >SHOULD be part of the description of strcpy(). It is extremely useful to >have a function which can safely be used to move part of a character >array towards its origin. I agree that it is useful to have a function which can safely move strings with overlapping characters. That is what memmove() is for. BTW, the answer to "what happens to the rest of the destination" in strcpy() would be is that it is unaffected, since there is no way of conveying what is meant by "the rest of the destination" to a function call; ie, how can strcpy() tell the difference between an exact fit and an inexact fit? It can't. And the answer to "what happens if the two areas overlap" is found directly in the standard: "If copying takes place between objects that overlap, the behavior is undefined." You may not like the answer, but the standard answers the question just the same. >If the memcpy() question was solved by adding a memmove(), is there >also a strmove() in the current dpANS draft? strmove() is not needed since it is just a very special case of memmove(). In order to copy possibly overlapping strings, you need to know the length of the source string. Therefore, give a source string s2 (char *s2) and a destination string s1 (char *s1): (char *)memmove((void *)s1, (void *)s2, strlen(s2) + (size_t)1) will accomplish that you would want a strmove() to do. -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_