[uClibc-cvs] uClibc/libc/misc/error err.c, NONE, 1.1 Makefile, 1.2, 1.3 error.c, 1.3, 1.4

Manuel Novoa III mjn3 at uclibc.org
Thu Mar 11 10:10:55 UTC 2004


Update of /var/cvs/uClibc/libc/misc/error
In directory nail:/tmp/cvs-serv1091

Modified Files:
	Makefile error.c 
Added Files:
	err.c 
Log Message:
Rewrite the err/warn functions as they were broken (__noreturn__ funcs
were returning).  Anyway, also make them threadsafe and smaller.  The
error.c file still needs work.


Index: Makefile
===================================================================
RCS file: /var/cvs/uClibc/libc/misc/error/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- a/Makefile	18 Oct 2003 10:18:48 -0000	1.2
+++ b/Makefile	11 Mar 2004 10:10:53 -0000	1.3
@@ -19,7 +19,7 @@
 TOPDIR=../../../
 include $(TOPDIR)Rules.mak
 
-CSRC=error.c
+CSRC=error.c err.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 OBJS=$(COBJS)
 

Index: error.c
===================================================================
RCS file: /var/cvs/uClibc/libc/misc/error/error.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/error.c	9 Oct 2003 09:02:05 -0000	1.3
+++ b/error.c	11 Mar 2004 10:10:53 -0000	1.4
@@ -99,78 +99,3 @@
 #undef error_at_line
 weak_alias (__error, error)
 weak_alias (__error_at_line, error_at_line)
-
-
-    
-#include "err.h"
-#include "errno.h"
-
-/* NORETURN */
-void verr (int status, const char *message, va_list args)
-{
-    fflush (stdout);
-
-    vfprintf (stderr, message, args);
-    if (errno) {
-        fprintf (stderr, ": %s", strerror (errno));
-    }
-    putc ('\n', stderr);
-    if (status)
-        exit (status);
-}
-
-/* NORETURN */
-void verrx (int status, const char *message, va_list args)
-{
-    fflush (stdout);
-
-    vfprintf (stderr, message, args);
-    if (status)
-        exit (status);
-}
-
-void vwarn (const char *message, va_list args)
-{
-    verr (0, message, args);
-}
-
-void vwarnx (const char *message, va_list args)
-{
-    verrx (0, message, args);
-}
-
-void err (int status, const char *message, ...)
-{
-    va_list args;
-
-    va_start (args, message);
-    verr (status, message, args);
-    va_end (args);
-}
-
-void errx (int status, const char *message, ...)
-{
-    va_list args;
-
-    va_start (args, message);
-    verrx (status, message, args);
-    va_end (args);
-}
-
-void warn (const char *message, ...)
-{
-    va_list args;
-
-    va_start (args, message);
-    verr (0, message, args);
-    va_end (args);
-}
-
-void warnx (const char *message, ...)
-{
-    va_list args;
-
-    va_start (args, message);
-    verrx (0, message, args);
-    va_end (args);
-}

--- NEW FILE: err.c ---
/* Copyright (C) 2004       Manuel Novoa III    <mjn3 at codepoet.org>
 *
 * GNU Library General Public License (LGPL) version 2 or later.
 *
 * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
 */

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <err.h>
#ifdef __UCLIBC_HAS_THREADS__
#include <pthread.h>
#endif

#ifdef __UCLIBC_MJN3_ONLY__
#warning REMINDER: Need a centralized __progname prototype.
#warning REMINDER: Deal with wide oriented stderr case.
#endif
extern const char *__progname;

static void vwarn_work(const char *format, va_list args, int showerr)
{
	/*                         0123 45678 9 a b*/
	static const char fmt[] = "%s: \0: %s\n\0\n";
	const char *f;
	char buf[64];
	__STDIO_AUTO_THREADLOCK_VAR;

	/* Do this first, in case something below changes errno. */
	f = fmt + 11;				/* At 11. */
	if (showerr) {
		f -= 4;					/* At 7. */
		_susv3_strerror_r(errno, buf, sizeof(buf));
	}

	__STDIO_AUTO_THREADLOCK(stderr);

	fprintf(stderr, fmt, __progname);
	if (format) {
		vfprintf(stderr, format, args);
		f -= 2;					/* At 5 (showerr) or 9. */
	}
	fprintf(stderr, f, buf);

	__STDIO_AUTO_THREADUNLOCK(stderr);
}

extern void warn(const char *format, ...)
{
	va_list args;

	va_start(args, format);
	vwarn(format, args);
	va_end(args);
}

extern void vwarn(const char *format, va_list args)
{
	vwarn_work(format, args, 1);
}

extern void warnx(const char *format, ...)
{
	va_list args;

	va_start(args, format);
	vwarnx(format, args);
	va_end(args);
}

extern void vwarnx(const char *format, va_list args)
{
	vwarn_work(format, args, 0);
}

extern void err(int status, const char *format, ...)
{
	va_list args;

	va_start(args, format);
	verr(status, format, args);
	/* This should get optimized away.  We'll leave it now for safety. */
	va_end(args);
}

extern void verr(int status, const char *format, va_list args)
{
	vwarn(format, args);
	exit(status);
}

extern void errx(int status, const char *format, ...)
{
	va_list args;

	va_start(args, format);
	verrx(status, format, args);
	/* This should get optimized away.  We'll leave it now for safety. */
	va_end(args);
}

extern void verrx(int status, const char *format, va_list args)
{
	vwarnx(format, args);
	exit(status);
}




More information about the uClibc-cvs mailing list