]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/berrno.h
Add new berrno files
[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
31 /*
32  * A more generalized way of handling errno that works with Unix, Windows,
33  *  and with Bacula bpipes.
34  *
35  * It works by picking up errno and creating a memory pool buffer 
36  *  for editing the message. strerror() does the actual editing, and
37  *  it is thread safe.
38  *
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.
42  */
43 class berrno {
44    POOLMEM *buf_;
45    int berrno_;
46 public:
47    berrno(int pool=PM_EMSG);
48    ~berrno();
49    const char *strerror();
50    void set_errno(int errnum);
51 };
52
53 /* Constructor */
54 inline berrno::berrno(int pool) 
55 {
56    berrno_ = errno;
57    buf_ = get_pool_memory(pool);
58 }
59    
60 inline berrno::~berrno()
61 {   
62    free_pool_memory(buf_);
63 }
64
65 inline void berrno::set_errno(int errnum)
66 {
67    berrno_ = errnum;
68 }