aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-03-19 19:24:06 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-03-19 19:24:06 +0000
commit1c1085caec1e039147e737dd6fbdd0de1f77cf31 (patch)
tree26a1f1080be5f9f44c72b45b72aae743d74685dd
parent55ff27793a2a50a13b7aed21deab3b97d7efb142 (diff)
downloadbusybox-w32-1c1085caec1e039147e737dd6fbdd0de1f77cf31.tar.gz
busybox-w32-1c1085caec1e039147e737dd6fbdd0de1f77cf31.tar.bz2
busybox-w32-1c1085caec1e039147e737dd6fbdd0de1f77cf31.zip
Split error messages into separate files.
Update libbb.h, per suggestion from Vladimir, to include __attribute__((format (printf ...))) stuff -Erik git-svn-id: svn://busybox.net/trunk/busybox@2145 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--Makefile5
-rw-r--r--include/libbb.h8
-rw-r--r--libbb/Makefile11
-rw-r--r--libbb/error_msg.c48
-rw-r--r--libbb/error_msg_and_die.c53
-rw-r--r--libbb/libbb.h8
-rw-r--r--libbb/perror_msg.c51
-rw-r--r--libbb/perror_msg_and_die.c52
-rw-r--r--libbb/verror_msg.c51
-rw-r--r--libbb/vperror_msg.c51
10 files changed, 285 insertions, 53 deletions
diff --git a/Makefile b/Makefile
index 1cd9c864c..de7320fb0 100644
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,8 @@ OPTIMIZATION := $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>
110 110
111WARNINGS = -Wall 111WARNINGS = -Wall
112 112
113ARFLAGS = -r
114
113# 115#
114#-------------------------------------------------------- 116#--------------------------------------------------------
115# If you're going to do a lot of builds with a non-vanilla configuration, 117# If you're going to do a lot of builds with a non-vanilla configuration,
@@ -233,7 +235,8 @@ mode_string.c parse_mode.c parse_number.c print_file.c process_escape_sequence.c
233my_getgrgid.c my_getpwnamegid.c my_getpwuid.c my_getgrnam.c my_getpwnam.c \ 235my_getgrgid.c my_getpwnamegid.c my_getpwuid.c my_getgrnam.c my_getpwnam.c \
234recursive_action.c safe_read.c safe_strncpy.c syscalls.c \ 236recursive_action.c safe_read.c safe_strncpy.c syscalls.c \
235syslog_msg_with_name.c time_string.c trim.c vdprintf.c wfopen.c xfuncs.c \ 237syslog_msg_with_name.c time_string.c trim.c vdprintf.c wfopen.c xfuncs.c \
236xregcomp.c 238xregcomp.c error_msg_and_die.c perror_msg.c perror_msg_and_die.c \
239verror_msg.c vperror_msg.c
237LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC)) 240LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
238LIBBB_CFLAGS = -I$(LIBBB_DIR) 241LIBBB_CFLAGS = -I$(LIBBB_DIR)
239 242
diff --git a/include/libbb.h b/include/libbb.h
index a85987d9e..4c23b2b80 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -68,11 +68,15 @@ static inline int is_octal(ch) { return ((ch >= '0') && (ch <= '7')); }
68 68
69 69
70extern void show_usage(void) __attribute__ ((noreturn)); 70extern void show_usage(void) __attribute__ ((noreturn));
71extern void error_msg(const char *s, ...); 71extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
72extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 72extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
73extern void perror_msg(const char *s, ...); 73extern void perror_msg(const char *s, ...);
74extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 74extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
75 75
76/* These two are used internally -- you shouldn't need to use them */
77extern void verror_msg(const char *s, va_list p);
78extern void vperror_msg(const char *s, va_list p);
79
76const char *mode_string(int mode); 80const char *mode_string(int mode);
77const char *time_string(time_t timeVal); 81const char *time_string(time_t timeVal);
78int is_directory(const char *name, const int followLinks, struct stat *statBuf); 82int is_directory(const char *name, const int followLinks, struct stat *statBuf);
diff --git a/libbb/Makefile b/libbb/Makefile
new file mode 100644
index 000000000..a9ea76947
--- /dev/null
+++ b/libbb/Makefile
@@ -0,0 +1,11 @@
1# Silly wrapper makefile. This Makefile is _not_ used by the build system for
2# busybox, it is just to make working on libbb more conveinient.
3# -Erik Andersen
4
5all:
6 make -C .. libbb.a
7
8clean:
9 - rm -rf libbb.a
10 - find -name \*.o -exec rm -f {} \;
11
diff --git a/libbb/error_msg.c b/libbb/error_msg.c
index 7773d32a2..c7d5fdb98 100644
--- a/libbb/error_msg.c
+++ b/libbb/error_msg.c
@@ -31,15 +31,6 @@
31#include <stdlib.h> 31#include <stdlib.h>
32#include "libbb.h" 32#include "libbb.h"
33 33
34extern const char *applet_name;
35
36static void verror_msg(const char *s, va_list p)
37{
38 fflush(stdout);
39 fprintf(stderr, "%s: ", applet_name);
40 vfprintf(stderr, s, p);
41}
42
43extern void error_msg(const char *s, ...) 34extern void error_msg(const char *s, ...)
44{ 35{
45 va_list p; 36 va_list p;
@@ -50,45 +41,6 @@ extern void error_msg(const char *s, ...)
50 putc('\n', stderr); 41 putc('\n', stderr);
51} 42}
52 43
53extern void error_msg_and_die(const char *s, ...)
54{
55 va_list p;
56
57 va_start(p, s);
58 verror_msg(s, p);
59 va_end(p);
60 putc('\n', stderr);
61 exit(EXIT_FAILURE);
62}
63
64static void vperror_msg(const char *s, va_list p)
65{
66 int err=errno;
67 if(s == 0) s = "";
68 verror_msg(s, p);
69 if (*s) s = ": ";
70 fprintf(stderr, "%s%s\n", s, strerror(err));
71}
72
73extern void perror_msg(const char *s, ...)
74{
75 va_list p;
76
77 va_start(p, s);
78 vperror_msg(s, p);
79 va_end(p);
80}
81
82extern void perror_msg_and_die(const char *s, ...)
83{
84 va_list p;
85
86 va_start(p, s);
87 vperror_msg(s, p);
88 va_end(p);
89 exit(EXIT_FAILURE);
90}
91
92 44
93/* END CODE */ 45/* END CODE */
94/* 46/*
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
new file mode 100644
index 000000000..b950ee00c
--- /dev/null
+++ b/libbb/error_msg_and_die.c
@@ -0,0 +1,53 @@
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 <stdio.h>
29#include <errno.h>
30#include <string.h>
31#include <stdlib.h>
32#include "libbb.h"
33
34extern void error_msg_and_die(const char *s, ...)
35{
36 va_list p;
37
38 va_start(p, s);
39 verror_msg(s, p);
40 va_end(p);
41 putc('\n', stderr);
42 exit(EXIT_FAILURE);
43}
44
45
46/* END CODE */
47/*
48Local Variables:
49c-file-style: "linux"
50c-basic-offset: 4
51tab-width: 4
52End:
53*/
diff --git a/libbb/libbb.h b/libbb/libbb.h
index a85987d9e..4c23b2b80 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -68,11 +68,15 @@ static inline int is_octal(ch) { return ((ch >= '0') && (ch <= '7')); }
68 68
69 69
70extern void show_usage(void) __attribute__ ((noreturn)); 70extern void show_usage(void) __attribute__ ((noreturn));
71extern void error_msg(const char *s, ...); 71extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
72extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 72extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
73extern void perror_msg(const char *s, ...); 73extern void perror_msg(const char *s, ...);
74extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); 74extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
75 75
76/* These two are used internally -- you shouldn't need to use them */
77extern void verror_msg(const char *s, va_list p);
78extern void vperror_msg(const char *s, va_list p);
79
76const char *mode_string(int mode); 80const char *mode_string(int mode);
77const char *time_string(time_t timeVal); 81const char *time_string(time_t timeVal);
78int is_directory(const char *name, const int followLinks, struct stat *statBuf); 82int is_directory(const char *name, const int followLinks, struct stat *statBuf);
diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c
new file mode 100644
index 000000000..18c71ab1c
--- /dev/null
+++ b/libbb/perror_msg.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 <stdio.h>
29#include <errno.h>
30#include <string.h>
31#include <stdlib.h>
32#include "libbb.h"
33
34extern void perror_msg(const char *s, ...)
35{
36 va_list p;
37
38 va_start(p, s);
39 vperror_msg(s, p);
40 va_end(p);
41}
42
43
44/* END CODE */
45/*
46Local Variables:
47c-file-style: "linux"
48c-basic-offset: 4
49tab-width: 4
50End:
51*/
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
new file mode 100644
index 000000000..9d304a26b
--- /dev/null
+++ b/libbb/perror_msg_and_die.c
@@ -0,0 +1,52 @@
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 <stdio.h>
29#include <errno.h>
30#include <string.h>
31#include <stdlib.h>
32#include "libbb.h"
33
34extern void perror_msg_and_die(const char *s, ...)
35{
36 va_list p;
37
38 va_start(p, s);
39 vperror_msg(s, p);
40 va_end(p);
41 exit(EXIT_FAILURE);
42}
43
44
45/* END CODE */
46/*
47Local Variables:
48c-file-style: "linux"
49c-basic-offset: 4
50tab-width: 4
51End:
52*/
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
new file mode 100644
index 000000000..b5278cfb7
--- /dev/null
+++ b/libbb/verror_msg.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 <stdio.h>
29#include <errno.h>
30#include <string.h>
31#include <stdlib.h>
32#include "libbb.h"
33
34extern const char *applet_name;
35
36extern void verror_msg(const char *s, va_list p)
37{
38 fflush(stdout);
39 fprintf(stderr, "%s: ", applet_name);
40 vfprintf(stderr, s, p);
41}
42
43
44/* END CODE */
45/*
46Local Variables:
47c-file-style: "linux"
48c-basic-offset: 4
49tab-width: 4
50End:
51*/
diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c
new file mode 100644
index 000000000..ca9361e45
--- /dev/null
+++ b/libbb/vperror_msg.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 <stdio.h>
29#include <errno.h>
30#include <string.h>
31#include <stdlib.h>
32#include "libbb.h"
33
34extern void vperror_msg(const char *s, va_list p)
35{
36 int err=errno;
37 if(s == 0) s = "";
38 verror_msg(s, p);
39 if (*s) s = ": ";
40 fprintf(stderr, "%s%s\n", s, strerror(err));
41}
42
43
44/* END CODE */
45/*
46Local Variables:
47c-file-style: "linux"
48c-basic-offset: 4
49tab-width: 4
50End:
51*/