]>
Commit | Line | Data |
---|---|---|
ee4d4e85 | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
ee4d4e85 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | /* | |
10 | * Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com> | |
11 | * | |
12 | * Permission to use, copy, modify, and distribute this software for any | |
13 | * purpose with or without fee is hereby granted, provided that the above | |
14 | * copyright notice and this permission notice appear in all copies. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | */ | |
24 | ||
25 | #include "squid.h" | |
26 | ||
27 | #if !HAVE_MEMRCHR | |
28 | ||
29 | #include "compat/memrchr.h" | |
30 | ||
31 | /* | |
32 | * Reverse memchr() | |
33 | * Find the last occurrence of 'c' in the buffer 's' of size 'n'. | |
34 | */ | |
35 | void * | |
36 | memrchr(const void *s, int c, size_t n) | |
37 | { | |
38 | const unsigned char *cp; | |
39 | ||
40 | if (n != 0) { | |
f53969cc SM |
41 | cp = (unsigned char *)s + n; |
42 | do { | |
43 | if (*(--cp) == (unsigned char)c) | |
44 | return((void *)cp); | |
45 | } while (--n != 0); | |
ee4d4e85 AJ |
46 | } |
47 | return((void *)0); | |
48 | } | |
49 | ||
50 | #endif | |
f53969cc | 51 |