new ARGBEGIN & usage() function

This commit is contained in:
Connor Lane Smith
2012-05-14 21:28:41 +01:00
parent f1259218f2
commit 146cca114e
11 changed files with 118 additions and 140 deletions

View File

@@ -1,15 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include "../util.h"
extern void venprintf(int, const char *, va_list);
void
enprintf(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
venprintf(status, fmt, ap);
va_end(ap);
}

View File

@@ -1,9 +1,13 @@
/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../util.h"
extern void venprintf(int, const char *, va_list);
char *argv0;
static void venprintf(int, const char *, va_list);
void
eprintf(const char *fmt, ...)
@@ -14,3 +18,34 @@ eprintf(const char *fmt, ...)
venprintf(EXIT_FAILURE, fmt, ap);
va_end(ap);
}
void
enprintf(int status, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
venprintf(status, fmt, ap);
va_end(ap);
}
void
usage(const char *s)
{
fprintf(stderr, "usage: %s %s\n", argv0, s);
exit(EXIT_FAILURE);
}
void
venprintf(int status, const char *fmt, va_list ap)
{
/*fprintf(stderr, "%s: ", argv0);*/
vfprintf(stderr, fmt, ap);
if(fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr);
perror(NULL);
}
exit(status);
}

View File

@@ -1,18 +0,0 @@
/* See LICENSE file for copyright and license details. */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../util.h"
void
venprintf(int status, const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
if(fmt[0] && fmt[strlen(fmt)-1] == ':') {
fputc(' ', stderr);
perror(NULL);
}
exit(status);
}