OSDN Git Service

438f4fa4a88cc4a2fc2d0f751bcd481963d33778
[uclinux-h8/uClibc.git] / libc / string / memchr.c
1 /*
2  * Copyright (C) 2002     Manuel Novoa III
3  * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4  *
5  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6  */
7
8 #include "_string.h"
9
10 #ifdef WANT_WIDE
11 # define Wmemchr wmemchr
12 #else
13 # undef memchr
14 # define Wmemchr memchr
15 #endif
16
17 Wvoid *Wmemchr(const Wvoid *s, Wint c, size_t n)
18 {
19         register const Wuchar *r = (const Wuchar *) s;
20 #ifdef __BCC__
21         /* bcc can optimize the counter if it thinks it is a pointer... */
22         register const char *np = (const char *) n;
23 #else
24 # define np n
25 #endif
26
27         while (np) {
28                 if (*r == ((Wuchar)c)) {
29                         return (Wvoid *) r;     /* silence the warning */
30                 }
31                 ++r;
32                 --np;
33         }
34
35         return NULL;
36 }
37 #undef np
38
39 libc_hidden_def(Wmemchr)