common.h revision f239fefc14226f655477179801c734749a04d4b4
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#ifdef ENABLE_NLS
17#include <libintl.h>
18#include <locale.h>
19#define _(a) (gettext (a))
20#ifdef gettext_noop
21#define N_(a) gettext_noop (a)
22#else
23#define N_(a) (a)
24#endif
25#define P_(singular, plural, n) (ngettext (singular, plural, n))
26#ifndef NLS_CAT_NAME
27#define NLS_CAT_NAME "e2fsprogs"
28#endif
29#ifndef LOCALEDIR
30#define LOCALEDIR "/usr/share/locale"
31#endif
32#else
33#define _(a) (a)
34#define N_(a) a
35#define P_(singular, plural, n) ((n) == 1 ? (singular) : (plural))
36#endif
37
38#define log_fatal(exit_code, format, ...)	do { \
39		fprintf(stderr, _("[FATAL] %s:%d:%s:: " format "\n"), \
40			__FILE__, __LINE__, __func__, __VA_ARGS__); \
41		exit(exit_code); \
42	} while (0)
43
44#define log_err(format, ...)	fprintf(stderr, \
45				_("[ERROR] %s:%d:%s:: " format "\n"), \
46				__FILE__, __LINE__, __func__, __VA_ARGS__)
47
48#ifdef DEBUG_QUOTA
49# define log_debug(format, ...)	fprintf(stderr, \
50				_("[DEBUG] %s:%d:%s:: " format "\n"), \
51				__FILE__, __LINE__, __func__, __VA_ARGS__)
52#else
53# define log_debug(format, ...)
54#endif
55
56#define BUG_ON(x)		do { if ((x)) { \
57					fprintf(stderr, \
58						_("BUG_ON: %s:%d:: ##x"), \
59						__FILE__, __LINE__); \
60					exit(2); \
61				} } while (0)
62
63/* malloc() with error check */
64void *smalloc(size_t);
65
66/* realloc() with error check */
67void *srealloc(void *, size_t);
68
69/* Safe strncpy - always finishes string */
70void sstrncpy(char *, const char *, size_t);
71
72/* Safe strncat - always finishes string */
73void sstrncat(char *, const char *, size_t);
74
75/* Safe version of strdup() */
76char *sstrdup(const char *s);
77
78#endif /* __QUOTA_COMMON_H__ */
79