aboutsummaryrefslogtreecommitdiffstats
path: root/main/recode/0001-avoid-gnu-error-3.patch
blob: 423ae190c59dbf7459a5dca5013a5901632e693d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
From 2b46384a2f115e54fef5e5295b4ad71206649b7f Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Fri, 8 Jan 2016 15:41:08 +0000
Subject: [PATCH] avoid gnu error(3)

---
 lib/Makefile.am |  4 +--
 lib/error.h     | 78 ---------------------------------------------------------
 src/argmatch.c  |  6 +++--
 src/common.h    |  1 -
 src/main.c      | 51 +++++++++++++++++++------------------
 src/xmalloc.c   |  8 ++----
 6 files changed, 34 insertions(+), 114 deletions(-)
 delete mode 100644 lib/error.h

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 237fe72..36d7430 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -20,8 +20,8 @@
 AUTOMAKE_OPTIONS = gnits
 
 noinst_LIBRARIES = libreco.a
-noinst_HEADERS = error.h getopt.h gettext.h pathmax.h xstring.h
-libreco_a_SOURCES = error.c getopt.c getopt1.c xstrdup.c
+noinst_HEADERS = xstring.h
+libreco_a_SOURCES = xstrdup.c
 
 EXTRA_DIST = alloca.c gettext.c malloc.c realloc.c strtol.c strtoul.c
 
diff --git a/lib/error.h b/lib/error.h
deleted file mode 100644
index 20f7582..0000000
--- a/lib/error.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Declaration for error-reporting function
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
-
-
-   NOTE: The canonical source of this file is maintained with the GNU C Library.
-   Bugs can be reported to bug-glibc@prep.ai.mit.edu.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any
-   later version.
-
-   This program 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 General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-   USA.  */
-
-#ifndef _ERROR_H
-#define _ERROR_H 1
-
-#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
-
-#ifdef	__cplusplus
-extern "C" {
-#endif
-
-#if defined (__STDC__) && __STDC__
-
-/* Print a message with `fprintf (stderr, FORMAT, ...)';
-   if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
-   If STATUS is nonzero, terminate the program with `exit (STATUS)'.  */
-
-extern void error (int status, int errnum, const char *format, ...)
-     __attribute__ ((__format__ (__printf__, 3, 4)));
-
-extern void error_at_line (int status, int errnum, const char *fname,
-			   unsigned int lineno, const char *format, ...)
-     __attribute__ ((__format__ (__printf__, 5, 6)));
-
-/* 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.  */
-extern void (*error_print_progname) (void);
-
-#else
-void error ();
-void error_at_line ();
-extern void (*error_print_progname) ();
-#endif
-
-/* This variable is incremented each time `error' is called.  */
-extern unsigned int error_message_count;
-
-/* Sometimes we want to have at most one error per line.  This
-   variable controls whether this mode is selected or not.  */
-extern int error_one_per_line;
-
-#ifdef	__cplusplus
-}
-#endif
-
-#endif /* error.h */
diff --git a/src/argmatch.c b/src/argmatch.c
index 9642706..daa39bd 100644
--- a/src/argmatch.c
+++ b/src/argmatch.c
@@ -36,7 +36,9 @@
 # define _(Text) Text
 #endif
 
-#include "error.h"
+#include <err.h>
+#include <stdlib.h>
+
 #include "quotearg.h"
 
 /* When reporting an invalid argument, show nonprinting characters
@@ -159,7 +161,7 @@ argmatch_invalid (const char *context, const char *value, int problem)
 			? _("invalid argument %s for `%s'")
 			: _("ambiguous argument %s for `%s'"));
 
-  error (0, 0, format, quotearg_style (ARGMATCH_QUOTING_STYLE, value), context);
+  warnx (format, quotearg_style (ARGMATCH_QUOTING_STYLE, value), context);
 }
 
 /* List the valid arguments for argmatch.
diff --git a/src/common.h b/src/common.h
index a4f56dc..089ea61 100644
--- a/src/common.h
+++ b/src/common.h
@@ -112,7 +112,6 @@ typedef enum {false = 0, true = 1} bool;
 #ifndef errno
 extern int errno;
 #endif
-#include "error.h"
 
 /* Generate a mask of LENGTH one-bits, right justified in a word.  */
 #define MASK(Length) ((unsigned) ~(~0 << (Length)))
