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 #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 #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 #define strchr(s1, c) __builtin_strchr(s1, c) 50 #endif 51 52 #ifndef __HAVE_ARCH_STRRCHR 53 char *strrchr(const char *, int); 54 #define strrchr(s1, c) __builtin_strrchr(s1, c) 55 #endif 56 57 #ifndef __HAVE_ARCH_STRSTR 58 char *strstr(const char *, const char *); 59 #define strstr(s1, s2) __builtin_strstr(s1, s2) 60 #endif 61 62 #ifndef __HAVE_ARCH_STRLEN 63 size_t strlen(const char *); 64 #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_MEMCMP 100 int memcmp(const void *, const void *, size_t); 101 #define memcmp(s1, s2, n) __builtin_memcmp(s1, s2, n) 102 #endif 103 104 #ifndef __HAVE_ARCH_MEMCHR 105 void *memchr(const void *, int, size_t); 106 #define memchr(s, c, n) __builtin_memchr(s, c, n) 107 #endif 108 109 void *memchr_inv(const void *, int, size_t); 110 111 #define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[]) 112 113 /* safe_xxx always NUL-terminates and returns !=0 if result is truncated. */ 114 #define safe_strcpy(d, s) ({ \ 115 BUILD_BUG_ON(!is_char_array(d)); \ 116 (strlcpy(d, s, sizeof(d)) >= sizeof(d)); \ 117 }) 118 #define safe_strcat(d, s) ({ \ 119 BUILD_BUG_ON(!is_char_array(d)); \ 120 (strlcat(d, s, sizeof(d)) >= sizeof(d)); \ 121 }) 122 123 #endif /* __XEN_STRING_H__ */ 124 /* 125 * Local variables: 126 * mode: C 127 * c-file-style: "BSD" 128 * c-basic-offset: 4 129 * indent-tabs-mode: nil 130 * End: 131 */ 132