]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/berrno.h
- Add code to ensure that reserved but unused volumes
[bacula/bacula] / bacula / src / lib / berrno.h
1 /*
2  *   Version $Id$
3  */
4
5 /*
6    Copyright (C) 2004 Kern Sibbald and John Walker
7
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.
12
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.
17
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,
21    MA 02111-1307, USA.
22
23    Kern Sibbald, July MMIV
24
25  */
26
27 #ifdef HAVE_WIN32
28 #define b_errno_win32  (1<<29)        /* user reserved bit */
29 #endif
30 #define b_errno_exit   (1<<28)        /* child exited, exit code returned */
31 #define b_errno_signal (1<<27)        /* child died, signal code returned */
32
33 /*
34  * A more generalized way of handling errno that works with Unix, Windows,
35  *  and with Bacula bpipes.
36  *
37  * It works by picking up errno and creating a memory pool buffer
38  *  for editing the message. strerror() does the actual editing, and
39  *  it is thread safe.
40  *
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.
44  *
45  */
46 class berrno : public SMARTALLOC {
47    POOLMEM *buf_;
48    int berrno_;
49 public:
50    berrno(int pool=PM_EMSG);
51    ~berrno();
52    const char *strerror();
53    const char *strerror(int errnum);
54    void set_errno(int errnum);
55 };
56
57 /* Constructor */
58 inline berrno::berrno(int pool)
59 {
60    berrno_ = errno;
61    buf_ = get_pool_memory(pool);
62 }
63
64 inline berrno::~berrno()
65 {
66    free_pool_memory(buf_);
67 }
68
69 inline const char *berrno::strerror(int errnum)
70 {
71    berrno_ = errnum;
72    return berrno::strerror();
73 }
74
75
76 inline void berrno::set_errno(int errnum)
77 {
78    berrno_ = errnum;
79 }