4 * Kern Sibbald, July MMIV
8 Bacula® - The Network Backup Solution
10 Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
12 The main author of Bacula is Kern Sibbald, with contributions from
13 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
32 Switzerland, email:ftf@fsfeurope.org.
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_exit (1<<28) /* child exited, exit code returned */
42 #define b_errno_signal (1<<27) /* child died, signal code returned */
45 * A more generalized way of handling errno that works with Unix, Windows,
46 * and with Bacula bpipes.
48 * It works by picking up errno and creating a memory pool buffer
49 * for editing the message. strerror() does the actual editing, and
52 * If bit 29 in berrno_ is set then it is a Win32 error, and we
53 * must do a GetLastError() to get the error code for formatting.
54 * If bit 29 in berrno_ is not set, then it is a Unix errno.
57 class berrno : public SMARTALLOC {
60 void format_win32_message();
62 berrno(int pool=PM_EMSG);
64 const char *strerror();
65 const char *strerror(int errnum);
66 void set_errno(int errnum);
67 int code() { return berrno_ & ~(b_errno_exit|b_errno_signal); }
68 int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
72 inline berrno::berrno(int pool)
75 buf_ = get_pool_memory(pool);
77 format_win32_message();
81 inline berrno::~berrno()
83 free_pool_memory(buf_);
86 inline const char *berrno::strerror(int errnum)
89 return berrno::strerror();
93 inline void berrno::set_errno(int errnum)