OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / string / memrchr.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 libc_hidden_proto(memrchr)
11
12 void *memrchr(const void *s, int c, size_t n)
13 {
14         register const unsigned char *r;
15 #ifdef __BCC__
16         /* bcc can optimize the counter if it thinks it is a pointer... */
17         register const char *np = (const char *) n;
18 #else
19 #define np n
20 #endif
21         
22         r = ((unsigned char *)s) + ((size_t) np);
23
24         while (np) {
25                 if (*--r == ((unsigned char)c)) {
26                         return (void *) r;      /* silence the warning */
27                 }
28                 --np;
29         }
30
31         return NULL;
32 }
33 #undef np
34
35 libc_hidden_def(memrchr)