/root/src/xen/xen/include/xen/string.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef __XEN_STRING_H__ |
2 | | #define __XEN_STRING_H__ |
3 | | |
4 | | #include <xen/types.h> /* for size_t */ |
5 | | |
6 | | /* |
7 | | * Include machine specific inline routines |
8 | | */ |
9 | | #include <asm/string.h> |
10 | | |
11 | | /* |
12 | | * These string functions are considered too dangerous for normal use. |
13 | | * Use safe_strcpy(), safe_strcat(), strlcpy(), strlcat() as appropriate. |
14 | | */ |
15 | | #define strcpy __xen_has_no_strcpy__ |
16 | | #define strcat __xen_has_no_strcat__ |
17 | | #define strncpy __xen_has_no_strncpy__ |
18 | | #define strncat __xen_has_no_strncat__ |
19 | | |
20 | | #ifndef __HAVE_ARCH_STRLCPY |
21 | | size_t strlcpy(char *, const char *, size_t); |
22 | | #endif |
23 | | |
24 | | #ifndef __HAVE_ARCH_STRLCAT |
25 | | size_t strlcat(char *, const char *, size_t); |
26 | | #endif |
27 | | |
28 | | #ifndef __HAVE_ARCH_STRCMP |
29 | | int strcmp(const char *, const char *); |
30 | 1.23k | #define strcmp(s1, s2) __builtin_strcmp(s1, s2) |
31 | | #endif |
32 | | |
33 | | #ifndef __HAVE_ARCH_STRNCMP |
34 | | int strncmp(const char *, const char *, size_t); |
35 | 95 | #define strncmp(s1, s2, n) __builtin_strncmp(s1, s2, n) |
36 | | #endif |
37 | | |
38 | | #ifndef __HAVE_ARCH_STRNICMP |
39 | | int strnicmp(const char *, const char *, size_t); |
40 | | #endif |
41 | | |
42 | | #ifndef __HAVE_ARCH_STRCASECMP |
43 | | int strcasecmp(const char *, const char *); |
44 | | #define strcasecmp(s1, s2) __builtin_strcasecmp(s1, s2) |
45 | | #endif |
46 | | |
47 | | #ifndef __HAVE_ARCH_STRCHR |
48 | | char *strchr(const char *, int); |
49 | 726 | #define strchr(s1, c) __builtin_strchr(s1, c) |
50 | | #endif |
51 | | |
52 | | #ifndef __HAVE_ARCH_STRRCHR |
53 | | char *strrchr(const char *, int); |
54 | 0 | #define strrchr(s1, c) __builtin_strrchr(s1, c) |
55 | | #endif |
56 | | |
57 | | #ifndef __HAVE_ARCH_STRSTR |
58 | | char *strstr(const char *, const char *); |
59 | 3 | #define strstr(s1, s2) __builtin_strstr(s1, s2) |
60 | | #endif |
61 | | |
62 | | #ifndef __HAVE_ARCH_STRLEN |
63 | | size_t strlen(const char *); |
64 | 403 | #define strlen(s1) __builtin_strlen(s1) |
65 | | #endif |
66 | | |
67 | | #ifndef __HAVE_ARCH_STRNLEN |
68 | | size_t strnlen(const char *, size_t); |
69 | | #endif |
70 | | |
71 | | #ifndef __HAVE_ARCH_STRPBRK |
72 | | char *strpbrk(const char *, const char *); |
73 | | #endif |
74 | | |
75 | | #ifndef __HAVE_ARCH_STRSEP |
76 | | char *strsep(char **, const char *); |
77 | | #endif |
78 | | |
79 | | #ifndef __HAVE_ARCH_STRSPN |
80 | | size_t strspn(const char *, const char *); |
81 | | #endif |
82 | | |
83 | | |
84 | | #ifndef __HAVE_ARCH_MEMSET |
85 | | void *memset(void *, int, size_t); |
86 | | #define memset(s, c, n) __builtin_memset(s, c, n) |
87 | | #endif |
88 | | |
89 | | #ifndef __HAVE_ARCH_MEMCPY |
90 | | void *memcpy(void *, const void *, size_t); |
91 | | #define memcpy(d, s, n) __builtin_memcpy(d, s, n) |
92 | | #endif |
93 | | |
94 | | #ifndef __HAVE_ARCH_MEMMOVE |
95 | | void *memmove(void *, const void *, size_t); |
96 | | #define memmove(d, s, n) __builtin_memmove(d, s, n) |
97 | | #endif |
98 | | |
99 | | #ifndef __HAVE_ARCH_MEMSCAN |
100 | | void *memscan(void *, int, size_t); |
101 | | #endif |
102 | | |
103 | | #ifndef __HAVE_ARCH_MEMCMP |
104 | | int memcmp(const void *, const void *, size_t); |
105 | 101k | #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n) |
106 | | #endif |
107 | | |
108 | | #ifndef __HAVE_ARCH_MEMCHR |
109 | | void *memchr(const void *, int, size_t); |
110 | | #define memchr(s, c, n) __builtin_memchr(s, c, n) |
111 | | #endif |
112 | | |
113 | | #define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[]) |
114 | | |
115 | | /* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */ |
116 | 18 | #define safe_strcpy(d, s) ({ \ |
117 | 18 | BUILD_BUG_ON(!is_char_array(d)); \ |
118 | 0 | (strlcpy(d, s, sizeof(d)) >= sizeof(d)); \ |
119 | 18 | }) |
120 | 0 | #define safe_strcat(d, s) ({ \ |
121 | 0 | BUILD_BUG_ON(!is_char_array(d)); \ |
122 | 0 | (strlcat(d, s, sizeof(d)) >= sizeof(d)); \ |
123 | 0 | }) |
124 | | |
125 | | #endif /* __XEN_STRING_H__ */ |
126 | | /* |
127 | | * Local variables: |
128 | | * mode: C |
129 | | * c-file-style: "BSD" |
130 | | * c-basic-offset: 4 |
131 | | * indent-tabs-mode: nil |
132 | | * End: |
133 | | */ |