6 Copyright (C) 2004 Kern Sibbald and John Walker
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but 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
19 License along with this program; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 Kern Sibbald, July MMIV
28 #define b_errno_win32 (1<<29) /* user reserved bit */
30 #define b_errno_exit (1<<28) /* child exited, exit code returned */
31 #define b_errno_signal (1<<27) /* child died, signal code returned */
34 * A more generalized way of handling errno that works with Unix, Windows,
35 * and with Bacula bpipes.
37 * It works by picking up errno and creating a memory pool buffer
38 * for editing the message. strerror() does the actual editing, and
41 * If bit 29 in berrno_ is set then it is a Win32 error, and we
42 * must to a GetLastError() to get the error code for formatting.
43 * If bit 29 in berrno_ is not set, then it is a Unix errno.
45 class berrno : public SMARTALLOC {
49 berrno(int pool=PM_EMSG);
51 const char *strerror();
52 const char *strerror(int errnum);
53 void set_errno(int errnum);
57 inline berrno::berrno(int pool)
60 buf_ = get_pool_memory(pool);
63 inline berrno::~berrno()
65 free_pool_memory(buf_);
68 inline const char *berrno::strerror(int errnum)
71 return berrno::strerror();
75 inline void berrno::set_errno(int errnum)