Clean up warnings regarding printf.

This commit is contained in:
Roy Marples 2008-10-08 15:56:47 +00:00
parent 5cdc489573
commit 8c8751fa60
4 changed files with 69 additions and 71 deletions

View File

@ -28,13 +28,11 @@
#define __EINFO_H__ #define __EINFO_H__
#if defined(__GNUC__) #if defined(__GNUC__)
# define __EINFO_PRINTF __attribute__ ((__format__ (__printf__, 1, 2))) # define EINFO_PRINTF(a, b) __attribute__((__format__(__printf__, a, b)))
# define __EINFO_XPRINTF __attribute__ ((__noreturn__, __format__ (__printf__, 1, 2))) # define EINFO_XPRINTF(a, b) __attribute__((__noreturn__,__format__(__printf__, a, b)))
# define __EEND_PRINTF __attribute__ ((__format__ (__printf__, 2, 3)))
#else #else
# define __EINFO_PRINTF # define EINFO_PRINTF(a, b)
# define __EINFO_XPRINTF # define EINFO_XPRINTF(a, b)
# define __EEND_PRINTF
#endif #endif
#include <sys/types.h> #include <sys/types.h>
@ -42,12 +40,12 @@
/* Although OpenRC requires C99, linking to us should not. */ /* Although OpenRC requires C99, linking to us should not. */
#ifdef restrict #ifdef restrict
# define __EINFO_RESTRICT restrict # define EINFO_RESTRICT restrict
#else #else
# ifdef __restrict # ifdef __restrict
# define __EINFO_RESTRICT __restrict # define EINFO_RESTRICT __restrict
# else # else
# define __EINFO_RESTRICT # define EINFO_RESTRICT
# endif # endif
#endif #endif
@ -68,7 +66,7 @@ typedef enum
const char *ecolor(ECOLOR); const char *ecolor(ECOLOR);
/*! @brief Writes to syslog. */ /*! @brief Writes to syslog. */
void elog(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; void elog(int, const char * EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
/*! /*!
* @brief Display informational messages. * @brief Display informational messages.
@ -86,22 +84,22 @@ void elog(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF;
* The v suffix means only print if EINFO_VERBOSE is yes. * The v suffix means only print if EINFO_VERBOSE is yes.
*/ */
/*@{*/ /*@{*/
int einfon(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int einfon(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ewarnn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ewarnn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int eerrorn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int eerrorn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int einfo(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int einfo(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ewarn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ewarn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
void ewarnx(const char * __EINFO_RESTRICT, ...) __EINFO_XPRINTF; void ewarnx(const char * __EINFO_RESTRICT, ...) EINFO_XPRINTF(1, 2);
int eerror(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int eerror(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
void eerrorx(const char * __EINFO_RESTRICT, ...) __EINFO_XPRINTF; void eerrorx(const char * __EINFO_RESTRICT, ...) EINFO_XPRINTF(1, 2);
int einfovn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int einfovn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ewarnvn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ewarnvn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ebeginvn(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ebeginvn(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int eendvn(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int eendvn(int, const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
int ewendvn(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int ewendvn(int, const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
int einfov(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int einfov(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ewarnv(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ewarnv(const char * __EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
/*@}*/ /*@}*/
/*! @ingroup ebegin /*! @ingroup ebegin
@ -109,8 +107,8 @@ int ewarnv(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF;
* *
* Similar to einfo, but we add ... to the end of the message */ * Similar to einfo, but we add ... to the end of the message */
/*@{*/ /*@{*/
int ebeginv(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ebeginv(const char * EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
int ebegin(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF; int ebegin(const char * EINFO_RESTRICT, ...) EINFO_PRINTF(1, 2);
/*@}*/ /*@}*/
/*! @ingroup eend /*! @ingroup eend
@ -122,12 +120,12 @@ int ebegin(const char * __EINFO_RESTRICT, ...) __EINFO_PRINTF;
* *
* ebracket allows you to specifiy the position, color and message */ * ebracket allows you to specifiy the position, color and message */
/*@{*/ /*@{*/
int eend(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int eend(int, const char * EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
int ewend(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int ewend(int, const char * EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
void ebracket(int, ECOLOR, const char * __EINFO_RESTRICT); void ebracket(int, ECOLOR, const char * EINFO_RESTRICT);
int eendv(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int eendv(int, const char * EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
int ewendv(int, const char * __EINFO_RESTRICT, ...) __EEND_PRINTF; int ewendv(int, const char * EINFO_RESTRICT, ...) EINFO_PRINTF(2, 3);
/*@}*/ /*@}*/
/*! @ingroup eindent /*! @ingroup eindent
@ -141,7 +139,7 @@ void eindentv(void);
void eoutdentv(void); void eoutdentv(void);
/*! @brief Prefix each einfo line with something */ /*! @brief Prefix each einfo line with something */
void eprefix(const char * __EINFO_RESTRICT); void eprefix(const char * EINFO_RESTRICT);
__END_DECLS __END_DECLS
#endif #endif

View File

@ -316,7 +316,7 @@ tgoto(const char *cap, int a, int b)
#endif #endif
static bool static bool
colour_terminal(FILE * __EINFO_RESTRICT f) colour_terminal(FILE * EINFO_RESTRICT f)
{ {
static int in_colour = -1; static int in_colour = -1;
char *e, *ee, *end, *d, *p; char *e, *ee, *end, *d, *p;
@ -460,7 +460,7 @@ colour_terminal(FILE * __EINFO_RESTRICT f)
} }
static int static int
get_term_columns(FILE * __EINFO_RESTRICT stream) get_term_columns(FILE * EINFO_RESTRICT stream)
{ {
struct winsize ws; struct winsize ws;
char *env = getenv("COLUMNS"); char *env = getenv("COLUMNS");
@ -480,14 +480,14 @@ get_term_columns(FILE * __EINFO_RESTRICT stream)
} }
void void
eprefix(const char *__EINFO_RESTRICT prefix) eprefix(const char *EINFO_RESTRICT prefix)
{ {
_eprefix = prefix; _eprefix = prefix;
} }
hidden_def(eprefix) hidden_def(eprefix)
static void static void EINFO_PRINTF(2, 0)
elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap) elogv(int level, const char *EINFO_RESTRICT fmt, va_list ap)
{ {
char *e = getenv("EINFO_LOG"); char *e = getenv("EINFO_LOG");
va_list apc; va_list apc;
@ -503,7 +503,7 @@ elogv(int level, const char *__EINFO_RESTRICT fmt, va_list ap)
} }
void void
elog(int level, const char *__EINFO_RESTRICT fmt, ...) elog(int level, const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -514,7 +514,7 @@ elog(int level, const char *__EINFO_RESTRICT fmt, ...)
hidden_def(elog) hidden_def(elog)
static int static int
_eindent(FILE * __EINFO_RESTRICT stream) _eindent(FILE * EINFO_RESTRICT stream)
{ {
char *env = getenv("EINFO_INDENT"); char *env = getenv("EINFO_INDENT");
int amount = 0; int amount = 0;
@ -538,7 +538,7 @@ _eindent(FILE * __EINFO_RESTRICT stream)
} }
static const char * static const char *
_ecolor(FILE * __EINFO_RESTRICT f, ECOLOR color) _ecolor(FILE * EINFO_RESTRICT f, ECOLOR color)
{ {
unsigned int i; unsigned int i;
@ -575,9 +575,8 @@ ecolor(ECOLOR color)
setenv("EINFO_LASTCMD", _cmd, 1); \ setenv("EINFO_LASTCMD", _cmd, 1); \
} }
static int static int EINFO_PRINTF(3, 0)
_einfo(FILE *f, ECOLOR color, const char *__EINFO_RESTRICT fmt, va_list va) _einfo(FILE *f, ECOLOR color, const char *EINFO_RESTRICT fmt, va_list va)
{ {
int retval = 0; int retval = 0;
char *last = getenv("EINFO_LASTCMD"); char *last = getenv("EINFO_LASTCMD");
@ -605,7 +604,7 @@ _einfo(FILE *f, ECOLOR color, const char *__EINFO_RESTRICT fmt, va_list va)
#define _eerrorvn(fmt, ap) _einfo(stderr, ECOLOR_BAD, fmt, ap) #define _eerrorvn(fmt, ap) _einfo(stderr, ECOLOR_BAD, fmt, ap)
int int
einfon(const char *__EINFO_RESTRICT fmt, ...) einfon(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -621,7 +620,7 @@ einfon(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(einfon) hidden_def(einfon)
int int
ewarnn(const char *__EINFO_RESTRICT fmt, ...) ewarnn(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -637,7 +636,7 @@ ewarnn(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ewarnn) hidden_def(ewarnn)
int int
eerrorn(const char *__EINFO_RESTRICT fmt, ...) eerrorn(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -651,7 +650,7 @@ eerrorn(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(eerrorn) hidden_def(eerrorn)
int int
einfo(const char *__EINFO_RESTRICT fmt, ...) einfo(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -668,7 +667,7 @@ einfo(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(einfo) hidden_def(einfo)
int int
ewarn(const char *__EINFO_RESTRICT fmt, ...) ewarn(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -686,7 +685,7 @@ ewarn(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ewarn) hidden_def(ewarn)
void void
ewarnx(const char *__EINFO_RESTRICT fmt, ...) ewarnx(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -703,7 +702,7 @@ ewarnx(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ewarnx) hidden_def(ewarnx)
int int
eerror(const char *__EINFO_RESTRICT fmt, ...) eerror(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -721,7 +720,7 @@ eerror(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(eerror) hidden_def(eerror)
void void
eerrorx(const char *__EINFO_RESTRICT fmt, ...) eerrorx(const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -737,7 +736,7 @@ eerrorx(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(eerrorx) hidden_def(eerrorx)
int int
ebegin(const char *__EINFO_RESTRICT fmt, ...) ebegin(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -756,7 +755,7 @@ ebegin(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ebegin) hidden_def(ebegin)
static void static void
_eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg) _eend(FILE * EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg)
{ {
int i; int i;
int cols; int cols;
@ -793,8 +792,8 @@ _eend(FILE * __EINFO_RESTRICT fp, int col, ECOLOR color, const char *msg)
} }
} }
static int static int EINFO_PRINTF(3, 0)
_do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list ap) _do_eend(const char *cmd, int retval, const char *EINFO_RESTRICT fmt, va_list ap)
{ {
int col = 0; int col = 0;
FILE *fp = stdout; FILE *fp = stdout;
@ -817,7 +816,7 @@ _do_eend(const char *cmd, int retval, const char *__EINFO_RESTRICT fmt, va_list
} }
int int
eend(int retval, const char *__EINFO_RESTRICT fmt, ...) eend(int retval, const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -832,7 +831,7 @@ eend(int retval, const char *__EINFO_RESTRICT fmt, ...)
hidden_def(eend) hidden_def(eend)
int int
ewend(int retval, const char *__EINFO_RESTRICT fmt, ...) ewend(int retval, const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -900,7 +899,7 @@ void eoutdent(void)
hidden_def(eoutdent) hidden_def(eoutdent)
int int
einfovn(const char *__EINFO_RESTRICT fmt, ...) einfovn(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -916,7 +915,7 @@ einfovn(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(einfovn) hidden_def(einfovn)
int int
ewarnvn(const char *__EINFO_RESTRICT fmt, ...) ewarnvn(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -932,7 +931,7 @@ ewarnvn(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ewarnvn) hidden_def(ewarnvn)
int int
einfov(const char *__EINFO_RESTRICT fmt, ...) einfov(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -949,7 +948,7 @@ einfov(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(einfov) hidden_def(einfov)
int int
ewarnv(const char *__EINFO_RESTRICT fmt, ...) ewarnv(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -966,7 +965,7 @@ ewarnv(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ewarnv) hidden_def(ewarnv)
int int
ebeginv(const char *__EINFO_RESTRICT fmt, ...) ebeginv(const char *EINFO_RESTRICT fmt, ...)
{ {
int retval; int retval;
va_list ap; va_list ap;
@ -986,7 +985,7 @@ ebeginv(const char *__EINFO_RESTRICT fmt, ...)
hidden_def(ebeginv) hidden_def(ebeginv)
int int
eendv(int retval, const char *__EINFO_RESTRICT fmt, ...) eendv(int retval, const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;
@ -1001,7 +1000,7 @@ eendv(int retval, const char *__EINFO_RESTRICT fmt, ...)
hidden_def(eendv) hidden_def(eendv)
int int
ewendv(int retval, const char *__EINFO_RESTRICT fmt, ...) ewendv(int retval, const char *EINFO_RESTRICT fmt, ...)
{ {
va_list ap; va_list ap;

View File

@ -84,8 +84,8 @@ static int do_e(int argc, char **argv)
int level = 0; int level = 0;
struct timespec ts; struct timespec ts;
struct timeval stop, now; struct timeval stop, now;
int (*e) (const char *, ...) __EINFO_PRINTF = NULL; int (*e) (const char *, ...) EINFO_PRINTF(1, 2) = NULL;
int (*ee) (int, const char *, ...) __EEND_PRINTF = NULL; int (*ee) (int, const char *, ...) EINFO_PRINTF(2, 3) = NULL;
/* Punt applet */ /* Punt applet */
argc--; argc--;
@ -205,9 +205,10 @@ static int do_e(int argc, char **argv)
ee = eend; ee = eend;
else if (strcmp(applet, "ewend") == 0) else if (strcmp(applet, "ewend") == 0)
ee = ewend; ee = ewend;
else if (strcmp(applet, "esyslog") == 0) else if (strcmp(applet, "esyslog") == 0) {
ee = elog; elog(retval, "%s", message);
else if (strcmp(applet, "veinfo") == 0) retval = 0;
} else if (strcmp(applet, "veinfo") == 0)
e = einfov; e = einfov;
else if (strcmp(applet, "veinfon") == 0) else if (strcmp(applet, "veinfon") == 0)
e = einfovn; e = einfovn;

View File

@ -557,7 +557,7 @@ static bool svc_wait(const char *svc)
static RC_SERVICE svc_status(void) static RC_SERVICE svc_status(void)
{ {
char status[10]; char status[10];
int (*e) (const char *fmt, ...) __EINFO_PRINTF = einfo; int (*e) (const char *fmt, ...) EINFO_PRINTF(1, 2) = einfo;
RC_SERVICE state = rc_service_state(service); RC_SERVICE state = rc_service_state(service);
if (state & RC_SERVICE_STOPPING) { if (state & RC_SERVICE_STOPPING) {