-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.h
46 lines (32 loc) · 902 Bytes
/
misc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef MISC_H__
#define MISC_H__
#include <stdarg.h>
#define __printf_fmt(fmt,args) __attribute__((format (printf,fmt,args)))
#define ARRAY_LENGTH(a) (sizeof(a) / sizeof(*a))
/*
* Calls perror(msg) and abort()
*/
void system_error(const char *msg);
/*
* Print the message on stderr
*/
__printf_fmt(1,2) void custom_warn(const char *format, ...);
/*
* Print the message on stderr and abort()
*/
__printf_fmt(1,2) void custom_error(const char *format, ...);
/*
* sprintf that allocate the buffer to write in
* The buffer must be freed with free()
*/
__printf_fmt(2,3) int asprintf(char **str, const char *format, ...);
/*
* vsprintf that allocate the buffer to write in
* The buffer must be freed with free()
*/
int avsprintf(char **str, const char *format, va_list ap);
/*
* Duplicate a string into a new buffer allocated by malloc.
*/
char *strdup(const char *str);
#endif