diff options
author | Pádraig Brady <P@draigBrady.com> | 2016-10-15 23:10:35 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2016-10-16 12:23:55 +0100 |
commit | 492dcb2eb191b844a2fd5e51db3eed85289bea1f (patch) | |
tree | 910f93d88891b573520ebd5c812d61ddc7fbeed8 /src/join.c | |
parent | d035eacfdeba2da0134e606c8a63b2f3c0bd05bb (diff) | |
download | coreutils-492dcb2eb191b844a2fd5e51db3eed85289bea1f.tar.xz |
all: use die() rather than error(EXIT_FAILURE)
die() has the advantage of being apparent to the compiler
that it doesn't return, which will avoid warnings in some cases,
and possibly generate better code.
* cfg.mk (sc_die_EXIT_FAILURE): A new syntax check rule to
catch any new uses of error (CONSTANT, ...);
Diffstat (limited to 'src/join.c')
-rw-r--r-- | src/join.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/join.c b/src/join.c index 9b25da667..98b461c40 100644 --- a/src/join.c +++ b/src/join.c @@ -23,6 +23,7 @@ #include <getopt.h> #include "system.h" +#include "die.h" #include "error.h" #include "fadvise.h" #include "hard-locale.h" @@ -461,7 +462,7 @@ get_line (FILE *fp, struct line **linep, int which) if (! readlinebuffer_delim (&line->buf, fp, eolchar)) { if (ferror (fp)) - error (EXIT_FAILURE, errno, _("read error")); + die (EXIT_FAILURE, errno, _("read error")); freeline (line); return false; } @@ -850,7 +851,7 @@ string_to_join_field (char const *str) if (s_err == LONGINT_OVERFLOW || (s_err == LONGINT_OK && SIZE_MAX < val)) val = SIZE_MAX; else if (s_err != LONGINT_OK || val == 0) - error (EXIT_FAILURE, 0, _("invalid field number: %s"), quote (str)); + die (EXIT_FAILURE, 0, _("invalid field number: %s"), quote (str)); result = val - 1; @@ -871,7 +872,7 @@ decode_field_spec (const char *s, int *file_index, size_t *field_index) if (s[1]) { /* '0' must be all alone -- no '.FIELD'. */ - error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s)); + die (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s)); } *file_index = 0; *field_index = 0; @@ -880,14 +881,14 @@ decode_field_spec (const char *s, int *file_index, size_t *field_index) case '1': case '2': if (s[1] != '.') - error (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s)); + die (EXIT_FAILURE, 0, _("invalid field specifier: %s"), quote (s)); *file_index = s[0] - '0'; *field_index = string_to_join_field (s + 2); break; default: - error (EXIT_FAILURE, 0, - _("invalid file number in field spec: %s"), quote (s)); + die (EXIT_FAILURE, 0, + _("invalid file number in field spec: %s"), quote (s)); /* Tell gcc -W -Wall that we can't get beyond this point. This avoids a warning (otherwise legit) that the caller's copies @@ -930,8 +931,8 @@ set_join_field (size_t *var, size_t val) { unsigned long int var1 = *var + 1; unsigned long int val1 = val + 1; - error (EXIT_FAILURE, 0, _("incompatible join fields %lu, %lu"), - var1, val1); + die (EXIT_FAILURE, 0, + _("incompatible join fields %lu, %lu"), var1, val1); } *var = val; } @@ -1047,8 +1048,8 @@ main (int argc, char **argv) unsigned long int val; if (xstrtoul (optarg, NULL, 10, &val, "") != LONGINT_OK || (val != 1 && val != 2)) - error (EXIT_FAILURE, 0, - _("invalid field number: %s"), quote (optarg)); + die (EXIT_FAILURE, 0, + _("invalid field number: %s"), quote (optarg)); if (val == 1) print_unpairables_1 = true; else @@ -1058,8 +1059,8 @@ main (int argc, char **argv) case 'e': if (empty_filler && ! STREQ (empty_filler, optarg)) - error (EXIT_FAILURE, 0, - _("conflicting empty-field replacement strings")); + die (EXIT_FAILURE, 0, + _("conflicting empty-field replacement strings")); empty_filler = optarg; break; @@ -1111,11 +1112,11 @@ main (int argc, char **argv) if (STREQ (optarg, "\\0")) newtab = '\0'; else - error (EXIT_FAILURE, 0, _("multi-character tab %s"), - quote (optarg)); + die (EXIT_FAILURE, 0, _("multi-character tab %s"), + quote (optarg)); } if (0 <= tab && tab != newtab) - error (EXIT_FAILURE, 0, _("incompatible tabs")); + die (EXIT_FAILURE, 0, _("incompatible tabs")); tab = newtab; } break; @@ -1183,18 +1184,18 @@ main (int argc, char **argv) fp1 = STREQ (g_names[0], "-") ? stdin : fopen (g_names[0], "r"); if (!fp1) - error (EXIT_FAILURE, errno, "%s", quotef (g_names[0])); + die (EXIT_FAILURE, errno, "%s", quotef (g_names[0])); fp2 = STREQ (g_names[1], "-") ? stdin : fopen (g_names[1], "r"); if (!fp2) - error (EXIT_FAILURE, errno, "%s", quotef (g_names[1])); + die (EXIT_FAILURE, errno, "%s", quotef (g_names[1])); if (fp1 == fp2) - error (EXIT_FAILURE, errno, _("both files cannot be standard input")); + die (EXIT_FAILURE, errno, _("both files cannot be standard input")); join (fp1, fp2); if (fclose (fp1) != 0) - error (EXIT_FAILURE, errno, "%s", quotef (g_names[0])); + die (EXIT_FAILURE, errno, "%s", quotef (g_names[0])); if (fclose (fp2) != 0) - error (EXIT_FAILURE, errno, "%s", quotef (g_names[1])); + die (EXIT_FAILURE, errno, "%s", quotef (g_names[1])); if (issued_disorder_warning[0] || issued_disorder_warning[1]) return EXIT_FAILURE; |