Updated man page to document new behaviour of -Z, -z and -Q flags.
[unix-history] / gnu / usr.bin / sort / error.c
CommitLineData
f0ec3cf6 1/* error.c -- error handler for noninteractive utilities
c4698cbb 2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
f0ec3cf6
NW
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18/* Written by David MacKenzie. */
19
c4698cbb
NW
20#ifdef HAVE_CONFIG_H
21#if defined (CONFIG_BROKETS)
22/* We use <config.h> instead of "config.h" so that a compilation
23 using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
24 (which it would do because it found this file in $srcdir). */
25#include <config.h>
26#else
27#include "config.h"
28#endif
29#endif
30
f0ec3cf6
NW
31#include <stdio.h>
32
33#ifdef HAVE_VPRINTF
34
35#if __STDC__
36#include <stdarg.h>
37#define VA_START(args, lastarg) va_start(args, lastarg)
38#else /* !__STDC__ */
39#include <varargs.h>
40#define VA_START(args, lastarg) va_start(args)
41#endif /* !__STDC__ */
42
43#else /* !HAVE_VPRINTF */
44
45#ifdef HAVE_DOPRNT
46#define va_alist args
47#define va_dcl int args;
48#else /* !HAVE_DOPRNT */
49#define va_alist a1, a2, a3, a4, a5, a6, a7, a8
50#define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
51#endif /* !HAVE_DOPRNT */
52
53#endif /* !HAVE_VPRINTF */
54
55#ifdef STDC_HEADERS
56#include <stdlib.h>
57#include <string.h>
58#else /* !STDC_HEADERS */
59void exit ();
60#endif /* !STDC_HEADERS */
61
62extern char *program_name;
63
64#ifndef HAVE_STRERROR
65static char *
66private_strerror (errnum)
67 int errnum;
68{
69 extern char *sys_errlist[];
70 extern int sys_nerr;
71
72 if (errnum > 0 && errnum <= sys_nerr)
73 return sys_errlist[errnum];
74 return "Unknown system error";
75}
76#define strerror private_strerror
77#endif /* !HAVE_STRERROR */
78
79/* Print the program name and error message MESSAGE, which is a printf-style
80 format string with optional args.
81 If ERRNUM is nonzero, print its corresponding system error message.
82 Exit with status STATUS if it is nonzero. */
83/* VARARGS */
84void
85#if defined (HAVE_VPRINTF) && __STDC__
86error (int status, int errnum, char *message, ...)
87#else /* !HAVE_VPRINTF or !__STDC__ */
88error (status, errnum, message, va_alist)
89 int status;
90 int errnum;
91 char *message;
92 va_dcl
93#endif /* !HAVE_VPRINTF or !__STDC__ */
94{
95#ifdef HAVE_VPRINTF
96 va_list args;
97#endif /* HAVE_VPRINTF */
98
99 fprintf (stderr, "%s: ", program_name);
100#ifdef HAVE_VPRINTF
101 VA_START (args, message);
102 vfprintf (stderr, message, args);
103 va_end (args);
104#else /* !HAVE_VPRINTF */
105#ifdef HAVE_DOPRNT
106 _doprnt (message, &args, stderr);
107#else /* !HAVE_DOPRNT */
108 fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
109#endif /* !HAVE_DOPRNT */
110#endif /* !HAVE_VPRINTF */
111 if (errnum)
112 fprintf (stderr, ": %s", strerror (errnum));
113 putc ('\n', stderr);
114 fflush (stderr);
115 if (status)
116 exit (status);
117}