common.h revision c93c1bc24becd643ea8948b33cbfd5cedacb215e
1/*
2 *
3 *	Various things common for all utilities
4 *
5 */
6
7#ifndef __QUOTA_COMMON_H__
8#define __QUOTA_COMMON_H__
9
10#ifndef __attribute__
11# if !defined __GNUC__ || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
12#  define __attribute__(x)
13# endif
14#endif
15
16#define log_fatal(exit_code, format, ...)	do { \
17		fprintf(stderr, "[FATAL] %s:%d:%s:: " format "\n", \
18			__FILE__, __LINE__, __func__, __VA_ARGS__); \
19		exit(exit_code); \
20	} while (0)
21
22#define log_err(format, ...)	fprintf(stderr, \
23				"[ERROR] %s:%d:%s:: " format "\n", \
24				__FILE__, __LINE__, __func__, __VA_ARGS__)
25
26#ifdef DEBUG_QUOTA
27# define log_debug(format, ...)	fprintf(stderr, \
28				"[DEBUG] %s:%d:%s:: " format "\n", \
29				__FILE__, __LINE__, __func__, __VA_ARGS__)
30#else
31# define log_debug(format, ...)
32#endif
33
34#define BUG_ON(x)		do { if ((x)) { \
35					fprintf(stderr, \
36						"BUG_ON: %s:%d:: ##x", \
37						__FILE__, __LINE__); \
38					exit(2); \
39				} } while (0)
40
41/* malloc() with error check */
42void *smalloc(size_t);
43
44/* realloc() with error check */
45void *srealloc(void *, size_t);
46
47/* Safe strncpy - always finishes string */
48void sstrncpy(char *, const char *, size_t);
49
50/* Safe strncat - always finishes string */
51void sstrncat(char *, const char *, size_t);
52
53/* Safe version of strdup() */
54char *sstrdup(const char *s);
55
56#endif /* __QUOTA_COMMON_H__ */
57