about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-12-06 00:14:32 +0000
committerRoland McGrath <roland@gnu.org>1995-12-06 00:14:32 +0000
commit196980f5117c8d38f10d64bf67eeb0924651675f (patch)
tree4e2a731a1f766ee63e1038d7f38bee3db8c78a2c /misc
parent77a58cad3fa0a286bd2581187a2463a762d711ba (diff)
downloadglibc-196980f5117c8d38f10d64bf67eeb0924651675f.tar.gz
glibc-196980f5117c8d38f10d64bf67eeb0924651675f.tar.xz
glibc-196980f5117c8d38f10d64bf67eeb0924651675f.zip
Updated from ../gpl2lgpl.sed /home/gd/gnu/lib/error.c
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile7
-rw-r--r--misc/err.c87
-rw-r--r--misc/err.h56
-rw-r--r--misc/error.c134
-rw-r--r--misc/error.h48
5 files changed, 330 insertions, 2 deletions
diff --git a/misc/Makefile b/misc/Makefile
index 173413c9ed..102fdd343f 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -25,7 +25,8 @@ subdir	:= misc
 headers	:= sys/uio.h sys/ioctl.h sys/ptrace.h ioctls.h sys/file.h	\
 	   a.out.h nlist.h stab.h stab.def sgtty.h sys/dir.h sys/cdefs.h \
 	   ttyent.h syscall.h syslog.h sys/syslog.h paths.h sys/reboot.h \
-	   sys/mman.h sys/param.h fstab.h mntent.h search.h utmp.h
+	   sys/mman.h sys/param.h fstab.h mntent.h search.h utmp.h	 \
+	   err.h error.h
 
 routines := brk sbrk sstk ioctl \
 	    readv writev \
@@ -50,12 +51,14 @@ routines := brk sbrk sstk ioctl \
 	    syslog syscall daemon \
 	    mmap munmap mprotect msync madvise \
 	    efgcvt efgcvt_r \
-	    hsearch hsearch_r tsearch
+	    hsearch hsearch_r tsearch \
+	    err error
 aux := progname init-misc
 distribute := bsd-compat.c
 extra-objs := bsd-compat.o
 install-lib := libbsd-compat.a libg.a
 non-lib.a := libbsd-compat.a
+gpl2lgpl := error.c error.h
 
 # Build the -lutil library with these extra functions.
 extra-libs	:= libutil
