From 00f0791ebdf380c5b728d22fe5920528a25b79a7 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Thu, 18 Feb 1999 08:57:03 +0000 Subject: [PATCH] Define them as G_INLINE_FUNC in if possible. 1999-02-18 Martin Baulig * sysdeps/common/error.c (glibtop_error_r, glibtop_warn_r): Define them as G_INLINE_FUNC in if possible. (glibtop_error_io_r, glibtop_warn_io_r): Likewise. (glibtop_error_vr, glibtop_warn_vr): New functions taking a va_list. (glibtop_error_io_vr, glibtop_warn_io_vr): New functions taking an errno an a va_list. --- ChangeLog | 9 +++ include/glibtop/error.h | 102 ++++++++++++++++++++++++++--- sysdeps/common/error.c | 140 +++++++++++++++++++++++----------------- 3 files changed, 183 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce99bc6f..f8d16519 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +1999-02-18 Martin Baulig + + * sysdeps/common/error.c (glibtop_error_r, glibtop_warn_r): Define + them as G_INLINE_FUNC in if possible. + (glibtop_error_io_r, glibtop_warn_io_r): Likewise. + (glibtop_error_vr, glibtop_warn_vr): New functions taking a va_list. + (glibtop_error_io_vr, glibtop_warn_io_vr): New functions taking an + errno an a va_list. + 1999-02-17 Martin Baulig Released LibGTop 0.99.8. diff --git a/include/glibtop/error.h b/include/glibtop/error.h index 8305430a..5806d351 100644 --- a/include/glibtop/error.h +++ b/include/glibtop/error.h @@ -23,13 +23,65 @@ #define __GLIBTOP_ERROR_H__ #include +#include __BEGIN_DECLS -/* - * FIXME: varargs macros only supported on gcc. - * Breaks Sun CC, maybe others. - */ +extern void glibtop_error_vr __P((glibtop *, char *, va_list)); +extern void glibtop_warn_vr __P((glibtop *, char *, va_list)); + +extern void glibtop_error_io_vr __P((glibtop *, char *, gint, va_list)); +extern void glibtop_warn_io_vr __P((glibtop *, char *, gint, va_list)); + +G_INLINE_FUNC void glibtop_error_r __P((glibtop *, char *, ...)); +G_INLINE_FUNC void glibtop_warn_r __P((glibtop *, char *, ...)); + +G_INLINE_FUNC void glibtop_error_io_r __P((glibtop *, char *, ...)); +G_INLINE_FUNC void glibtop_warn_io_r __P((glibtop *, char *, ...)); + +#ifdef G_CAN_INLINE +G_INLINE_FUNC void +glibtop_error_r (glibtop *server, char *format, ...) +{ + va_list args; + + va_start (args, format); + glibtop_error_vr (server, format, args); + va_end (args); +} + +G_INLINE_FUNC void +glibtop_warn_r (glibtop *server, char *format, ...) +{ + va_list args; + + va_start (args, format); + glibtop_warn_vr (server, format, args); + va_end (args); +} + +G_INLINE_FUNC void +glibtop_error_io_r (glibtop *server, char *format, ...) +{ + va_list args; + + va_start (args, format); + glibtop_error_io_vr (server, format, errno, args); + va_end (args); +} + +G_INLINE_FUNC void +glibtop_warn_io_r (glibtop *server, char *format, ...) +{ + va_list args; + + va_start (args, format); + glibtop_warn_io_vr (server, format, errno, args); + va_end (args); +} +#endif + +#ifdef __GNUC__ #define glibtop_error(p1, args...) glibtop_error_r(glibtop_global_server , p1 , ## args) #define glibtop_warn(p1, args...) glibtop_warn_r(glibtop_global_server , p1 , ## args) @@ -37,11 +89,45 @@ __BEGIN_DECLS #define glibtop_error_io(p1, args...) glibtop_error_io_r(glibtop_global_server , p1 , ## args) #define glibtop_warn_io(p1, args...) glibtop_warn_io_r(glibtop_global_server , p1 , ## args) -extern void glibtop_error_r __P((glibtop *, char *, ...)); -extern void glibtop_warn_r __P((glibtop *, char *, ...)); +#else /* no __GNUC__ */ -extern void glibtop_error_io_r __P((glibtop *, char *, ...)); -extern void glibtop_warn_io_r __P((glibtop *, char *, ...)); +static void +glibtop_error (char *format, ...) +{ + va_list args; + va_start (args, format); + glibtop_error_vr (glibtop_global_server, format, args); + va_end (args); +} + +static void +glibtop_warn (char *format, ...) +{ + va_list args; + va_start (args, format); + glibtop_warn_vr (glibtop_global_server, format, args); + va_end (args); +} + +static void +glibtop_error_io (char *format, ...) +{ + va_list args; + va_start (args, format); + glibtop_error_io_vr (glibtop_global_server, format, errno, args); + va_end (args); +} + +static void +glibtop_warn_io (char *format, ...) +{ + va_list args; + va_start (args, format); + glibtop_warn_io_vr (glibtop_global_server, format, errno, args); + va_end (args); +} + +#endif /* no __GNUC__ */ __END_DECLS diff --git a/sysdeps/common/error.c b/sysdeps/common/error.c index 2ddd7dd9..f7772675 100644 --- a/sysdeps/common/error.c +++ b/sysdeps/common/error.c @@ -34,77 +34,97 @@ print_server_name (glibtop *server) } void +glibtop_error_vr (glibtop *server, char *format, va_list args) +{ + print_server_name (server); + vfprintf (stderr, format, args); + fprintf (stderr, "\n"); + +#ifdef LIBGTOP_ENABLE_DEBUG + abort (); +#else + exit (1); +#endif +} + +void +glibtop_error_io_vr (glibtop *server, char *format, gint error, va_list args) +{ + print_server_name (server); + vfprintf (stderr, format, args); + fprintf (stderr, ": %s\n", strerror (error)); + +#ifdef LIBGTOP_ENABLE_DEBUG + abort (); +#else + exit (1); +#endif +} + +void +glibtop_warn_vr (glibtop *server, char *format, va_list args) +{ + print_server_name (server); + vfprintf (stderr, format, args); + fprintf (stderr, "\n"); + +#ifdef LIBGTOP_FATAL_WARNINGS + abort (); +#endif +} + +void +glibtop_warn_io_vr (glibtop *server, char *format, gint error, va_list args) +{ + print_server_name (server); + vfprintf (stderr, format, args); + fprintf (stderr, ": %s\n", strerror (error)); + +#ifdef LIBGTOP_FATAL_WARNINGS + abort (); +#endif +} + +#ifndef G_CAN_INLINE + +G_INLINE_FUNC void glibtop_error_r (glibtop *server, char *format, ...) { - va_list ap; - - va_start (ap, format); + va_list args; - print_server_name (server); - vfprintf (stderr, format, ap); - fprintf (stderr, "\n"); - - va_end (ap); - -#ifdef LIBGTOP_ENABLE_DEBUG - abort (); -#else - exit (1); -#endif + va_start (args, format); + glibtop_error_vr (server, format, args); + va_end (args); } -void -glibtop_error_io_r (glibtop *server, char *format, ...) -{ - va_list ap; - - va_start (ap, format); - - print_server_name (server); - vfprintf (stderr, format, ap); - fprintf (stderr, ": %s\n", strerror (errno)); - - va_end (ap); - -#ifdef LIBGTOP_ENABLE_DEBUG - abort (); -#else - exit (1); -#endif -} - -void +G_INLINE_FUNC void glibtop_warn_r (glibtop *server, char *format, ...) { - va_list ap; - - va_start (ap, format); - - print_server_name (server); - vfprintf (stderr, format, ap); - fprintf (stderr, "\n"); - - va_end (ap); + va_list args; -#ifdef LIBGTOP_FATAL_WARNINGS - abort (); -#endif + va_start (args, format); + glibtop_warn_vr (server, format, args); + va_end (args); } -void +G_INLINE_FUNC void +glibtop_error_io_r (glibtop *server, char *format, ...) +{ + va_list args; + + va_start (args, format); + glibtop_error_io_vr (server, format, errno, args); + va_end (args); +} + +G_INLINE_FUNC void glibtop_warn_io_r (glibtop *server, char *format, ...) { - va_list ap; + va_list args; - va_start (ap, format); - - print_server_name (server); - vfprintf (stderr, format, ap); - fprintf (stderr, ": %s\n", strerror (errno)); - - va_end (ap); - -#ifdef LIBGTOP_FATAL_WARNINGS - abort (); -#endif + va_start (args, format); + glibtop_warn_io_vr (server, format, errno, args); + va_end (args); } + +#endif /* not G_CAN_INLINE */