Also emulate error_at_line if not present

This commit is contained in:
Michael Forney 2013-10-01 05:44:46 +00:00 committed by Jaromir Capik
parent d6a3a3d97e
commit 007c438148
3 changed files with 20 additions and 2 deletions

View File

@ -123,6 +123,24 @@ static void error(int status, int errnum, const char *format, ...)
if (status != 0)
exit(status);
}
/* Emulate the error_at_line() function from glibc */
__attribute__((__format__(__printf__, 5, 6)))
static void error_at_line(int status, int errnum, const char *filename,
unsigned int linenum, const char *format, ...)
{
va_list argp;
fprintf(stderr, "%s:%s:%u: ", program_invocation_short_name,
filename, linenum);
va_start(argp, format);
vfprintf(stderr, format, argp);
va_end(argp);
if (errnum != 0)
fprintf(stderr, ": error code %d", errnum);
fprintf(stderr, "\n");
if (status != 0)
exit(status);
}
#endif
#define xwarn(...) error(0, errno, __VA_ARGS__)
#define xwarnx(...) error(0, 0, __VA_ARGS__)

View File

@ -25,7 +25,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <error.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
@ -38,6 +37,7 @@
#include "../proc/wchan.h"
#include "../include/fileutils.h"
#include "../include/c.h"
#include "common.h"
#ifndef SIGCHLD

View File

@ -25,7 +25,6 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <error.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
@ -36,6 +35,7 @@
#include "../proc/version.h"
#include "../proc/sysinfo.h"
#include "../include/c.h"
#include "common.h"
#ifndef __GNU_LIBRARY__