2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
31 * Kern Sibbald, July MMIV
36 * Extra bits set to interpret errno value differently from errno
39 #define b_errno_win32 (1<<29) /* user reserved bit */
41 #define b_errno_win32 0 /* On Unix/Linix system */
43 #define b_errno_exit (1<<28) /* child exited, exit code returned */
44 #define b_errno_signal (1<<27) /* child died, signal code returned */
47 * A more generalized way of handling errno that works with Unix, Windows,
48 * and with Bacula bpipes.
50 * It works by picking up errno and creating a memory pool buffer
51 * for editing the message. strerror() does the actual editing, and
54 * If bit 29 in m_berrno is set then it is a Win32 error, and we
55 * must do a GetLastError() to get the error code for formatting.
56 * If bit 29 in m_berrno is not set, then it is a Unix errno.
59 class berrno : public SMARTALLOC {
62 void format_win32_message();
64 berrno(int pool=PM_EMSG);
66 const char *bstrerror();
67 const char *bstrerror(int errnum);
68 void set_errno(int errnum);
69 int code() { return m_berrno & ~(b_errno_exit|b_errno_signal); }
70 int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
74 inline berrno::berrno(int pool)
77 m_buf = get_pool_memory(pool);
82 inline berrno::~berrno()
84 free_pool_memory(m_buf);
87 inline const char *berrno::bstrerror(int errnum)
90 return berrno::bstrerror();
94 inline void berrno::set_errno(int errnum)