diff --git a/misc/err.c b/misc/err.c
new file mode 100644
index 0000000000..82719a8756
--- /dev/null
+++ b/misc/err.c
@@ -0,0 +1,87 @@
+/* err.c --- 4.4BSD utility functions for error messages.
+Copyright (C) 1995 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#include <stdarg.h>
+#include <err.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+extern char *__progname;
+
+#define VA(call)							      \
+{									      \
+  va_list ap;								      \
+  va_start (ap, format);						      \
+  call;									      \
+  va_end (ap);								      \
+}
+
+void
+vwarn (const char *format, __gnuc_va_list ap)
+{
+  fprintf (stderr, format, ap);
+}
+
+void
+vwarnx (const char *format, __gnuc_va_list ap)
+{
+  if (__progname)
+    fprintf (stderr, "%s: ", __progname);
+  fprintf (stderr, format, ap);
+  putc ('\n', stderr);
+}
+
+
+void
+warn (const char *format, ...)
+{
+  VA (vwarn (format, ap))
+}
+
+void
+warnx (const char *format, ...)
+{
+  VA (vwarnx (format, ap))
+}
+
+void
+verr (int status, const char *format, __gnuc_va_list ap)
+{
+  vwarn (format, ap);
+  exit (status);
+}
+
+void
+verrx (int status, const char *format, __gnuc_va_list ap)
+{
+  vwarnx (format, ap);
+  exit (status);
+}
+
+void
+err (int status, const char *format, ...)
+{
+  VA (verr (status, format, ap))
+}
+
+void
+errx (int status, const char *format, ...)
+{
+  VA (verrx (status, format, ap))
+}
diff --git a/misc/err.h b/misc/err.h
new file mode 100644
index 0000000000..c81de1b396
--- /dev/null
+++ b/misc/err.h
@@ -0,0 +1,56 @@
+/* err.h --- 4.4BSD utility functions for error messages.
+Copyright (C) 1995 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#ifndef	_ERR_H_
+#define	_ERR_H_	1
+#include <features.h>
+
+#define	__need___va_list
+#include <stdarg.h>
+#ifndef	__GNUC_VA_LIST
+#define	__gnuc_va_list	__ptr_t
+#endif
+
+__BEGIN_DECLS
+
+/* Print FORMAT on stderr.  */
+extern void warn __P ((const char *__format, ...))
+     __attribute__ ((format (printf, 1, 2)));
+extern void vwarn __P ((const char *__format, __gnuc_va_list))
+     __attribute__ ((format (printf, 1, 0)));
+
+/* Print "program: ", and FORMAT, and a newline, on stderr.  */
+extern void warnx __P ((const char *__format, ...))
+     __attribute__ ((format (printf, 1, 2)));
+extern void vwarnx __P ((const char *__format, __gnuc_va_list))
+     __attribute__ ((format (printf, 1, 0)));
+
+/* Likewise, and then exit with STATUS.  */
+extern void err __P ((int __status, const char *__format, ...))
+     __attribute__ ((noreturn, format (printf, 2, 3)));
+extern void verr __P ((int __status, const char *__format, __gnuc_va_list))
+     __attribute__ ((noreturn, format (printf, 2, 0)));
+extern void errx __P ((int __status, const char *__format, ...))
+     __attribute__ ((noreturn, format (printf, 2, 3)));
+extern void verrx __P ((int __status, const char *, __gnuc_va_list))
+     __attribute__ ((noreturn, format (printf, 2, 0)));
+
+__END_DECLS
+
+#endif	/* err.h */
diff --git a/misc/error.c b/misc/error.c
new file mode 100644
index 0000000000..da3c6ee1b2
--- /dev/null
+++ b/misc/error.c
@@ -0,0 +1,134 @@
+/* error.c -- error handler for noninteractive utilities
+   Copyright (C) 1990, 91, 92, 93, 94, 95 Free Software Foundation, Inc.
+
+This file is part of the GNU C Library.  Its master source is NOT part of
+the C library, however.  The master source lives in /gd/gnu/lib.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+/* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#if HAVE_VPRINTF || HAVE_DOPRNT || _LIBC
+# if __STDC__
+#  include <stdarg.h>
+#  define VA_START(args, lastarg) va_start(args, lastarg)
+# else
+#  include <varargs.h>
+#  define VA_START(args, lastarg) va_start(args)
+# endif
+#else
+# define va_alist a1, a2, a3, a4, a5, a6, a7, a8
+# define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
+#endif
+
+#if STDC_HEADERS || _LIBC
+# include <stdlib.h>
+# include <string.h>
+#else
+void exit ();
+#endif
+
+/* This variable is incremented each time `error' is called.  */
+unsigned int error_message_count;
+
+/* If NULL, error will flush stdout, then print on stderr the program
+   name, a colon and a space.  Otherwise, error will call this
+   function without parameters instead.  */
+void (*error_print_progname) () = NULL;
+
+#ifdef _LIBC
+#define program_name program_invocation_name
+#endif
+
+/* The calling program should define program_name and set it to the
+   name of the executing program.  */
+extern char *program_name;
+
+#if HAVE_STRERROR || _LIBC
+# ifndef strerror		/* On some systems, strerror is a macro */
+char *strerror ();
+# endif
+#else
+static char *
+private_strerror (errnum)
+     int errnum;
+{
+  extern char *sys_errlist[];
+  extern int sys_nerr;
+
+  if (errnum > 0 && errnum <= sys_nerr)
+    return sys_errlist[errnum];
+  return "Unknown system error";
+}
+#define strerror private_strerror
+#endif
+
+/* Print the program name and error message MESSAGE, which is a printf-style
+   format string with optional args.
+   If ERRNUM is nonzero, print its corresponding system error message.
+   Exit with status STATUS if it is nonzero.  */
+/* VARARGS */
+
+void
+#if defined(VA_START) && __STDC__
+error (int status, int errnum, const char *message, ...)
+#else
+error (status, errnum, message, va_alist)
+     int status;
+     int errnum;
+     char *message;
+     va_dcl
+#endif
+{
+#ifdef VA_START
+  va_list args;
+#endif
+
+  if (error_print_progname)
+    (*error_print_progname) ();
+  else
+    {
+      fflush (stdout);
+      fprintf (stderr, "%s: ", program_name);
+    }
+
+#ifdef VA_START
+  VA_START (args, message);
+# if HAVE_VPRINTF || _LIBC
+  vfprintf (stderr, message, args);
+# else
+  _doprnt (message, args, stderr);
+# endif
+  va_end (args);
+#else
+  fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
+#endif
+
+  ++error_message_count;
+
+  if (errnum)
+    fprintf (stderr, ": %s", strerror (errnum));
+  putc ('\n', stderr);
+  fflush (stderr);
+  if (status)
+    exit (status);
+}
diff --git a/misc/error.h b/misc/error.h
new file mode 100644
index 0000000000..40b345b9fc
--- /dev/null
+++ b/misc/error.h
@@ -0,0 +1,48 @@
+/* error.h -- declaration for error-reporting function
+   Copyright (C) 1995 Software Foundation, Inc.
+
+This file is part of the GNU C Library.  Its master source is NOT part of
+the C library, however.  The master source lives in /gd/gnu/lib.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB.  If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA.  */
+
+#ifndef _error_h_
+#define _error_h_
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
+#if __STDC__
+void error (int, int, const char *, ...) \
+  __attribute__ ((__format__ (__printf__, 3, 4)));
+#else
+void error ();
+#endif
+
+/* This variable is incremented each time `error' is called.  */
+extern unsigned int error_message_count;
+
+#endif /* _error_h_ */