Split error messages into separate files.
authorEric Andersen <andersen@codepoet.org>
Mon, 19 Mar 2001 19:24:06 +0000 (19:24 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 19 Mar 2001 19:24:06 +0000 (19:24 -0000)
Update libbb.h, per suggestion from Vladimir, to include __attribute__((format
(printf ...))) stuff
 -Erik

Makefile
include/libbb.h
libbb/Makefile [new file with mode: 0644]
libbb/error_msg.c
libbb/error_msg_and_die.c [new file with mode: 0644]
libbb/libbb.h
libbb/perror_msg.c [new file with mode: 0644]
libbb/perror_msg_and_die.c [new file with mode: 0644]
libbb/verror_msg.c [new file with mode: 0644]
libbb/vperror_msg.c [new file with mode: 0644]

index 1cd9c864c23f5194e9c0d273c8306caacdf9e007..de7320fb0d5142dcdfe83aed5bb8999eacdba309 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -110,6 +110,8 @@ OPTIMIZATION := $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>
 
 WARNINGS = -Wall
 
+ARFLAGS = -r
+
 #
 #--------------------------------------------------------
 # 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
 my_getgrgid.c my_getpwnamegid.c my_getpwuid.c my_getgrnam.c my_getpwnam.c \
 recursive_action.c safe_read.c safe_strncpy.c syscalls.c \
 syslog_msg_with_name.c time_string.c trim.c vdprintf.c wfopen.c xfuncs.c \
-xregcomp.c 
+xregcomp.c error_msg_and_die.c perror_msg.c perror_msg_and_die.c \
+verror_msg.c vperror_msg.c 
 LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
 LIBBB_CFLAGS = -I$(LIBBB_DIR)
 
index a85987d9e30571b48cab03caa4b73af2997b4aad..4c23b2b80178f4860d99dffc8ae509cfd0f8703a 100644 (file)
@@ -68,11 +68,15 @@ static inline int is_octal(ch)   { return ((ch >= '0') && (ch <= '7')); }
 
 
 extern void show_usage(void) __attribute__ ((noreturn));
-extern void error_msg(const char *s, ...);
-extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
+extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
 extern void perror_msg(const char *s, ...);
 extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
 
+/* These two are used internally -- you shouldn't need to use them */
+extern void verror_msg(const char *s, va_list p);
+extern void vperror_msg(const char *s, va_list p);
+
 const char *mode_string(int mode);
 const char *time_string(time_t timeVal);
 int is_directory(const char *name, const int followLinks, struct stat *statBuf);
diff --git a/libbb/Makefile b/libbb/Makefile
new file mode 100644 (file)
index 0000000..a9ea769
--- /dev/null
@@ -0,0 +1,11 @@
+# Silly wrapper makefile.  This Makefile is _not_ used by the build system for
+# busybox, it is just to make working on libbb more conveinient.
+#  -Erik Andersen
+
+all:
+       make -C .. libbb.a
+
+clean:
+       - rm -rf libbb.a
+       - find -name \*.o -exec rm -f {} \;
+
index 7773d32a24ffb0163888e564db83b3366d2e91af..c7d5fdb98582a2982bd7c439d161475782132539 100644 (file)
 #include <stdlib.h>
 #include "libbb.h"
 
-extern const char *applet_name;
-
-static void verror_msg(const char *s, va_list p)
-{
-       fflush(stdout);
-       fprintf(stderr, "%s: ", applet_name);
-       vfprintf(stderr, s, p);
-}
-
 extern void error_msg(const char *s, ...)
 {
        va_list p;
@@ -50,45 +41,6 @@ extern void error_msg(const char *s, ...)
        putc('\n', stderr);
 }
 
-extern void error_msg_and_die(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       verror_msg(s, p);
-       va_end(p);
-       putc('\n', stderr);
-       exit(EXIT_FAILURE);
-}
-
-static void vperror_msg(const char *s, va_list p)
-{
-       int err=errno;
-       if(s == 0) s = "";
-       verror_msg(s, p);
-       if (*s) s = ": ";
-       fprintf(stderr, "%s%s\n", s, strerror(err));
-}
-
-extern void perror_msg(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       vperror_msg(s, p);
-       va_end(p);
-}
-
-extern void perror_msg_and_die(const char *s, ...)
-{
-       va_list p;
-
-       va_start(p, s);
-       vperror_msg(s, p);
-       va_end(p);
-       exit(EXIT_FAILURE);
-}
-
 
 /* END CODE */
 /*
diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c
new file mode 100644 (file)
index 0000000..b950ee0
--- /dev/null
@@ -0,0 +1,53 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void error_msg_and_die(const char *s, ...)
+{
+       va_list p;
+
+       va_start(p, s);
+       verror_msg(s, p);
+       va_end(p);
+       putc('\n', stderr);
+       exit(EXIT_FAILURE);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
index a85987d9e30571b48cab03caa4b73af2997b4aad..4c23b2b80178f4860d99dffc8ae509cfd0f8703a 100644 (file)
@@ -68,11 +68,15 @@ static inline int is_octal(ch)   { return ((ch >= '0') && (ch <= '7')); }
 
 
 extern void show_usage(void) __attribute__ ((noreturn));
-extern void error_msg(const char *s, ...);
-extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
+extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
+extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
 extern void perror_msg(const char *s, ...);
 extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn));
 
+/* These two are used internally -- you shouldn't need to use them */
+extern void verror_msg(const char *s, va_list p);
+extern void vperror_msg(const char *s, va_list p);
+
 const char *mode_string(int mode);
 const char *time_string(time_t timeVal);
 int 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 (file)
index 0000000..18c71ab
--- /dev/null
@@ -0,0 +1,51 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void perror_msg(const char *s, ...)
+{
+       va_list p;
+
+       va_start(p, s);
+       vperror_msg(s, p);
+       va_end(p);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c
new file mode 100644 (file)
index 0000000..9d304a2
--- /dev/null
@@ -0,0 +1,52 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void perror_msg_and_die(const char *s, ...)
+{
+       va_list p;
+
+       va_start(p, s);
+       vperror_msg(s, p);
+       va_end(p);
+       exit(EXIT_FAILURE);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
new file mode 100644 (file)
index 0000000..b5278cf
--- /dev/null
@@ -0,0 +1,51 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern const char *applet_name;
+
+extern void verror_msg(const char *s, va_list p)
+{
+       fflush(stdout);
+       fprintf(stderr, "%s: ", applet_name);
+       vfprintf(stderr, s, p);
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c
new file mode 100644 (file)
index 0000000..ca9361e
--- /dev/null
@@ -0,0 +1,51 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Based in part on code from sash, Copyright (c) 1999 by David I. Bell 
+ * Permission has been granted to redistribute this code under the GPL.
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include "libbb.h"
+
+extern void vperror_msg(const char *s, va_list p)
+{
+       int err=errno;
+       if(s == 0) s = "";
+       verror_msg(s, p);
+       if (*s) s = ": ";
+       fprintf(stderr, "%s%s\n", s, strerror(err));
+}
+
+
+/* END CODE */
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/