LCOV - code coverage report
Current view: top level - src - berrno.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 0 16 0.0 %
Date: 2017-07-30 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :    Bacula® - The Network Backup Solution
       3             : 
       4             :    Copyright (C) 2004-2009 Free Software Foundation Europe e.V.
       5             : 
       6             :    The main author of Bacula is Kern Sibbald, with contributions from
       7             :    many others, a complete list can be found in the file AUTHORS.
       8             :    This program is Free Software; you can redistribute it and/or
       9             :    modify it under the terms of version three of the GNU Affero General Public
      10             :    License as published by the Free Software Foundation and included
      11             :    in the file LICENSE.
      12             : 
      13             :    This program is distributed in the hope that it will be useful, but
      14             :    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 Affero General Public License
      19             :    along with this program; if not, write to the Free Software
      20             :    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
      21             :    02110-1301, USA.
      22             : 
      23             :    Bacula® is a registered trademark of Kern Sibbald.
      24             :    The licensor of Bacula is the Free Software Foundation Europe
      25             :    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
      26             :    Switzerland, email:ftf@fsfeurope.org.
      27             : */
      28             : /*
      29             :  *   Kern Sibbald, July MMIV
      30             :  */
      31             : /*
      32             :  * Originally from bacula-5.0.3:src/lib/berrno.h.
      33             :  * Converted to be C instead of a C++ class.
      34             :  *    Graham Keeling, 2014.
      35             :  */
      36             : 
      37             : #include "burp.h"
      38             : #include "berrno.h"
      39             : 
      40           0 : void berrno_init(struct berrno *b)
      41             : {
      42           0 :         b->m_berrno=errno;
      43           0 :         *(b->m_buf)=0;
      44           0 :         errno=b->m_berrno;
      45           0 : }
      46             : 
      47           0 : static int bstrerror(int errnum, char *buf, size_t bufsiz)
      48             : {
      49           0 :         int stat=0;
      50             :         const char *msg;
      51             : 
      52           0 :         if(!(msg=strerror(errnum)))
      53             :         {
      54           0 :                 msg="Bad errno";
      55           0 :                 stat=-1;
      56             :         }
      57             :         snprintf(buf, bufsiz, "%s", msg);
      58           0 :         return stat;
      59             : }
      60             : 
      61             : #ifdef HAVE_WIN32
      62             : static void format_win32_message(struct berrno *b)
      63             : {
      64             :         LPVOID msg;
      65             :         FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
      66             :                 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
      67             :                 NULL,
      68             :                 GetLastError(),
      69             :                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      70             :                 (LPTSTR)&msg,
      71             :                 0,
      72             :                 NULL);
      73             :         snprintf(b->m_buf, sizeof(b->m_buf), "%s", (const char *)msg);
      74             :         LocalFree(msg);
      75             : }
      76             : #endif
      77             : 
      78           0 : const char *berrno_bstrerror(struct berrno *b, int errnum)
      79             : {
      80           0 :         b->m_berrno=errnum;
      81             : 
      82           0 :         *(b->m_buf)=0;
      83             : #ifdef HAVE_WIN32
      84             :         if(b->m_berrno & b_errno_win32)
      85             :         {
      86             :                 format_win32_message(b);
      87             :                 return (const char *)(b->m_buf);
      88             :         }
      89             : #endif
      90             :         // Normal errno.
      91           0 :         if(bstrerror(b->m_berrno, b->m_buf, sizeof(b->m_buf))<0)
      92             :                 return "Invalid errno. No error message possible.";
      93             : 
      94           0 :         return b->m_buf;
      95             : }

Generated by: LCOV version 1.10