1 /* Hardware capability support for run-time dynamic loader. String splitting.
2 Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <dl-hwcaps.h>
24 _dl_hwcaps_split (struct dl_hwcaps_split
*s
)
26 if (s
->segment
== NULL
)
29 /* Skip over the previous segment. */
30 s
->segment
+= s
->length
;
32 /* Consume delimiters. This also avoids returning an empty
34 while (*s
->segment
== ':')
36 if (*s
->segment
== '\0')
39 /* This could use strchrnul, but we would have to link the function
40 into ld.so for that. */
41 const char *colon
= strchr (s
->segment
, ':');
43 s
->length
= strlen (s
->segment
);
45 s
->length
= colon
- s
->segment
;
50 _dl_hwcaps_split_masked (struct dl_hwcaps_split_masked
*s
)
54 if (!_dl_hwcaps_split (&s
->split
))
56 bool active
= s
->bitmask
& 1;
58 if (active
&& _dl_hwcaps_contains (s
->mask
,
59 s
->split
.segment
, s
->split
.length
))
65 _dl_hwcaps_contains (const char *hwcaps
, const char *name
, size_t name_length
)
70 struct dl_hwcaps_split split
;
71 _dl_hwcaps_split_init (&split
, hwcaps
);
72 while (_dl_hwcaps_split (&split
))
73 if (split
.length
== name_length
74 && memcmp (split
.segment
, name
, name_length
) == 0)