Be more verbose about errors and warnings location

Print function name and line,
and also print a W: or E: in front of the warn/errors
This commit is contained in:
Julien Danjou 2008-03-09 17:10:23 +01:00
parent 33560c393d
commit 8c901c8b1e
2 changed files with 18 additions and 11 deletions

View file

@ -28,30 +28,28 @@
#include "util.h"
/** Print error and exit
* with EXIT_FAILURE code
/** Print error and exit with EXIT_FAILURE code
*/
void
eprint(const char *fmt, ...)
_eprint(int line, const char *fct, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "awesome: ");
fprintf(stderr, "E: awesome: %s:%d: ", fct, line);
vfprintf(stderr, fmt, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
/** Print error message
* on stderr
/** Print error message on stderr
*/
void
warn(const char *fmt, ...)
_warn(int line, const char *fct, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "awesome: ");
fprintf(stderr, "W: awesome: %s:%d: ", fct, line);
vfprintf(stderr, fmt, ap);
va_end(ap);
}

View file

@ -216,10 +216,19 @@ a_strncat(char *dst, ssize_t n, const char *src, ssize_t l)
return dlen + a_strncpy(dst + dlen, n - dlen, src, l);
}
void die(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2)));
void eprint(const char *, ...) __attribute__ ((noreturn)) __attribute__ ((format(printf, 1, 2)));
#define eprint(string, ...) _eprint(__LINE__, \
__FUNCTION__, \
string, ## __VA_ARGS__)
void _eprint(int, const char *, const char *, ...)
__attribute__ ((noreturn)) __attribute__ ((format(printf, 3, 4)));
#define warn(string, ...) _warn(__LINE__, \
__FUNCTION__, \
string, ## __VA_ARGS__)
void _warn(int, const char *, const char *, ...)
__attribute__ ((format(printf, 3, 4)));
double compute_new_value_from_arg(const char *, double);
void warn(const char *, ...) __attribute__ ((format(printf, 1, 2)));
void *name_func_lookup(const char *, const name_func_link_t *);
#endif