util.h (614B)
1 2 #ifndef NDB_UTIL_H 3 #define NDB_UTIL_H 4 5 static inline int min(int a, int b) { 6 return a < b ? a : b; 7 } 8 9 static inline int max(int a, int b) { 10 return a > b ? a : b; 11 } 12 13 static inline void* memdup(const void* src, size_t size) { 14 void* dest = malloc(size); 15 if (dest == NULL) { 16 return NULL; // Memory allocation failed 17 } 18 memcpy(dest, src, size); 19 return dest; 20 } 21 22 static inline char *strdupn(const char *src, size_t size) { 23 char* dest = malloc(size+1); 24 if (dest == NULL) { 25 return NULL; // Memory allocation failed 26 } 27 memcpy(dest, src, size); 28 dest[size] = '\0'; 29 return dest; 30 } 31 #endif // NDB_UTIL_H 32