]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/berrno.h
Eliminate dependency on man2html.
[bacula/bacula] / bacula / src / lib / berrno.h
index 88492e1772e160e31ad83602c880bdc08d21bb0c..46a6a3a3040d9e455046a615caef636fee30ee8e 100644 (file)
@@ -1,67 +1,82 @@
 /*
  *   Version $Id$
+ *
+ * Kern Sibbald, July MMIV
+ *
  */
-
 /*
-   Copyright (C) 2004 Kern Sibbald and John Walker
+   Copyright (C) 2004-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   modify it under the terms of the GNU General Public License
+   version 2 as amended with additional clauses defined in the
+   file LICENSE in the main source directory.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
-
-   Kern Sibbald, July MMIV
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+   the file LICENSE for additional details.
 
  */
 
+/*
+ * Extra bits set to interpret errno value differently from errno
+ */
 #ifdef HAVE_WIN32
-#define b_errno_win32 (1<<29)         /* user reserved bit */
+#define b_errno_win32  (1<<29)        /* user reserved bit */
 #endif
+#define b_errno_exit   (1<<28)        /* child exited, exit code returned */
+#define b_errno_signal (1<<27)        /* child died, signal code returned */
 
 /*
  * A more generalized way of handling errno that works with Unix, Windows,
  *  and with Bacula bpipes.
  *
- * It works by picking up errno and creating a memory pool buffer 
+ * It works by picking up errno and creating a memory pool buffer
  *  for editing the message. strerror() does the actual editing, and
  *  it is thread safe.
  *
  * If bit 29 in berrno_ is set then it is a Win32 error, and we
  *  must to a GetLastError() to get the error code for formatting.
  * If bit 29 in berrno_ is not set, then it is a Unix errno.
+ *
  */
-class berrno {
+class berrno : public SMARTALLOC {
    POOLMEM *buf_;
    int berrno_;
+   void format_win32_message();
 public:
    berrno(int pool=PM_EMSG);
    ~berrno();
    const char *strerror();
+   const char *strerror(int errnum);
    void set_errno(int errnum);
+   int code() { return berrno_ & ~(b_errno_exit|b_errno_signal); }
+   int code(int stat) { return stat & ~(b_errno_exit|b_errno_signal); }
 };
 
 /* Constructor */
-inline berrno::berrno(int pool) 
+inline berrno::berrno(int pool)
 {
    berrno_ = errno;
    buf_ = get_pool_memory(pool);
+#ifdef HAVE_WIN32
+   format_win32_message();
+#endif
 }
-   
+
 inline berrno::~berrno()
-{   
+{
    free_pool_memory(buf_);
 }
 
+inline const char *berrno::strerror(int errnum)
+{
+   berrno_ = errnum;
+   return berrno::strerror();
+}
+
+
 inline void berrno::set_errno(int errnum)
 {
    berrno_ = errnum;