1 /*
2 * This file is part of the Sofia-SIP package
3 *
4 * Copyright (C) 2005 Nokia Corporation.
5 *
6 * Contact: Pekka Pessi <pekka.pessi@nokia.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */
24
25 /**@internal @file memccpy.c
26 * @brief The memccpy() replacement function.
27 *
28 * @author Pekka Pessi <Pekka.Pessi@nokia.com>
29 *
30 * @date Created: Thu Nov 17 17:45:51 EET 2005 ppessi
31 */
32
33 #include "config.h"
34
35 #include <string.h>
36 #include <limits.h>
37
38 /**Copy memory until @a c is found.
39 *
40 * Copies no more than @a n bytes from memory area @a src to memory area @a
41 * dest, stopping after the character @a c is copied and found.
42 *
43 * @param dest pointer to destination area
44 *�@param src pointer to source area
45 * @param c terminating byte
46 * @param n size of destination area
47 *
48 * @return
49 * Returns a pointer to the next character in @a dest after @a c,
50 * or NULL if @a c was not found in the first @a n characters of @a src.
51 */
memccpy(void * dest,const void * src,int c,size_t n)52 void *memccpy(void *dest, const void *src, int c, size_t n)
53 {
54 char *d;
55 char const *s;
56
57 if (!src || !dest)
58 return dest;
59
60 for (d = dest, s = src; n-- > 0;) {
61 if (c == (*d++ = *s++))
62 return d;
63 }
64
65 return NULL;
66 }
67
68