xref: /openbsd/sys/lib/libkern/memcpy.c (revision 77f321a5)
1*77f321a5Sjsg /*	$OpenBSD: memcpy.c,v 1.5 2021/05/16 04:45:58 jsg Exp $	*/
24d6af78aSderaadt 
34d6af78aSderaadt /*-
44d6af78aSderaadt  * Copyright (c) 1993
54d6af78aSderaadt  *	The Regents of the University of California.  All rights reserved.
64d6af78aSderaadt  *
74d6af78aSderaadt  * Redistribution and use in source and binary forms, with or without
84d6af78aSderaadt  * modification, are permitted provided that the following conditions
94d6af78aSderaadt  * are met:
104d6af78aSderaadt  * 1. Redistributions of source code must retain the above copyright
114d6af78aSderaadt  *    notice, this list of conditions and the following disclaimer.
124d6af78aSderaadt  * 2. Redistributions in binary form must reproduce the above copyright
134d6af78aSderaadt  *    notice, this list of conditions and the following disclaimer in the
144d6af78aSderaadt  *    documentation and/or other materials provided with the distribution.
154d6af78aSderaadt  * 3. Neither the name of the University nor the names of its contributors
164d6af78aSderaadt  *    may be used to endorse or promote products derived from this software
174d6af78aSderaadt  *    without specific prior written permission.
184d6af78aSderaadt  *
194d6af78aSderaadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
204d6af78aSderaadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
214d6af78aSderaadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
224d6af78aSderaadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
234d6af78aSderaadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
244d6af78aSderaadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
254d6af78aSderaadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
264d6af78aSderaadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
274d6af78aSderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
284d6af78aSderaadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
294d6af78aSderaadt  * SUCH DAMAGE.
304d6af78aSderaadt  */
314d6af78aSderaadt 
324d6af78aSderaadt #include <sys/types.h>
33371f3ceaSgrange #include <sys/systm.h>
344d6af78aSderaadt 
35249415e0Skettenis #undef memcpy
36249415e0Skettenis 
374d6af78aSderaadt /*
384d6af78aSderaadt  * This is designed to be small, not fast.
394d6af78aSderaadt  */
404d6af78aSderaadt void *
memcpy(void * s1,const void * s2,size_t n)41e56c36efSderaadt memcpy(void *s1, const void *s2, size_t n)
424d6af78aSderaadt {
43*77f321a5Sjsg 	const char *f = s2;
44*77f321a5Sjsg 	char *t = s1;
454d6af78aSderaadt 
464d6af78aSderaadt 	while (n-- > 0)
474d6af78aSderaadt 		*t++ = *f++;
484d6af78aSderaadt 	return s1;
494d6af78aSderaadt }
50