From: Michael Forney Date: Tue, 1 Oct 2013 05:44:46 +0000 (+0000) Subject: Also emulate error_at_line if not present X-Git-Tag: v3.3.10~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=007c438148aec7c59b8285c56c9ebc5132294006;p=procps-ng Also emulate error_at_line if not present --- diff --git a/include/c.h b/include/c.h index 6bcdf5f5..aca88a72 100644 --- a/include/c.h +++ b/include/c.h @@ -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__) diff --git a/ps/display.c b/ps/display.c index a659cbf3..a2adcc8f 100644 --- a/ps/display.c +++ b/ps/display.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -38,6 +37,7 @@ #include "../proc/wchan.h" #include "../include/fileutils.h" +#include "../include/c.h" #include "common.h" #ifndef SIGCHLD diff --git a/ps/global.c b/ps/global.c index b75f7284..5a4f1e57 100644 --- a/ps/global.c +++ b/ps/global.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -36,6 +35,7 @@ #include "../proc/version.h" #include "../proc/sysinfo.h" +#include "../include/c.h" #include "common.h" #ifndef __GNU_LIBRARY__