]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/berrno.h
1879ded31ab475d1bb688564ac118293cbe76163
[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 class berrno : public SMARTALLOC {
46    POOLMEM *buf_;
47    int berrno_;
48 public:
49    berrno(int pool=PM_EMSG);
50    ~berrno();
51    const char *strerror();
52    const char *strerror(int errnum);
53    void set_errno(int errnum);
54 };
55
56 /* Constructor */
57 inline berrno::berrno(int pool) 
58 {
59    berrno_ = errno;
60    buf_ = get_pool_memory(pool);
61 }
62    
63 inline berrno::~berrno()
64 {   
65    free_pool_memory(buf_);
66 }
67
68 inline const char *berrno::strerror(int errnum)
69 {
70    berrno_ = errnum;
71    return berrno::strerror();
72 }
73
74
75 inline void berrno::set_errno(int errnum)
76 {
77    berrno_ = errnum;
78 }