xref: /csrg-svn/lib/libc/string/memccpy.c (revision 42447)
141958Sbostic /*-
241958Sbostic  * Copyright (c) 1990 The Regents of the University of California.
334479Sbostic  * All rights reserved.
434479Sbostic  *
541958Sbostic  * %sccs.include.redist.c%
624194Skre  */
724194Skre 
826525Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*42447Sbostic static char sccsid[] = "@(#)memccpy.c	5.6 (Berkeley) 05/29/90";
1034479Sbostic #endif /* LIBC_SCCS and not lint */
1124194Skre 
1241958Sbostic #include <string.h>
1341958Sbostic #include <sys/stdc.h>
1424194Skre 
1541958Sbostic void *
1624194Skre memccpy(t, f, c, n)
17*42447Sbostic 	void *t;
18*42447Sbostic 	const void *f;
19*42447Sbostic 	int c;
2041958Sbostic 	register size_t n;
2124194Skre {
22*42447Sbostic 
23*42447Sbostic 	if (n) {
24*42447Sbostic 		register unsigned char *t;
25*42447Sbostic 		register const unsigned char *f;
26*42447Sbostic 		register unsigned char ch = c;
27*42447Sbostic 
28*42447Sbostic 		do {
29*42447Sbostic 			if ((*t++ = *f++) == c)
30*42447Sbostic 				return (t);
31*42447Sbostic 		} while (--n != 0);
32*42447Sbostic 	}
3324194Skre 	return (0);
3424194Skre }
35