4 * berrno is a simplistic errno handler that works for
5 * Unix, Win32, and Bacula bpipes.
7 * See berrno.h for how to use berrno.
9 * Kern Sibbald, July MMIV
15 Copyright (C) 2004 Kern Sibbald and John Walker
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation; either version 2 of
20 the License, or (at your option) any later version.
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 General Public License for more details.
27 You should have received a copy of the GNU General Public
28 License along with this program; if not, write to the Free
29 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
37 extern const char *get_signal_name(int sig);
38 extern int num_execvp_errors;
39 extern int execvp_errors[];
42 const char *berrno::strerror()
48 if (berrno_ && b_errno_win32) {
49 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
50 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
53 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
58 pm_strcpy(&buf_, (const char *)msg);
60 return (const char *)buf_;
63 if (berrno_ & b_errno_exit) {
64 stat = (berrno_ & ~b_errno_exit); /* remove bit */
66 return "Child exited normally."; /* this really shouldn't happen */
68 /* Maybe an execvp failure */
70 if (stat < 200 + num_execvp_errors) {
71 berrno_ = execvp_errors[stat - 200];
73 return "Unknown error during program execvp";
76 Mmsg(&buf_, "Child exited with code %d", stat);
79 /* If we drop out here, berrno_ is set to an execvp errno */
82 if (berrno_ & b_errno_signal) {
83 stat = (berrno_ & ~b_errno_signal); /* remove bit */
84 Mmsg(&buf_, "Child died from signal %d: %s", stat, get_signal_name(stat));
89 if (bstrerror(berrno_, buf_, 1024) < 0) {
90 return "Invalid errno. No error message possible.";