1 #ifndef NETDATA_INLINED_H
2 #define NETDATA_INLINED_H
7 typedef uint32_t kernel_uint_t;
8 #define str2kernel_unit_t(string) str2uint32_t(string)
9 #define KERNEL_UINT_FORMAT "%u"
11 typedef uint64_t kernel_uint_t;
12 #define str2kernel_unit_t(string) str2uint64_t(string)
13 #define KERNEL_UINT_FORMAT "%lu"
16 #define str2pid_t(string) str2uint32_t(string)
19 // for faster execution, allow the compiler to inline
20 // these functions that are called thousands of times per second
22 static inline uint32_t simple_hash(const char *name) {
23 unsigned char *s = (unsigned char *) name;
24 uint32_t hval = 0x811c9dc5;
27 hval ^= (uint32_t) *s++;
32 static inline uint32_t simple_uhash(const char *name) {
33 unsigned char *s = (unsigned char *) name;
34 uint32_t hval = 0x811c9dc5, c;
36 if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
43 static inline int simple_hash_strcmp(const char *name, const char *b, uint32_t *hash) {
44 unsigned char *s = (unsigned char *) name;
45 uint32_t hval = 0x811c9dc5;
48 if(!ret) ret = *s - *b++;
50 hval ^= (uint32_t) *s++;
56 static inline int str2i(const char *s) {
58 char c, negative = (*s == '-');
60 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
65 if(unlikely(negative))
71 static inline long str2l(const char *s) {
73 char c, negative = (*s == '-');
75 for(c = (negative)?*(++s):*s; c >= '0' && c <= '9' ; c = *(++s)) {
80 if(unlikely(negative))
86 static inline uint32_t str2uint32_t(const char *s) {
89 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
96 static inline uint64_t str2uint64_t(const char *s) {
99 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
106 static inline unsigned long str2ul(const char *s) {
109 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
116 static inline unsigned long long str2ull(const char *s) {
117 unsigned long long n = 0;
119 for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) {
126 #ifdef NETDATA_STRCMP_OVERRIDE
130 #define strcmp(a, b) strsame(a, b)
131 static inline int strsame(const char *a, const char *b) {
132 if(unlikely(a == b)) return 0;
133 while(*a && *a == *b) { a++; b++; }
136 #endif // NETDATA_STRSAME
138 static inline int read_single_number_file(const char *filename, unsigned long long *result) {
141 int fd = open(filename, O_RDONLY, 0666);
142 if(unlikely(fd == -1)) {
147 ssize_t r = read(fd, buffer, 30);
148 if(unlikely(r == -1)) {
156 *result = str2ull(buffer);
160 #endif //NETDATA_INLINED_H