nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

util.h (480B)


      1 
      2 #ifndef NDB_UTIL_H
      3 #define NDB_UTIL_H
      4 
      5 static inline void* memdup(const void* src, size_t size) {
      6 	void* dest = malloc(size);
      7 	if (dest == NULL) {
      8 		return NULL;  // Memory allocation failed
      9 	}
     10 	memcpy(dest, src, size);
     11 	return dest;
     12 }
     13 
     14 static inline char *strdupn(const char *src, size_t size) {
     15 	char* dest = malloc(size+1);
     16 	if (dest == NULL) {
     17 		return NULL;  // Memory allocation failed
     18 	}
     19 	memcpy(dest, src, size);
     20 	dest[size] = '\0';
     21 	return dest;
     22 }
     23 #endif // NDB_UTIL_H
     24