1 #ifdef HAVE_CONFIG_H 2 #include "config.h" 3 #endif 4 5 #ifdef HAVE_STDLIB_H 6 #include <stdlib.h> 7 #endif 8 9 #include "misc.h" 10 #include "logging.h" 11 12 /** 13 * ntfs_calloc 14 * 15 * Return a pointer to the allocated memory or NULL if the request fails. 16 */ 17 void *ntfs_calloc(size_t size) 18 { 19 void *p; 20 21 p = calloc(1, size); 22 if (!p) 23 ntfs_log_perror("Failed to calloc %lld bytes", (long long)size); 24 return p; 25 } 26 27 void *ntfs_malloc(size_t size) 28 { 29 void *p; 30 31 p = malloc(size); 32 if (!p) 33 ntfs_log_perror("Failed to malloc %lld bytes", (long long)size); 34 return p; 35 } 36 37 #if defined(__BEOS__) || defined(__HAIKU__) 38 #include <stdio.h> 39 int ntfs_snprintf(char *buff, size_t size, const char *format, ...) 40 { 41 int ret; 42 char buffer[BUF_SIZE]; 43 va_list args; 44 va_start(args, format); 45 memset(buffer,0,BUF_SIZE); 46 ret = sprintf(buffer, format, args); 47 va_end(args); 48 strncpy(buff,buffer,size); 49 return ret; 50 } 51 #endif 52