summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 1cd9c86..de7320f 100644
--- 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)
diff --git a/include/libbb.h b/include/libbb.h
index a85987d..4c23b2b 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -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
index 0000000..a9ea769
--- /dev/null
+++ b/libbb/Makefile
@@ -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 {} \;
+
diff --git a/libbb/error_msg.c b/libbb/error_msg.c
index 7773d32..c7d5fdb 100644
--- a/libbb/error_msg.c
+++ b/libbb/error_msg.c
@@ -31,15 +31,6 @@
#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
index 0000000..b950ee0
--- /dev/null
+++ b/libbb/error_msg_and_die.c
@@ -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:
+*/
diff --git a/libbb/libbb.h b/libbb/libbb.h
index a85987d..4c23b2b 100644
--- a/libbb/libbb.h
+++ b/libbb/libbb.h
@@ -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
index 0000000..18c71ab
--- /dev/null
+++ b/libbb/perror_msg.c
@@ -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
index 0000000..9d304a2
--- /dev/null
+++ b/libbb/perror_msg_and_die.c
@@ -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
index 0000000..b5278cf
--- /dev/null
+++ b/libbb/verror_msg.c
@@ -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
index 0000000..ca9361e
--- /dev/null
+++ b/libbb/vperror_msg.c
@@ -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:
+*/