diff options
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/herror_msg.c | 50 | ||||
| -rw-r--r-- | libbb/herror_msg_and_die.c | 51 | ||||
| -rw-r--r-- | libbb/libbb.h | 7 | ||||
| -rw-r--r-- | libbb/vherror_msg.c | 45 | ||||
| -rw-r--r-- | libbb/xgethostbyname.c | 35 |
5 files changed, 188 insertions, 0 deletions
diff --git a/libbb/herror_msg.c b/libbb/herror_msg.c new file mode 100644 index 000000000..f4210edad --- /dev/null +++ b/libbb/herror_msg.c | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) tons of folks. Tracking down who wrote what | ||
| 6 | * isn't something I'm going to worry about... If you wrote something | ||
| 7 | * here, please feel free to acknowledge your work. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | * (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License | ||
| 20 | * along with this program; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | * | ||
| 23 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell | ||
| 24 | * Permission has been granted to redistribute this code under the GPL. | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <stdarg.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | |||
| 31 | #include "libbb.h" | ||
| 32 | |||
| 33 | extern void herror_msg(const char *s, ...) | ||
| 34 | { | ||
| 35 | va_list p; | ||
| 36 | |||
| 37 | va_start(p, s); | ||
| 38 | vherror_msg(s, p); | ||
| 39 | va_end(p); | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | /* END CODE */ | ||
| 44 | /* | ||
| 45 | Local Variables: | ||
| 46 | c-file-style: "linux" | ||
| 47 | c-basic-offset: 4 | ||
| 48 | tab-width: 4 | ||
| 49 | End: | ||
| 50 | */ | ||
diff --git a/libbb/herror_msg_and_die.c b/libbb/herror_msg_and_die.c new file mode 100644 index 000000000..0df5ed016 --- /dev/null +++ b/libbb/herror_msg_and_die.c | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) tons of folks. Tracking down who wrote what | ||
| 6 | * isn't something I'm going to worry about... If you wrote something | ||
| 7 | * here, please feel free to acknowledge your work. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | * (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License | ||
| 20 | * along with this program; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | * | ||
| 23 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell | ||
| 24 | * Permission has been granted to redistribute this code under the GPL. | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <stdarg.h> | ||
| 29 | #include <stdlib.h> | ||
| 30 | |||
| 31 | #include "libbb.h" | ||
| 32 | |||
| 33 | extern void herror_msg_and_die(const char *s, ...) | ||
| 34 | { | ||
| 35 | va_list p; | ||
| 36 | |||
| 37 | va_start(p, s); | ||
| 38 | vherror_msg(s, p); | ||
| 39 | va_end(p); | ||
| 40 | exit(EXIT_FAILURE); | ||
| 41 | } | ||
| 42 | |||
| 43 | |||
| 44 | /* END CODE */ | ||
| 45 | /* | ||
| 46 | Local Variables: | ||
| 47 | c-file-style: "linux" | ||
| 48 | c-basic-offset: 4 | ||
| 49 | tab-width: 4 | ||
| 50 | End: | ||
| 51 | */ | ||
diff --git a/libbb/libbb.h b/libbb/libbb.h index 7ab06388a..29a756b7f 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
| @@ -29,6 +29,8 @@ | |||
| 29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
| 30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
| 31 | 31 | ||
| 32 | #include <netdb.h> | ||
| 33 | |||
| 32 | #ifdef DMALLOC | 34 | #ifdef DMALLOC |
| 33 | #include "dmalloc.h" | 35 | #include "dmalloc.h" |
| 34 | #endif | 36 | #endif |
| @@ -77,6 +79,9 @@ extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)) | |||
| 77 | extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | 79 | extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
| 78 | extern void perror_msg(const char *s, ...); | 80 | extern void perror_msg(const char *s, ...); |
| 79 | extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); | 81 | extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); |
| 82 | extern void vherror_msg(const char *s, va_list p); | ||
| 83 | extern void herror_msg(const char *s, ...); | ||
| 84 | extern void herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); | ||
| 80 | 85 | ||
| 81 | /* These two are used internally -- you shouldn't need to use them */ | 86 | /* These two are used internally -- you shouldn't need to use them */ |
| 82 | extern void verror_msg(const char *s, va_list p); | 87 | extern void verror_msg(const char *s, va_list p); |
| @@ -252,6 +257,8 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file); | |||
| 252 | extern void gz_close(int gunzip_pid); | 257 | extern void gz_close(int gunzip_pid); |
| 253 | extern int gz_open(FILE *compressed_file, int *pid); | 258 | extern int gz_open(FILE *compressed_file, int *pid); |
| 254 | 259 | ||
| 260 | extern struct hostent *xgethostbyname(const char *name); | ||
| 261 | |||
| 255 | #define CT_AUTO 0 | 262 | #define CT_AUTO 0 |
| 256 | #define CT_UNIX2DOS 1 | 263 | #define CT_UNIX2DOS 1 |
| 257 | #define CT_DOS2UNIX 2 | 264 | #define CT_DOS2UNIX 2 |
diff --git a/libbb/vherror_msg.c b/libbb/vherror_msg.c new file mode 100644 index 000000000..9a06f3a38 --- /dev/null +++ b/libbb/vherror_msg.c | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) tons of folks. Tracking down who wrote what | ||
| 6 | * isn't something I'm going to worry about... If you wrote something | ||
| 7 | * here, please feel free to acknowledge your work. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | * (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 17 | * General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License | ||
| 20 | * along with this program; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | * | ||
| 23 | * Based in part on code from sash, Copyright (c) 1999 by David I. Bell | ||
| 24 | * Permission has been granted to redistribute this code under the GPL. | ||
| 25 | * | ||
| 26 | */ | ||
| 27 | |||
| 28 | #include <stdarg.h> | ||
| 29 | #include <netdb.h> | ||
| 30 | extern int h_errno; | ||
| 31 | |||
| 32 | #include <stdio.h> | ||
| 33 | |||
| 34 | #include "libbb.h" | ||
| 35 | |||
| 36 | extern void vherror_msg(const char *s, va_list p) | ||
| 37 | { | ||
| 38 | int err = h_errno; | ||
| 39 | if(s == 0) | ||
| 40 | s = ""; | ||
| 41 | verror_msg(s, p); | ||
| 42 | if (*s) | ||
| 43 | s = ": "; | ||
| 44 | fprintf(stderr, "%s%s\n", s, hstrerror(err)); | ||
| 45 | } | ||
diff --git a/libbb/xgethostbyname.c b/libbb/xgethostbyname.c new file mode 100644 index 000000000..c722951cf --- /dev/null +++ b/libbb/xgethostbyname.c | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Mini xgethostbyname implementation. | ||
| 4 | * | ||
| 5 | * | ||
| 6 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (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 License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | |||
| 24 | #include <netdb.h> | ||
| 25 | extern int h_errno; | ||
| 26 | |||
| 27 | struct hostent *xgethostbyname(const char *name) | ||
| 28 | { | ||
| 29 | struct hostent *retval; | ||
| 30 | |||
| 31 | if ((retval = gethostbyname(name)) == NULL) | ||
| 32 | herror_msg_and_die("%s", name); | ||
| 33 | |||
| 34 | return retval; | ||
| 35 | } | ||
