]>
Commit | Line | Data |
---|---|---|
dff8da6b | 1 | /* Copyright (C) 1991-2024 Free Software Foundation, Inc. |
41bdb6e2 | 2 | This file is part of the GNU C Library. |
c4563d2d UD |
3 | |
4 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
5 | modify it under the terms of the GNU Lesser General Public |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
c4563d2d UD |
8 | |
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
c4563d2d | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 15 | License along with the GNU C Library; if not, see |
5a82c748 | 16 | <https://www.gnu.org/licenses/>. */ |
c4563d2d | 17 | |
685e844a AZ |
18 | #include <libc-pointer-arith.h> |
19 | #include <string-fzb.h> | |
20 | #include <string-fzc.h> | |
21 | #include <string-fzi.h> | |
22 | #include <string-shift.h> | |
c4563d2d UD |
23 | #include <string.h> |
24 | ||
25 | #undef __strchrnul | |
26 | #undef strchrnul | |
27 | ||
685e844a AZ |
28 | #ifdef STRCHRNUL |
29 | # define __strchrnul STRCHRNUL | |
31c81aaa AZ |
30 | #endif |
31 | ||
c4563d2d UD |
32 | /* Find the first occurrence of C in S or the final NUL byte. */ |
33 | char * | |
685e844a | 34 | __strchrnul (const char *str, int c_in) |
c4563d2d | 35 | { |
685e844a AZ |
36 | /* Align pointer to sizeof op_t. */ |
37 | uintptr_t s_int = (uintptr_t) str; | |
38 | const op_t *word_ptr = (const op_t *) PTR_ALIGN_DOWN (str, sizeof (op_t)); | |
c4563d2d | 39 | |
685e844a | 40 | op_t repeated_c = repeat_bytes (c_in); |
c4563d2d | 41 | |
685e844a AZ |
42 | op_t word = *word_ptr; |
43 | find_t mask = shift_find (find_zero_eq_all (word, repeated_c), s_int); | |
44 | if (mask != 0) | |
45 | return (char *) str + index_first (mask); | |
c4563d2d | 46 | |
685e844a AZ |
47 | do |
48 | word = *++word_ptr; | |
49 | while (! has_zero_eq (word, repeated_c)); | |
c4563d2d | 50 | |
685e844a | 51 | return (char *) word_ptr + index_first_zero_eq (word, repeated_c); |
c4563d2d | 52 | } |
685e844a | 53 | #ifndef STRCHRNUL |
7ea51012 | 54 | libc_hidden_def (__strchrnul) |
c4563d2d | 55 | weak_alias (__strchrnul, strchrnul) |
685e844a | 56 | #endif |