From 063dfdc4f91072858789781fdf30940ef30307e1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 11 May 2015 21:09:50 +0200 Subject: libgamma_perror supports NULL and empty string in the same ways as perror MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/lib/libgamma-error.c.gpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/libgamma-error.c.gpp b/src/lib/libgamma-error.c.gpp index 3d124eb..27c2008 100644 --- a/src/lib/libgamma-error.c.gpp +++ b/src/lib/libgamma-error.c.gpp @@ -108,17 +108,29 @@ void libgamma_perror(const char* name, int error_code) long int gid = (long int)libgamma_group_gid; if (libgamma_group_name == NULL) /* Group name unknown. */ - fprintf(stderr, "%s: %s: %ld\n", name, error, gid); + if (name && *name) + fprintf(stderr, "%s: %s: %ld\n", name, error, gid); + else + fprintf(stderr, "%s: %ld\n", error, gid); else /* Group name known, ID is second class. */ - fprintf(stderr, "%s: %s: %s (%ld)\n", name, error, libgamma_group_name, gid); + if (name && *name) + fprintf(stderr, "%s: %s: %s (%ld)\n", name, error, libgamma_group_name, gid); + else + fprintf(stderr, "%s: %s (%ld)\n", error, libgamma_group_name, gid); } else if (error_code < LIBGAMMA_ERROR_MIN) /* If the error code does not exist, print "(?)" */ - fprintf(stderr, "%s: (?)\n", name); + if (name && *name) + fprintf(stderr, "%s: (?)\n", name); + else + fprintf(stderr, "(?)\n"); else /* Print the name of the error. */ - fprintf(stderr, "%s: %s\n", name, libgamma_name_of_error(error_code)); + if (name && *name) + fprintf(stderr, "%s: %s\n", name, libgamma_name_of_error(error_code)); + else + fprintf(stderr, "%s\n", libgamma_name_of_error(error_code)); } -- cgit v1.2.3-70-g09d2