1 /* Public domain. */ 2 3 #ifndef _LINUX_STRING_H 4 #define _LINUX_STRING_H 5 6 #include <sys/types.h> 7 #include <sys/systm.h> 8 #include <sys/malloc.h> 9 #include <sys/stdint.h> 10 #include <sys/errno.h> 11 12 void *memchr_inv(const void *, int, size_t); 13 14 static inline void * 15 memset32(uint32_t *b, uint32_t c, size_t len) 16 { 17 uint32_t *dst = b; 18 while (len--) 19 *dst++ = c; 20 return b; 21 } 22 23 static inline void * 24 memset64(uint64_t *b, uint64_t c, size_t len) 25 { 26 uint64_t *dst = b; 27 while (len--) 28 *dst++ = c; 29 return b; 30 } 31 32 static inline void * 33 memset_p(void **p, void *v, size_t n) 34 { 35 #ifdef __LP64__ 36 return memset64((uint64_t *)p, (uintptr_t)v, n); 37 #else 38 return memset32((uint32_t *)p, (uintptr_t)v, n); 39 #endif 40 } 41 42 static inline void * 43 kmemdup(const void *src, size_t len, int flags) 44 { 45 void *p = malloc(len, M_DRM, flags); 46 if (p) 47 memcpy(p, src, len); 48 return (p); 49 } 50 51 static inline void * 52 kstrdup(const char *str, int flags) 53 { 54 size_t len; 55 char *p; 56 57 len = strlen(str) + 1; 58 p = malloc(len, M_DRM, flags); 59 if (p) 60 memcpy(p, str, len); 61 return (p); 62 } 63 64 static inline int 65 match_string(const char * const *array, size_t n, const char *str) 66 { 67 int i; 68 69 for (i = 0; i < n; i++) { 70 if (array[i] == NULL) 71 break; 72 if (!strcmp(array[i], str)) 73 return i; 74 } 75 76 return -EINVAL; 77 } 78 79 #endif 80