-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.h
60 lines (53 loc) · 1.1 KB
/
utils.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <string.h>
/**
* strestr - string end string - tests if the needle is the last
* substring in the haystack
*/
static inline char *strestr(const char *haystack, const char *needle)
{
haystack = haystack + strlen(haystack) - 1 - strlen(needle);
return strstr(haystack, needle);
}
/**
* @return Computed hash, memory pointed by len will contain length
* of the string with /0 character.
*/
static inline unsigned int gethash(const char *ptr, int *len)
{
unsigned int hash = 0;
const char *start = ptr;
do {
hash = 31 * hash + *ptr;
ptr++;
} while (*ptr);
*len = ptr - start + 1;
return hash;
}
#include "config.h"
#include <stdint.h>
#ifdef __linux__
#include <asm/byteorder.h>
#endif
#ifdef __linux__
static inline uint64_t from_le64(uint64_t v)
{
return __le64_to_cpu(v);
}
static inline uint64_t to_le64(uint64_t v)
{
return __cpu_to_le64(v);
}
#else
#ifdef FC_LITTLE_ENDIAN
static inline uint64_t from_le64(uint64_t v)
{
return v;
}
static inline uint64_t to_le64(uint64_t v)
{
return v;
}
#else
#error no generic big-endian support
#endif
#endif