summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2007-05-19 12:25:05 +0200
committerDavid Härdeman <david@hardeman.nu>2007-05-19 12:25:05 +0200
commit22fd68b59d5f792ff033120ad260581ac7fa72ee (patch)
treeda8efee0169c33d8ae532fd31e5a83862688fc52 /utils.c
parent3cb9d64b9b2ace1463f274c8554bffbfa4979e0d (diff)
Change all printf() calls to msg() calls and clean up output
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/utils.c b/utils.c
index 91cb1ed..dc053ea 100644
--- a/utils.c
+++ b/utils.c
@@ -19,7 +19,12 @@ msg(int level, const char *fmt, ...)
return 0;
va_start(ap, fmt);
- ret = vfprintf(stderr, fmt, ap);
+
+ if (level < MSG_QUIET)
+ ret = vfprintf(stderr, fmt, ap);
+ else
+ ret = vfprintf(stdout, fmt, ap);
+
va_end(ap);
return ret;
}
@@ -29,7 +34,7 @@ xmalloc(size_t size)
{
void *result = malloc(size);
if (!result) {
- fprintf(stderr, "Failed to malloc %zi bytes\n", size);
+ msg(MSG_CRITICAL, "Failed to malloc %zi bytes\n", size);
exit(EXIT_FAILURE);
}
return result;
@@ -40,7 +45,7 @@ xstrdup(const char *s)
{
char *result = strdup(s);
if (!result) {
- fprintf(stderr, "Failed to strdup %zi bytes\n", strlen(s));
+ msg(MSG_CRITICAL, "Failed to strdup %zi bytes\n", strlen(s));
exit(EXIT_FAILURE);
}
return result;
@@ -53,9 +58,9 @@ binary_print(const char *s, ssize_t len)
for (i = 0; i < len; i++) {
if (isprint(s[i]))
- printf("%c", s[i]);
+ msg(MSG_DEBUG, "%c", s[i]);
else
- printf("0x%02X", (int)s[i]);
+ msg(MSG_DEBUG, "0x%02X", (int)s[i]);
}
}
@@ -98,7 +103,7 @@ read_int(char **from, size_t len, const char *max)
int i;
if (*from + len > max) {
- fprintf(stderr, "Attempt to read beyond end of file, corrupt file?\n");
+ msg(MSG_CRITICAL, "Attempt to read beyond end of file, corrupt file?\n");
exit(EXIT_FAILURE);
}
@@ -114,7 +119,7 @@ read_binary_string(char **from, size_t len, const char *max)
char *result;
if (*from + len > max) {
- fprintf(stderr, "Attempt to read beyond end of file, corrupt file?\n");
+ msg(MSG_CRITICAL, "Attempt to read beyond end of file, corrupt file?\n");
exit(EXIT_FAILURE);
}