aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-01-05 22:26:58 -0600
committerRob Landley <rob@landley.net>2016-01-05 22:26:58 -0600
commitd3a435e53c94ec25b4ae5fa2614f49ef8884e08a (patch)
tree12e38a4739bd1832040b7d7e3efd2e054351fbf0 /lib/lib.c
parent8dfbf2efc89154fd74b34b5f4d8bf774dba63abf (diff)
downloadtoybox-d3a435e53c94ec25b4ae5fa2614f49ef8884e08a.tar.gz
Add error_msg_raw() and friends, replace error_msg("%s", s) uses, enable format
checking, and fix up format checking complaints. Added out(type, value) function to stat to avoid a zillion printf typecasts.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/lib/lib.c b/lib/lib.c
index c89aeb60..8d12b983 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -49,6 +49,18 @@ void error_exit(char *msg, ...)
xexit();
}
+// Die with an error message and strerror(errno)
+void perror_exit(char *msg, ...)
+{
+ va_list va;
+
+ va_start(va, msg);
+ verror_msg(msg, errno, va);
+ va_end(va);
+
+ xexit();
+}
+
// Exit with an error message after showing help text.
void help_exit(char *msg, ...)
{
@@ -65,16 +77,28 @@ void help_exit(char *msg, ...)
xexit();
}
-// Die with an error message and strerror(errno)
-void perror_exit(char *msg, ...)
+// If you want to explicitly disable the printf() behavior (because you're
+// printing user-supplied data, or because android's static checker produces
+// false positives for 'char *s = x ? "blah1" : "blah2"; printf(s);' and it's
+// -Werror there for policy reasons).
+void error_msg_raw(char *msg)
{
- va_list va;
+ error_msg("%s", msg);
+}
- va_start(va, msg);
- verror_msg(msg, errno, va);
- va_end(va);
+void perror_msg_raw(char *msg)
+{
+ perror_msg("%s", msg);
+}
- xexit();
+void error_exit_raw(char *msg)
+{
+ error_exit("%s", msg);
+}
+
+void perror_exit_raw(char *msg)
+{
+ error_exit("%s", msg);
}
// Keep reading until full or EOF
@@ -260,7 +284,7 @@ long xstrtol(char *str, char **end, int base)
{
long l = estrtol(str, end, base);
- if (errno) perror_exit("%s", str);
+ if (errno) perror_exit_raw(str);
return l;
}
@@ -525,7 +549,7 @@ void loopfiles_rw(char **argv, int flags, int permissions, int failok,
if (!strcmp(*argv, "-")) fd=0;
else if (0>(fd = open(*argv, flags, permissions)) && !failok)
- perror_msg("%s", *argv);
+ perror_msg_raw(*argv);
else {
function(fd, *argv);
if (flags & O_CLOEXEC) close(fd);