diff --git a/src/main.c b/src/main.c
index 3a5de1d..9575b32 100644
--- a/src/main.c
+++ b/src/main.c
@@ -23,7 +23,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include "getopt.h"
+#include <getopt.h>
+#include <err.h>
 
 #if HAVE_UNISTD_H
 # include <unistd.h>
@@ -427,11 +428,11 @@ main (int argc, char *const *argv)
 	switch (argmatch (optarg, sequence_strings, NULL, 0))
 	  {
 	  case -2:
-	    error (0, 0, _("Sequence `%s' is ambiguous"), optarg);
+	    warnx ( _("Sequence `%s' is ambiguous"), optarg);
 	    usage (EXIT_FAILURE, 0);
 
 	  case -1:
-	    error (0, 0, _("Sequence `%s' is unknown"), optarg);
+	    warnx ( _("Sequence `%s' is unknown"), optarg);
 	    usage (EXIT_FAILURE, 0);
 
 	  case 0:
@@ -461,11 +462,11 @@ main (int argc, char *const *argv)
 	  switch (argmatch (optarg, language_strings, NULL, 0))
 	    {
 	    case -2:
-	      error (0, 0, _("Language `%s' is ambiguous"), optarg);
+	      warnx ( _("Language `%s' is ambiguous"), optarg);
 	      usage (EXIT_FAILURE, 0);
 
 	    default:		/* -1 */
-	      error (0, 0, _("Language `%s' is unknown"), optarg);
+	      warnx ( _("Language `%s' is unknown"), optarg);
 	      usage (EXIT_FAILURE, 0);
 
 	    case 0:
@@ -519,11 +520,11 @@ main (int argc, char *const *argv)
 	    switch (argmatch (buffer, language_strings, NULL, 0))
 	      {
 	      case -2:
-		error (0, 0, _("Language `%s' is ambiguous"), buffer);
+		warnx ( _("Language `%s' is ambiguous"), buffer);
 		usage (EXIT_FAILURE, 0);
 
 	      default:		/* -1 */
-		error (0, 0, _("Language `%s' is unknown"), buffer);
+		warnx ( _("Language `%s' is unknown"), buffer);
 		usage (EXIT_FAILURE, 0);
 
 	      case 0:
@@ -557,11 +558,11 @@ main (int argc, char *const *argv)
 	  switch (argmatch (optarg, format_strings, NULL, 0))
 	    {
 	    case -2:
-	      error (0, 0, _("Format `%s' is ambiguous"), optarg);
+	      warnx ( _("Format `%s' is ambiguous"), optarg);
 	      usage (EXIT_FAILURE, 0);
 
 	    case -1:
-	      error (0, 0, _("Format `%s' is unknown"), optarg);
+	      warnx ( _("Format `%s' is unknown"), optarg);
 	      usage (EXIT_FAILURE, 0);
 
 	    case 0:
@@ -666,7 +667,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 
       if (!alias)
 	{
-	  error (0, 0, _("Symbol `%s' is unknown"), ignored_name);
+	  warnx ( _("Symbol `%s' is unknown"), ignored_name);
 	  usage (EXIT_FAILURE, 1);
 	}
 
@@ -688,12 +689,12 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
       if (charset_restrictions)
 	if (!decode_known_pairs (outer, charset_restrictions))
 	  {
-	    error (0, 0, "Could not understand `%s'", charset_restrictions);
+	    warnx ( "Could not understand `%s'", charset_restrictions);
 	    usage (EXIT_FAILURE, 0);
 	  }
       if (optind + 1 < argc)
 	{
-	  error (0, 0, "Argument `%s' is extraneous", argv[optind]);
+	  warnx ( "Argument `%s' is extraneous", argv[optind]);
 	  usage (EXIT_FAILURE, 0);
 	}
 
@@ -706,7 +707,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 
 	  if (!alias)
 	    {
-	      error (0, 0, _("Charset `%s' is unknown or ambiguous"),
+	      warnx ( _("Charset `%s' is unknown or ambiguous"),
 		     argv[optind]);
 	      usage (EXIT_FAILURE, 1);
 	    }
@@ -720,7 +721,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 
 	  if (!alias)
 	    {
-	      error (0, 0, _("Charset `%s' is unknown or ambiguous"),
+	      warnx ( _("Charset `%s' is unknown or ambiguous"),
 		     argv[optind]);
 	      usage (EXIT_FAILURE, 1);
 	    }
@@ -751,7 +752,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 
   if (optind + 1 > argc)
     {
-      error (0, 0, _("Required argument is missing"));
+      warnx ( _("Required argument is missing"));
       usage (EXIT_FAILURE, 0);
     }
 
@@ -794,13 +795,13 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 
 	    user_request = rewritten_request;
 	    if (!quiet_flag)
-	      error (0, 0, _("Syntax is deprecated, please prefer `%s'"),
+	      warnx ( _("Syntax is deprecated, please prefer `%s'"),
 		     user_request);
 	  }
       }
 
     if (!recode_scan_request (request, user_request))
-      error (EXIT_FAILURE, 0, _("Request `%s' is erroneous"), user_request);
+      errx (EXIT_FAILURE, _("Request `%s' is erroneous"), user_request);
     if (rewritten_request)
       free (rewritten_request);
   }
@@ -857,7 +858,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 	      /* Check if the file can be read and rewritten.  */
 
 	      if (file = fopen (input_name, "r+"), file == NULL)
-		error (EXIT_FAILURE, errno, "fopen (%s)", input_name);
+		err (EXIT_FAILURE, "fopen (%s)", input_name);
 
 	      /* Save the input file attrobites.  */
 
@@ -917,22 +918,22 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 		  /* Move the new file over the original.  */
 
 		  if (unlink (input_name) < 0)
-		    error (EXIT_FAILURE, errno, "unlink (%s)", input_name);
+		    err (EXIT_FAILURE, "unlink (%s)", input_name);
 
 		  /* Preserve the file permissions.  */
 
 		  if (chmod (output_name, file_stat.st_mode & 07777) < 0)
-		    error (EXIT_FAILURE, errno, "chmod (%s)", output_name);
+		    err (EXIT_FAILURE, "chmod (%s)", output_name);
 #if HAVE_RENAME
 		  if (rename (output_name, input_name) < 0)
-		    error (EXIT_FAILURE, errno, "rename (%s, %s)",
+		    err (EXIT_FAILURE, "rename (%s, %s)",
 			   output_name, input_name);
 #else
 		  if (link (output_name, input_name) < 0)
-		    error (EXIT_FAILURE, errno, "link (%s, %s)",
+		    err (EXIT_FAILURE, "link (%s, %s)",
 			   output_name, input_name);
 		  if (unlink (output_name) < 0)
-		    error (EXIT_FAILURE, errno, "unlink (%s)", output_name);
+		    err (EXIT_FAILURE, "unlink (%s)", output_name);
 #endif
 
 		  /* Adjust the time stamp for the new file.  */
@@ -958,7 +959,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 		      fflush (stderr);
 		    }
 		  else if (!quiet_flag)
-		    error (0, 0, _("%s failed: %s in step `%s..%s'"),
+		    warnx ( _("%s failed: %s in step `%s..%s'"),
 			   input_name, task_perror (task),
 			   task->error_at_step->before->name,
 			   task->error_at_step->after->name);
@@ -981,7 +982,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"),
 	  {
 	    success = false;
 	    if (!quiet_flag)
-	      error (0, 0, _("%s in step `%s..%s'"),
+	      warnx ( _("%s in step `%s..%s'"),
 		     task_perror (task),
 		     task->error_at_step->before->name,
 		     task->error_at_step->after->name);
diff --git a/src/xmalloc.c b/src/xmalloc.c
index 8206a94..9c5080e 100644
--- a/src/xmalloc.c
+++ b/src/xmalloc.c
@@ -20,6 +20,7 @@
 #endif
 
 #include <sys/types.h>
+#include <err.h>
 
 #if STDC_HEADERS
 # include <stdlib.h>
@@ -39,7 +40,6 @@ void free ();
 #endif
 #define N_(Text) Text
 
-#include "error.h"
 #include "xalloc.h"
 
 #ifndef EXIT_FAILURE
@@ -70,11 +70,7 @@ xalloc_die (void)
 {
   if (xalloc_fail_func)
     (*xalloc_fail_func) ();
-  error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
-  /* The `noreturn' cannot be given to error, since it may return if
-     its first argument is 0.  To help compilers understand the
-     xalloc_die does terminate, call exit. */
-  exit (EXIT_FAILURE);
+  errx (xalloc_exit_failure, "%s", _(xalloc_msg_memory_exhausted));
 }
 
 /* Allocate N bytes of memory dynamically, with error checking.  */
-- 
2.7.0