| 1 | /* rawmemchr - find a character in a memory zone |
| 2 | |
| 3 | Copyright (C) 2015-2024 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of the GNU C Library. |
| 6 | |
| 7 | The GNU C Library is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU Lesser General Public |
| 9 | License as published by the Free Software Foundation; either |
| 10 | version 2.1 of the License, or (at your option) any later version. |
| 11 | |
| 12 | The GNU C Library is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | Lesser General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU Lesser General Public |
| 18 | License along with the GNU C Library. If not, see |
| 19 | <https://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include <sysdep.h> |
| 22 | |
| 23 | /* Special case rawmemchr (s, 0) as strlen, otherwise tailcall memchr. |
| 24 | Call strlen without setting up a full frame - it preserves x14/x15. |
| 25 | */ |
| 26 | |
| 27 | ENTRY (__rawmemchr) |
| 28 | cbz w1, L(do_strlen) |
| 29 | mov x2, -1 |
| 30 | b __memchr |
| 31 | |
| 32 | L(do_strlen): |
| 33 | mov x15, x30 |
| 34 | cfi_register (x30, x15) |
| 35 | mov x14, x0 |
| 36 | bl __strlen |
| 37 | add x0, x14, x0 |
| 38 | ret x15 |
| 39 | |
| 40 | END (__rawmemchr) |
| 41 | weak_alias (__rawmemchr, rawmemchr) |
| 42 | libc_hidden_builtin_def (__rawmemchr) |
| 43 | |