4 * Kern Sibbald, July MMIV
8 Copyright (C) 2004-2006 Kern Sibbald
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 version 2 as amended with additional clauses defined in the
13 file LICENSE in the main source directory.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 the file LICENSE for additional details.
23 * Extra bits set to interpret errno value differently from errno
26 #define b_errno_win32 (1<<29) /* user reserved bit */
28 #define b_errno_exit (1<<28) /* child exited, exit code returned */
29 #define b_errno_signal (1<<27) /* child died, signal code returned */
32 * A more generalized way of handling errno that works with Unix, Windows,
33 * and with Bacula bpipes.
35 * It works by picking up errno and creating a memory pool buffer
36 * for editing the message. strerror() does the actual editing, and
39 * If bit 29 in berrno_ is set then it is a Win32 error, and we
40 * must to a GetLastError() to get the error code for formatting.
41 * If bit 29 in berrno_ is not set, then it is a Unix errno.
44 class berrno : public SMARTALLOC {
47 void format_win32_message();
49 berrno(int pool=PM_EMSG);
51 const char *strerror();
52 const char *strerror(int errnum);
53 void set_errno(int errnum);
54 int code() { return berrno_ & ~(b_errno_exit|b_errno_signal); }
55 int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
59 inline berrno::berrno(int pool)
62 buf_ = get_pool_memory(pool);
64 format_win32_message();
68 inline berrno::~berrno()
70 free_pool_memory(buf_);
73 inline const char *berrno::strerror(int errnum)
76 return berrno::strerror();
80 inline void berrno::set_errno(int errnum)