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