aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c42
-rw-r--r--lib/lib.h6
-rw-r--r--lib/portability.h4
-rw-r--r--lib/xwrap.c4
4 files changed, 40 insertions, 16 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);
diff --git a/lib/lib.h b/lib/lib.h
index 235b208f..d56cdbe3 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -152,8 +152,12 @@ void verror_msg(char *msg, int err, va_list va);
void error_msg(char *msg, ...) printf_format;
void perror_msg(char *msg, ...) printf_format;
void error_exit(char *msg, ...) printf_format noreturn;
-void help_exit(char *msg, ...) printf_format noreturn;
void perror_exit(char *msg, ...) printf_format noreturn;
+void help_exit(char *msg, ...) printf_format noreturn;
+void error_msg_raw(char *msg);
+void perror_msg_raw(char *msg);
+void error_exit_raw(char *msg);
+void perror_exit_raw(char *msg);
ssize_t readall(int fd, void *buf, size_t len);
ssize_t writeall(int fd, void *buf, size_t len);
off_t lskip(int fd, off_t offset);
diff --git a/lib/portability.h b/lib/portability.h
index f2f98069..eadd9961 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -11,12 +11,8 @@
#ifdef __GNUC__
#define noreturn __attribute__((noreturn))
-#if CFG_TOYBOX_DEBUG
#define printf_format __attribute__((format(printf, 1, 2)))
#else
-#define printf_format
-#endif
-#else
#define noreturn
#define printf_format
#endif
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 6d0c5113..09f9197d 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -214,7 +214,7 @@ pid_t xpopen_both(char **argv, int *pipes)
// setting high bit of argv[0][0] to let new process know
**toys.argv |= 0x80;
execv(s, toys.argv);
- perror_msg(s);
+ perror_msg_raw(s);
_exit(127);
}
@@ -291,7 +291,7 @@ void xunlink(char *path)
int xcreate(char *path, int flags, int mode)
{
int fd = open(path, flags^O_CLOEXEC, mode);
- if (fd == -1) perror_exit("%s", path);
+ if (fd == -1) perror_exit_raw(path);
return fd;
}