2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Kern Sibbald, July MMIV
26 * Extra bits set to interpret errno value differently from errno
29 #define b_errno_win32 (1<<29) /* user reserved bit */
30 #define b_errno_WSA (1<<26)
32 #define b_errno_win32 0 /* On Unix/Linix system */
34 #define b_errno_exit (1<<28) /* child exited, exit code returned */
35 #define b_errno_signal (1<<27) /* child died, signal code returned */
38 * A more generalized way of handling errno that works with Unix, Windows,
39 * and with Bacula bpipes.
41 * It works by picking up errno and creating a memory pool buffer
42 * for editing the message. strerror() does the actual editing, and
45 * If bit 29 in m_berrno is set then it is a Win32 error, and we
46 * must do a GetLastError() to get the error code for formatting.
47 * If bit 29 in m_berrno is not set, then it is a Unix errno.
50 class berrno : public SMARTALLOC {
53 void format_win32_message();
55 berrno(int pool=PM_EMSG);
57 const char *bstrerror();
58 const char *bstrerror(int errnum);
59 void set_errno(int errnum);
60 int code() { return m_berrno & ~(b_errno_exit|b_errno_signal); }
61 int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
65 inline berrno::berrno(int pool)
68 m_buf = get_pool_memory(pool);
73 inline berrno::~berrno()
75 free_pool_memory(m_buf);
78 inline const char *berrno::bstrerror(int errnum)
81 return berrno::bstrerror();
85 inline void berrno::set_errno(int errnum)