xref: /aosp_15_r20/bionic/libc/include/strings.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*	$NetBSD: strings.h,v 1.10 2005/02/03 04:39:32 perry Exp $	*/
2*8d67ca89SAndroid Build Coastguard Worker 
3*8d67ca89SAndroid Build Coastguard Worker /*-
4*8d67ca89SAndroid Build Coastguard Worker  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5*8d67ca89SAndroid Build Coastguard Worker  * All rights reserved.
6*8d67ca89SAndroid Build Coastguard Worker  *
7*8d67ca89SAndroid Build Coastguard Worker  * This code is derived from software contributed to The NetBSD Foundation
8*8d67ca89SAndroid Build Coastguard Worker  * by Klaus Klein.
9*8d67ca89SAndroid Build Coastguard Worker  *
10*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
11*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
12*8d67ca89SAndroid Build Coastguard Worker  * are met:
13*8d67ca89SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
14*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
15*8d67ca89SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
16*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
17*8d67ca89SAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
18*8d67ca89SAndroid Build Coastguard Worker  * 3. All advertising materials mentioning features or use of this software
19*8d67ca89SAndroid Build Coastguard Worker  *    must display the following acknowledgement:
20*8d67ca89SAndroid Build Coastguard Worker  *        This product includes software developed by the NetBSD
21*8d67ca89SAndroid Build Coastguard Worker  *        Foundation, Inc. and its contributors.
22*8d67ca89SAndroid Build Coastguard Worker  * 4. Neither the name of The NetBSD Foundation nor the names of its
23*8d67ca89SAndroid Build Coastguard Worker  *    contributors may be used to endorse or promote products derived
24*8d67ca89SAndroid Build Coastguard Worker  *    from this software without specific prior written permission.
25*8d67ca89SAndroid Build Coastguard Worker  *
26*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27*8d67ca89SAndroid Build Coastguard Worker  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28*8d67ca89SAndroid Build Coastguard Worker  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29*8d67ca89SAndroid Build Coastguard Worker  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30*8d67ca89SAndroid Build Coastguard Worker  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31*8d67ca89SAndroid Build Coastguard Worker  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32*8d67ca89SAndroid Build Coastguard Worker  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33*8d67ca89SAndroid Build Coastguard Worker  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34*8d67ca89SAndroid Build Coastguard Worker  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35*8d67ca89SAndroid Build Coastguard Worker  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36*8d67ca89SAndroid Build Coastguard Worker  * POSSIBILITY OF SUCH DAMAGE.
37*8d67ca89SAndroid Build Coastguard Worker  */
38*8d67ca89SAndroid Build Coastguard Worker 
39*8d67ca89SAndroid Build Coastguard Worker #pragma once
40*8d67ca89SAndroid Build Coastguard Worker 
41*8d67ca89SAndroid Build Coastguard Worker /**
42*8d67ca89SAndroid Build Coastguard Worker  * @file strings.h
43*8d67ca89SAndroid Build Coastguard Worker  * @brief Extra string functions.
44*8d67ca89SAndroid Build Coastguard Worker  */
45*8d67ca89SAndroid Build Coastguard Worker 
46*8d67ca89SAndroid Build Coastguard Worker #include <sys/cdefs.h>
47*8d67ca89SAndroid Build Coastguard Worker 
48*8d67ca89SAndroid Build Coastguard Worker #include <sys/types.h>
49*8d67ca89SAndroid Build Coastguard Worker #include <xlocale.h>
50*8d67ca89SAndroid Build Coastguard Worker 
51*8d67ca89SAndroid Build Coastguard Worker #include <bits/strcasecmp.h>
52*8d67ca89SAndroid Build Coastguard Worker 
53*8d67ca89SAndroid Build Coastguard Worker #if !defined(__BIONIC_STRINGS_INLINE)
54*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_STRINGS_INLINE static __inline
55*8d67ca89SAndroid Build Coastguard Worker #endif
56*8d67ca89SAndroid Build Coastguard Worker 
57*8d67ca89SAndroid Build Coastguard Worker #undef ffs
58*8d67ca89SAndroid Build Coastguard Worker #undef ffsl
59*8d67ca89SAndroid Build Coastguard Worker #undef ffsll
60*8d67ca89SAndroid Build Coastguard Worker 
61*8d67ca89SAndroid Build Coastguard Worker __BEGIN_DECLS
62*8d67ca89SAndroid Build Coastguard Worker 
63*8d67ca89SAndroid Build Coastguard Worker /** Deprecated. Use memmove() instead. */
64*8d67ca89SAndroid Build Coastguard Worker #define bcopy(b1, b2, len) __bionic_bcopy((b1), (b2), (len))
__bionic_bcopy(const void * _Nonnull b1,void * _Nonnull b2,size_t len)65*8d67ca89SAndroid Build Coastguard Worker static __inline __always_inline void __bionic_bcopy(const void* _Nonnull b1, void* _Nonnull b2, size_t len) {
66*8d67ca89SAndroid Build Coastguard Worker   __builtin_memmove(b2, b1, len);
67*8d67ca89SAndroid Build Coastguard Worker }
68*8d67ca89SAndroid Build Coastguard Worker 
69*8d67ca89SAndroid Build Coastguard Worker /** Deprecated. Use memset() instead. */
70*8d67ca89SAndroid Build Coastguard Worker #define bzero(b, len) __bionic_bzero((b), (len))
__bionic_bzero(void * _Nonnull b,size_t len)71*8d67ca89SAndroid Build Coastguard Worker static __inline __always_inline void __bionic_bzero(void* _Nonnull b, size_t len) {
72*8d67ca89SAndroid Build Coastguard Worker   __builtin_memset(b, 0, len);
73*8d67ca89SAndroid Build Coastguard Worker }
74*8d67ca89SAndroid Build Coastguard Worker 
75*8d67ca89SAndroid Build Coastguard Worker /**
76*8d67ca89SAndroid Build Coastguard Worker  * [ffs(3)](https://man7.org/linux/man-pages/man3/ffs.3.html) finds the
77*8d67ca89SAndroid Build Coastguard Worker  * first set bit in `__n`.
78*8d67ca89SAndroid Build Coastguard Worker  *
79*8d67ca89SAndroid Build Coastguard Worker  * Returns 0 if no bit is set, or the index of the lowest set bit (counting
80*8d67ca89SAndroid Build Coastguard Worker  * from 1) otherwise.
81*8d67ca89SAndroid Build Coastguard Worker  */
ffs(int __n)82*8d67ca89SAndroid Build Coastguard Worker __BIONIC_STRINGS_INLINE int ffs(int __n) {
83*8d67ca89SAndroid Build Coastguard Worker   return __builtin_ffs(__n);
84*8d67ca89SAndroid Build Coastguard Worker }
85*8d67ca89SAndroid Build Coastguard Worker 
86*8d67ca89SAndroid Build Coastguard Worker /**
87*8d67ca89SAndroid Build Coastguard Worker  * [ffsl(3)](https://man7.org/linux/man-pages/man3/ffsl.3.html) finds the
88*8d67ca89SAndroid Build Coastguard Worker  * first set bit in `__n`.
89*8d67ca89SAndroid Build Coastguard Worker  *
90*8d67ca89SAndroid Build Coastguard Worker  * Returns 0 if no bit is set, or the index of the lowest set bit (counting
91*8d67ca89SAndroid Build Coastguard Worker  * from 1) otherwise.
92*8d67ca89SAndroid Build Coastguard Worker  */
ffsl(long __n)93*8d67ca89SAndroid Build Coastguard Worker __BIONIC_STRINGS_INLINE int ffsl(long __n) {
94*8d67ca89SAndroid Build Coastguard Worker   return __builtin_ffsl(__n);
95*8d67ca89SAndroid Build Coastguard Worker }
96*8d67ca89SAndroid Build Coastguard Worker 
97*8d67ca89SAndroid Build Coastguard Worker /**
98*8d67ca89SAndroid Build Coastguard Worker  * [ffsll(3)](https://man7.org/linux/man-pages/man3/ffsll.3.html) finds the
99*8d67ca89SAndroid Build Coastguard Worker  * first set bit in `__n`.
100*8d67ca89SAndroid Build Coastguard Worker  *
101*8d67ca89SAndroid Build Coastguard Worker  * Returns 0 if no bit is set, or the index of the lowest set bit (counting
102*8d67ca89SAndroid Build Coastguard Worker  * from 1) otherwise.
103*8d67ca89SAndroid Build Coastguard Worker  */
ffsll(long long __n)104*8d67ca89SAndroid Build Coastguard Worker __BIONIC_STRINGS_INLINE int ffsll(long long __n) {
105*8d67ca89SAndroid Build Coastguard Worker   return __builtin_ffsll(__n);
106*8d67ca89SAndroid Build Coastguard Worker }
107*8d67ca89SAndroid Build Coastguard Worker 
108*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
109*8d67ca89SAndroid Build Coastguard Worker #include <bits/fortify/strings.h>
110*8d67ca89SAndroid Build Coastguard Worker #endif
111*8d67ca89SAndroid Build Coastguard Worker 
112*8d67ca89SAndroid Build Coastguard Worker __END_DECLS
113