New option: --mountpoint.
[dss.git] / err.h
1 /*
2 * Copyright (C) 2006-2010 Andre Noll <maan@tuebingen.mpg.de>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6 extern char *dss_errlist[];
7 extern char *dss_error_txt;
8
9 void dss_log_set_params(int ll, const char *file, int line, const char *func);
10 __printf_1_2 void dss_log(const char* fmt,...);
11
12 /**
13 * This bit indicates whether a number is considered a system error number
14 * If yes, the system errno is just the result of clearing this bit from
15 * the given number.
16 */
17 #define SYSTEM_ERROR_BIT 30
18
19 /** Check whether the system error bit is set. */
20 #define IS_SYSTEM_ERROR(num) (!!((num) & (1 << SYSTEM_ERROR_BIT)))
21
22 /** Set the system error bit for the given number. */
23 #define ERRNO_TO_DSS_ERROR(num) ((num) | (1 << SYSTEM_ERROR_BIT))
24
25 /**
26 * dss' version of strerror(3).
27 *
28 * \param num The error number.
29 *
30 * \return The error text of \a num.
31 */
32 static inline char *dss_strerror(int num)
33 {
34 assert(num > 0);
35 if (IS_SYSTEM_ERROR(num))
36 return strerror((num) & ((1 << SYSTEM_ERROR_BIT) - 1));
37 else
38 return dss_errlist[num];
39 }
40
41 #define DSS_ERRORS \
42 DSS_ERROR(SUCCESS, "success"), \
43 DSS_ERROR(SYNTAX, "syntax error"), \
44 DSS_ERROR(ATOI_OVERFLOW, "value too large"), \
45 DSS_ERROR(STRTOLL, "unknown strtoll error"), \
46 DSS_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \
47 DSS_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \
48 DSS_ERROR(INVALID_NUMBER, "invalid number"), \
49 DSS_ERROR(STRFTIME, "strftime() failed"), \
50 DSS_ERROR(LOCALTIME, "localtime() failed"), \
51 DSS_ERROR(MOUNTPOINT, "destination directory is no mountpoint"), \
52 DSS_ERROR(NULL_OPEN, "can not open /dev/null"), \
53 DSS_ERROR(DUP_PIPE, "exec error: can not create pipe"), \
54 DSS_ERROR(INVOLUNTARY_EXIT, "unexpected termination cause"), \
55 DSS_ERROR(BAD_EXIT_CODE, "unexpected exit code"), \
56 DSS_ERROR(SIGNAL_SIG_ERR, "signal() returned SIG_ERR"), \
57 DSS_ERROR(SIGNAL, "caught terminating signal"), \
58 DSS_ERROR(BUG, "values of beta might cause dom!"), \
59 DSS_ERROR(NOT_RUNNING, "dss not running"), \
60 DSS_ERROR(ALREADY_RUNNING, "dss already running"), \
61 DSS_ERROR(TOO_MANY_RSYNC_ERRORS, "too many consecutive rsync errors"), \
62 DSS_ERROR(LOPSUB, "lopsub error")
63
64 /**
65 * This is temporarily defined to expand to its first argument (prefixed by
66 * 'E_') and gets later redefined to expand to the error text only
67 */
68 #define DSS_ERROR(err, msg) E_ ## err
69
70 enum dss_error_codes {
71 DSS_ERRORS
72 };
73 #undef DSS_ERROR
74 #define DSS_ERROR(err, msg) msg
75 #define DEFINE_DSS_ERRLIST char *dss_errlist[] = {DSS_ERRORS}