-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
47 lines (38 loc) · 970 Bytes
/
util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* util.h - utility functions
This file is part of yalloc, yet another memory allocator providing affordable safety in a compact package.
SPDX-FileCopyrightText: © 2024 Joris van der Geer
SPDX-License-Identifier: GPL-3.0-or-later
*/
static size_t atox(cchar *s)
{
size_t x = 0;
char c;
while ( (c = *s++) ) {
if (c == '.') continue;
x <<= 4;
if (c >= '0' && c <= '9') x += (size_t)c - '0';
else {
c |= 0x20;
if (c >= 'a' && c <= 'f') x += (size_t)c - 'a' + 10;
else return x;
}
}
return x;
}
static size_t atoul(cchar *p)
{
size_t x = 0;
char c;
if (*p == '0' && (p[1] | 0x20) == 'x') return atox(p + 2);
while ( (c = *p++) ) {
if (c == '.') continue;
if (c >= '0' && c <= '9') x = x * 10 + (size_t)(c - '0');
else break;
}
return x;
}
static ub4 atou(cchar *p) { return (ub4)atoul(p); }
static inline Const bool sometimes(const ub4 a,const ub4 b)
{
return ( (a & b) == b);
}