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-2006 Kern Sibbald
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 version 2 as amended with additional clauses defined in the
20 file LICENSE in the main source directory.
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
25 the file LICENSE for additional details.
32 extern const char *get_signal_name(int sig);
33 extern int num_execvp_errors;
34 extern int execvp_errors[];
37 const char *berrno::strerror()
40 if (berrno_ & b_errno_win32) {
41 return (const char *)buf_;
46 if (berrno_ & b_errno_exit) {
47 stat = (berrno_ & ~b_errno_exit); /* remove bit */
49 return _("Child exited normally."); /* this really shouldn't happen */
51 /* Maybe an execvp failure */
53 if (stat < 200 + num_execvp_errors) {
54 berrno_ = execvp_errors[stat - 200];
56 return _("Unknown error during program execvp");
59 Mmsg(buf_, _("Child exited with code %d"), stat);
62 /* If we drop out here, berrno_ is set to an execvp errno */
65 if (berrno_ & b_errno_signal) {
66 stat = (berrno_ & ~b_errno_signal); /* remove bit */
67 Mmsg(buf_, _("Child died from signal %d: %s"), stat, get_signal_name(stat));
72 if (bstrerror(berrno_, buf_, 1024) < 0) {
73 return _("Invalid errno. No error message possible.");
78 void berrno::format_win32_message()
82 if (berrno_ & b_errno_win32) {
83 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
84 FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
87 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
92 pm_strcpy(&buf_, (const char *)msg);