From 492dcb2eb191b844a2fd5e51db3eed85289bea1f Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sat, 15 Oct 2016 23:10:35 +0100 Subject: 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, ...); --- src/stty.c | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'src/stty.c') diff --git a/src/stty.c b/src/stty.c index 467f8ae89..64435ad24 100644 --- a/src/stty.c +++ b/src/stty.c @@ -55,6 +55,7 @@ #include #include "system.h" +#include "die.h" #include "error.h" #include "fd-reopen.h" #include "quote.h" @@ -1136,7 +1137,7 @@ main (int argc, char **argv) case 'F': if (file_name) - error (EXIT_FAILURE, 0, _("only one device may be specified")); + die (EXIT_FAILURE, 0, _("only one device may be specified")); file_name = optarg; break; @@ -1169,14 +1170,14 @@ main (int argc, char **argv) /* Specifying both -a and -g gets an error. */ if (verbose_output && recoverable_output) - error (EXIT_FAILURE, 0, - _("the options for verbose and stty-readable output styles are\n" - "mutually exclusive")); + die (EXIT_FAILURE, 0, + _("the options for verbose and stty-readable output styles are\n" + "mutually exclusive")); /* Specifying any other arguments with -a or -g gets an error. */ if (!noargs && (verbose_output || recoverable_output)) - error (EXIT_FAILURE, 0, - _("when specifying an output style, modes may not be set")); + die (EXIT_FAILURE, 0, + _("when specifying an output style, modes may not be set")); /* FIXME: it'd be better not to open the file until we've verified that all arguments are valid. Otherwise, we could end up doing @@ -1188,17 +1189,17 @@ main (int argc, char **argv) int fdflags; device_name = file_name; if (fd_reopen (STDIN_FILENO, device_name, O_RDONLY | O_NONBLOCK, 0) < 0) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); if ((fdflags = fcntl (STDIN_FILENO, F_GETFL)) == -1 || fcntl (STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) - error (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"), - quotef (device_name)); + die (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"), + quotef (device_name)); } else device_name = _("standard input"); if (tcgetattr (STDIN_FILENO, &mode)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); if (verbose_output || recoverable_output || noargs) { @@ -1304,8 +1305,8 @@ main (int argc, char **argv) if (ioctl (STDIN_FILENO, TIOCEXT, &val) != 0) { - error (EXIT_FAILURE, errno, _("%s: error setting %s"), - quotef_n (0, device_name), quote_n (1, arg)); + die (EXIT_FAILURE, errno, _("%s: error setting %s"), + quotef_n (0, device_name), quote_n (1, arg)); } } #endif @@ -1386,7 +1387,7 @@ main (int argc, char **argv) static struct termios new_mode; if (tcsetattr (STDIN_FILENO, tcsetattr_options, &mode)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); /* POSIX (according to Zlotnick's book) tcsetattr returns zero if it performs *any* of the requested operations. This means it @@ -1396,7 +1397,7 @@ main (int argc, char **argv) compare them to the requested ones. */ if (tcgetattr (STDIN_FILENO, &new_mode)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); /* Normally, one shouldn't use memcmp to compare structures that may have 'holes' containing uninitialized data, but we have been @@ -1421,9 +1422,9 @@ main (int argc, char **argv) if (speed_was_set || memcmp (&mode, &new_mode, sizeof (mode)) != 0) #endif { - error (EXIT_FAILURE, 0, - _("%s: unable to perform all requested operations"), - quotef (device_name)); + die (EXIT_FAILURE, 0, + _("%s: unable to perform all requested operations"), + quotef (device_name)); #ifdef TESTING { size_t i; @@ -1703,7 +1704,7 @@ set_window_size (int rows, int cols, char const *device_name) if (get_win_size (STDIN_FILENO, &win)) { if (errno != EINVAL) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); memset (&win, 0, sizeof (win)); } @@ -1745,16 +1746,16 @@ set_window_size (int rows, int cols, char const *device_name) win.ws_col = 1; if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); if (ioctl (STDIN_FILENO, TIOCSSIZE, (char *) &ttysz)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); return; } # endif if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win)) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); } static void @@ -1765,11 +1766,11 @@ display_window_size (bool fancy, char const *device_name) if (get_win_size (STDIN_FILENO, &win)) { if (errno != EINVAL) - error (EXIT_FAILURE, errno, "%s", quotef (device_name)); + die (EXIT_FAILURE, errno, "%s", quotef (device_name)); if (!fancy) - error (EXIT_FAILURE, 0, - _("%s: no size information for this device"), - quotef (device_name)); + die (EXIT_FAILURE, 0, + _("%s: no size information for this device"), + quotef (device_name)); } else { -- cgit v1.2.3-54-g00ecf