diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2022-10-29 19:18:52 +0200 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2023-02-05 00:24:13 +0100 |
commit | 436279a01c8e49265c504eb4e6bc5b97fe8290d8 (patch) | |
tree | 03c1303b3be31a49e46dd1d0ccdf3b196508045f /linux/LinuxProcessList.c | |
parent | da494896914a327476ab7e0298619d742a6205d4 (diff) |
Linux: move helper function to top of file
Make them reusable for function defined earlier in the file.
Diffstat (limited to 'linux/LinuxProcessList.c')
-rw-r--r-- | linux/LinuxProcessList.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 8490d82c..27792bf8 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -88,6 +88,48 @@ static FILE* fopenat(openat_arg_t openatArg, const char* pathname, const char* m return stream; } +static inline uint64_t fast_strtoull_dec(char** str, int maxlen) { + register uint64_t result = 0; + + if (!maxlen) + --maxlen; + + while (maxlen-- && **str >= '0' && **str <= '9') { + result *= 10; + result += **str - '0'; + (*str)++; + } + + return result; +} + +static inline uint64_t fast_strtoull_hex(char** str, int maxlen) { + register uint64_t result = 0; + register int nibble, letter; + const long valid_mask = 0x03FF007E; + + if (!maxlen) + --maxlen; + + while (maxlen--) { + nibble = (unsigned char)**str; + if (!(valid_mask & (1 << (nibble & 0x1F)))) + break; + if ((nibble < '0') || (nibble & ~0x20) > 'F') + break; + letter = (nibble & 0x40) ? 'A' - '9' - 1 : 0; + nibble &=~0x20; // to upper + nibble ^= 0x10; // switch letters and digits + nibble -= letter; + nibble &= 0x0f; + result <<= 4; + result += (uint64_t)nibble; + (*str)++; + } + + return result; +} + static int sortTtyDrivers(const void* va, const void* vb) { const TtyDriver* a = (const TtyDriver*) va; const TtyDriver* b = (const TtyDriver*) vb; @@ -574,48 +616,6 @@ typedef struct LibraryData_ { bool exec; } LibraryData; -static inline uint64_t fast_strtoull_dec(char** str, int maxlen) { - register uint64_t result = 0; - - if (!maxlen) - --maxlen; - - while (maxlen-- && **str >= '0' && **str <= '9') { - result *= 10; - result += **str - '0'; - (*str)++; - } - - return result; -} - -static inline uint64_t fast_strtoull_hex(char** str, int maxlen) { - register uint64_t result = 0; - register int nibble, letter; - const long valid_mask = 0x03FF007E; - - if (!maxlen) - --maxlen; - - while (maxlen--) { - nibble = (unsigned char)**str; - if (!(valid_mask & (1 << (nibble & 0x1F)))) - break; - if ((nibble < '0') || (nibble & ~0x20) > 'F') - break; - letter = (nibble & 0x40) ? 'A' - '9' - 1 : 0; - nibble &=~0x20; // to upper - nibble ^= 0x10; // switch letters and digits - nibble -= letter; - nibble &= 0x0f; - result <<= 4; - result += (uint64_t)nibble; - (*str)++; - } - - return result; -} - static void LinuxProcessList_calcLibSize_helper(ATTR_UNUSED ht_key_t key, void* value, void* data) { if (!data) return; |