1c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes/* $NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $ */ 2c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 3c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes/*- 4c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * Copyright (c) 1990, 1993 5c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * The Regents of the University of California. All rights reserved. 6c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * 7c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * Redistribution and use in source and binary forms, with or without 8c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * modification, are permitted provided that the following conditions 9c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * are met: 10c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * 1. Redistributions of source code must retain the above copyright 11c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * notice, this list of conditions and the following disclaimer. 12c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * 2. Redistributions in binary form must reproduce the above copyright 13c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * notice, this list of conditions and the following disclaimer in the 14c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * documentation and/or other materials provided with the distribution. 15c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * 3. Neither the name of the University nor the names of its contributors 16c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * may be used to endorse or promote products derived from this software 17c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * without specific prior written permission. 18c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * 19c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes * SUCH DAMAGE. 30c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes */ 31c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 32c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#include <sys/cdefs.h> 33c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#if defined(LIBC_SCCS) && !defined(lint) 34c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#if 0 35c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughesstatic char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; 36c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#else 37c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes__RCSID("$NetBSD: memccpy.c,v 1.13 2012/06/25 22:32:46 abs Exp $"); 38c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#endif 39c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#endif /* LIBC_SCCS and not lint */ 40c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 41c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#include <assert.h> 42c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes#include <string.h> 43c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 44c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughesvoid * 45c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughesmemccpy(void *t, const void *f, int c, size_t n) 46c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes{ 47c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 48c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes _DIAGASSERT(t != 0); 49c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes _DIAGASSERT(f != 0); 50c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes 51c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes if (n) { 52c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes unsigned char *tp = t; 53c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes const unsigned char *fp = f; 54c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes unsigned char uc = c; 55c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes do { 56c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes if ((*tp++ = *fp++) == uc) 57c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes return (tp); 58c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes } while (--n != 0); 59c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes } 60c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes return (0); 61c51cd764a2d0897234762abd4dbd21420cb9f17dElliott Hughes} 62