summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/cut.c68
-rw-r--r--coreutils/date.c65
-rw-r--r--coreutils/dd.c4
-rw-r--r--coreutils/df.c32
-rw-r--r--coreutils/du.c93
-rw-r--r--coreutils/env.c17
-rw-r--r--coreutils/mkdir.c26
-rw-r--r--coreutils/mv.c36
-rw-r--r--coreutils/rm.c22
-rw-r--r--coreutils/stty.c71
-rw-r--r--coreutils/test.c6
11 files changed, 199 insertions, 241 deletions
diff --git a/coreutils/cut.c b/coreutils/cut.c
index c24cf66..8ae762f 100644
--- a/coreutils/cut.c
+++ b/coreutils/cut.c
@@ -22,20 +22,22 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h> /* getopt */
+#include <getopt.h>
+#include <unistd.h>
#include <string.h>
#include <limits.h>
#include "busybox.h"
-/* globals from other files */
-extern int optind;
-extern char *optarg;
-
-
/* option vars */
-static char part = 0; /* (b)yte, (c)har, (f)ields */
-static unsigned int supress_non_delimited_lines = 0;
+static const char optstring[] = "b:c:f:d:sn";
+#define OPT_BYTE_FLGS 1
+#define OPT_CHAR_FLGS 2
+#define OPT_FIELDS_FLGS 4
+#define OPT_DELIM_FLGS 8
+#define OPT_SUPRESS_FLGS 16
+static char part; /* (b)yte, (c)har, (f)ields */
+static unsigned int supress_non_delimited_lines;
static char delim = '\t'; /* delimiter, default is tab */
struct cut_list {
@@ -270,11 +272,11 @@ static void cut_file(FILE *file)
while ((line = bb_get_chomped_line_from_file(file)) != NULL) {
/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
- if (part == 'c' || part == 'b')
+ if ((part & (OPT_CHAR_FLGS | OPT_BYTE_FLGS)))
cut_line_by_chars(line);
/* cut based on fields */
- else if (part == 'f') {
+ else {
if (delim == '\n')
cut_file_by_lines(line, linenum);
else
@@ -289,46 +291,32 @@ static void cut_file(FILE *file)
extern int cut_main(int argc, char **argv)
{
- int opt;
-
- while ((opt = getopt(argc, argv, "b:c:d:f:ns")) > 0) {
- switch (opt) {
- case 'b':
- case 'c':
- case 'f':
- /* make sure they didn't ask for two types of lists */
- if (part != 0) {
+ unsigned long opt;
+ char *sopt, *sdopt;
+
+ bb_opt_complementaly = "b~bcf:c~bcf:f~bcf";
+ opt = bb_getopt_ulflags(argc, argv, optstring, &sopt, &sopt, &sopt, &sdopt);
+ part = opt & (OPT_BYTE_FLGS|OPT_CHAR_FLGS|OPT_FIELDS_FLGS);
+ if(part == 0)
+ bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
+ if(opt & 0x80000000UL)
bb_error_msg_and_die("only one type of list may be specified");
- }
- part = (char)opt;
- parse_lists(optarg);
- break;
- case 'd':
- if (strlen(optarg) > 1) {
+ parse_lists(sopt);
+ if((opt & (OPT_DELIM_FLGS))) {
+ if (strlen(sdopt) > 1) {
bb_error_msg_and_die("the delimiter must be a single character");
}
- delim = optarg[0];
- break;
- case 'n':
- /* no-op */
- break;
- case 's':
- supress_non_delimited_lines++;
- break;
- }
- }
-
- if (part == 0) {
- bb_error_msg_and_die("you must specify a list of bytes, characters, or fields");
+ delim = sdopt[0];
}
+ supress_non_delimited_lines = opt & OPT_SUPRESS_FLGS;
/* non-field (char or byte) cutting has some special handling */
- if (part != 'f') {
+ if (part != OPT_FIELDS_FLGS) {
if (supress_non_delimited_lines) {
bb_error_msg_and_die("suppressing non-delimited lines makes sense"
" only when operating on fields");
}
- if (delim != '\t' && part != 'f') {
+ if (delim != '\t') {
bb_error_msg_and_die("a delimiter may be specified only when operating on fields");
}
}
diff --git a/coreutils/date.c b/coreutils/date.c
index afbedb9..6e7aa1f 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -120,74 +120,65 @@ int date_main(int argc, char **argv)
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
- int c;
- int set_time = 0;
- int rfc822 = 0;
- int utc = 0;
+ int set_time;
+ int rfc822;
+ int utc;
int use_arg = 0;
time_t tm;
+ unsigned long opt;
struct tm tm_time;
#ifdef CONFIG_FEATURE_DATE_ISOFMT
int ifmt = 0;
+ char *isofmt_arg;
# define GETOPT_ISOFMT "I::"
#else
# define GETOPT_ISOFMT
#endif
-
- /* Interpret command line args */
- while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) {
- switch (c) {
- case 'R':
- rfc822 = 1;
- break;
- case 's':
- set_time = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
- bb_show_usage();
- }
- break;
- case 'u':
- utc = 1;
+ bb_opt_complementaly = "d~ds:s~ds";
+ opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
+ &date_str, &date_str
+#ifdef CONFIG_FEATURE_DATE_ISOFMT
+ , &isofmt_arg
+#endif
+ );
+ rfc822 = opt & 1;
+ set_time = opt & 2;
+ utc = opt & 4;
+ if(utc) {
if (putenv("TZ=UTC0") != 0)
bb_error_msg_and_die(bb_msg_memory_exhausted);
- break;
- case 'd':
- use_arg = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL))
+ }
+ use_arg = opt & 8;
+ if(opt & 0x80000000UL)
bb_show_usage();
- break;
#ifdef CONFIG_FEATURE_DATE_ISOFMT
- case 'I':
- if (!optarg)
+ if(opt & 16) {
+ if (!isofmt_arg)
ifmt = 1;
else {
- int ifmt_len = bb_strlen(optarg);
+ int ifmt_len = bb_strlen(isofmt_arg);
if ((ifmt_len <= 4)
- && (strncmp(optarg, "date", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
ifmt = 1;
} else if ((ifmt_len <= 5)
- && (strncmp(optarg, "hours", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
ifmt = 2;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "minutes", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
ifmt = 3;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "seconds", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
ifmt = 4;
}
}
- if (ifmt) {
- break; /* else bb_show_usage(); */
- }
-#endif
- default:
+ if (!ifmt) {
bb_show_usage();
}
}
-
+#endif
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
date_fmt = &argv[optind][1]; /* Skip over the '+' */
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 1150861..cd97b24 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -106,9 +106,7 @@ int dd_main(int argc, char **argv)
buf = xmalloc(bs);
if (infile != NULL) {
- if ((ifd = open(infile, O_RDONLY)) < 0) {
- bb_perror_msg_and_die("%s", infile);
- }
+ ifd = bb_xopen(infile, O_RDONLY);
} else {
ifd = STDIN_FILENO;
infile = bb_msg_standard_input;
diff --git a/coreutils/df.c b/coreutils/df.c
index 708e12c..9673633 100644
--- a/coreutils/df.c
+++ b/coreutils/df.c
@@ -55,41 +55,27 @@ extern int df_main(int argc, char **argv)
unsigned long df_disp_hr = KILOBYTE;
#endif
int status = EXIT_SUCCESS;
- int opt;
+ unsigned long opt;
FILE *mount_table;
struct mntent *mount_entry;
struct statfs s;
static const char hdr_1k[] = "1k-blocks"; /* default display is kilobytes */
const char *disp_units_hdr = hdr_1k;
- while ((opt = getopt(argc, argv, "k"
#ifdef CONFIG_FEATURE_HUMAN_READABLE
- "hm"
-#endif
-)) > 0)
- {
- switch (opt) {
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- case 'h':
+ bb_opt_complementaly = "h-km:k-hm:m-hk";
+ opt = bb_getopt_ulflags(argc, argv, "hmk");
+ if(opt & 1) {
df_disp_hr = 0;
disp_units_hdr = " Size";
- break;
- case 'm':
+ }
+ if(opt & 2) {
df_disp_hr = MEGABYTE;
disp_units_hdr = "1M-blocks";
- break;
-#endif
- case 'k':
- /* default display is kilobytes */
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- df_disp_hr = KILOBYTE;
- disp_units_hdr = hdr_1k;
-#endif
- break;
- default:
- bb_show_usage();
- }
}
+#else
+ opt = bb_getopt_ulflags(argc, argv, "k");
+#endif
bb_printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
"", disp_units_hdr);
diff --git a/coreutils/du.c b/coreutils/du.c
index 1c16cfb..a9f6c28 100644
--- a/coreutils/du.c
+++ b/coreutils/du.c
@@ -166,8 +166,9 @@ int du_main(int argc, char **argv)
{
long total;
int slink_depth_save;
- int print_final_total = 0;
- int c;
+ int print_final_total;
+ char *smax_print_depth;
+ unsigned long opt;
#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
@@ -185,57 +186,57 @@ int du_main(int argc, char **argv)
* gnu du exits with an error code in this case. We choose to simply
* ignore -a. This is consistent with -s being equivalent to -d 0.
*/
-
- while ((c = getopt(argc, argv, "aHkLsx" "d:" "lc"
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- "hm"
-#endif
- )) > 0) {
- switch (c) {
- case 'a':
- print_files = INT_MAX;
- break;
- case 'H':
- slink_depth = 1;
- break;
- case 'k':
#ifdef CONFIG_FEATURE_HUMAN_READABLE
+ bb_opt_complementaly = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
+ if((opt & (1 << 9))) {
+ /* -h opt */
+ disp_hr = 0;
+ }
+ if((opt & (1 << 10))) {
+ /* -m opt */
+ disp_hr = MEGABYTE;
+ }
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_hr = KILOBYTE;
-#elif !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ }
+#else
+ bb_opt_complementaly = "H-L:L-H:s-d:d-s";
+ opt = bb_getopt_ulflags(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
+#if !defined CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K
+ if((opt & (1 << 2))) {
+ /* -k opt */
disp_k = 1;
+ }
+#endif
#endif
- break;
- case 'L':
+ if((opt & (1 << 0))) {
+ /* -a opt */
+ print_files = INT_MAX;
+ }
+ if((opt & (1 << 1))) {
+ /* -H opt */
+ slink_depth = 1;
+ }
+ if((opt & (1 << 3))) {
+ /* -L opt */
slink_depth = INT_MAX;
- break;
- case 's':
+ }
+ if((opt & (1 << 4))) {
+ /* -s opt */
max_print_depth = 0;
- break;
- case 'x':
- one_file_system = 1;
- break;
-
- case 'd':
- max_print_depth = bb_xgetularg10_bnd(optarg, 0, INT_MAX);
- break;
- case 'l':
- count_hardlinks = 1;
- break;
- case 'c':
- print_final_total = 1;
- break;
-#ifdef CONFIG_FEATURE_HUMAN_READABLE
- case 'h':
- disp_hr = 0;
- break;
- case 'm':
- disp_hr = MEGABYTE;
- break;
-#endif
- default:
- bb_show_usage();
}
+ one_file_system = opt & (1 << 5); /* -x opt */
+ if((opt & (1 << 6))) {
+ /* -d opt */
+ max_print_depth = bb_xgetularg10_bnd(smax_print_depth, 0, INT_MAX);
}
+ if((opt & (1 << 7))) {
+ /* -l opt */
+ count_hardlinks = 1;
+ }
+ print_final_total = opt & (1 << 8); /* -c opt */
/* go through remaining args (if any) */
argv += optind;
@@ -252,7 +253,9 @@ int du_main(int argc, char **argv)
total += du(*argv);
slink_depth = slink_depth_save;
} while (*++argv);
+#ifdef CONFIG_FEATURE_CLEAN_UP
reset_ino_dev_hashtable();
+#endif
if (print_final_total) {
print(total, "total");
diff --git a/coreutils/env.c b/coreutils/env.c
index db13b3a..eb761e9 100644
--- a/coreutils/env.c
+++ b/coreutils/env.c
@@ -44,20 +44,13 @@ extern int env_main(int argc, char** argv)
{
char **ep, *p;
char *cleanenv[1] = { NULL };
- int ch;
+ unsigned long opt;
- while ((ch = getopt(argc, argv, "iu:")) > 0) {
- switch(ch) {
- case 'i':
+ opt = bb_getopt_ulflags(argc, argv, "iu:", &p);
+ if(opt & 1)
environ = cleanenv;
- break;
- case 'u':
- unsetenv(optarg);
- break;
- default:
- bb_show_usage();
- }
- }
+ if(opt & 2)
+ unsetenv(p);
argv += optind;
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index b018ac1..50364f1 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -31,27 +31,33 @@
#include <stdlib.h>
#include <unistd.h>
+#include <getopt.h>
#include "busybox.h"
+static const struct option mkdir_long_options[] = {
+ { "mode", 1, NULL, 'm' },
+ { "parents", 0, NULL, 'p' },
+ { 0, 0, 0, 0 }
+};
+
extern int mkdir_main (int argc, char **argv)
{
mode_t mode = (mode_t)(-1);
int status = EXIT_SUCCESS;
int flags = 0;
- int opt;
+ unsigned long opt;
+ char *smode;
- while ((opt = getopt (argc, argv, "m:p")) > 0) {
- if (opt == 'm') {
+ bb_applet_long_options = mkdir_long_options;
+ opt = bb_getopt_ulflags(argc, argv, "m:p", &smode);
+ if(opt & 1) {
mode = 0777;
- if (!bb_parse_mode (optarg, &mode)) {
- bb_error_msg_and_die ("invalid mode `%s'", optarg);
- }
- } else if (opt == 'p') {
- flags |= FILEUTILS_RECUR;
- } else {
- bb_show_usage();
+ if (!bb_parse_mode (smode, &mode)) {
+ bb_error_msg_and_die ("invalid mode `%s'", smode);
}
}
+ if(opt & 2)
+ flags |= FILEUTILS_RECUR;
if (optind == argc) {
bb_show_usage();
diff --git a/coreutils/mv.c b/coreutils/mv.c
index ae0ee92..55da2cc 100644
--- a/coreutils/mv.c
+++ b/coreutils/mv.c
@@ -31,10 +31,21 @@
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
+#include <getopt.h>
#include "busybox.h"
#include "libcoreutils/coreutils.h"
-static const char *fmt = "cannot overwrite %sdirectory with %sdirectory";
+static const struct option mv_long_options[] = {
+ { "interactive", 0, NULL, 'i' },
+ { "force", 0, NULL, 'f' },
+ { 0, 0, 0, 0 }
+};
+
+static const char mv_getopt_short_option[] = "fi";
+#define OPT_FILEUTILS_FORCE 1
+#define OPT_FILEUTILS_INTERACTIVE 2
+
+static const char fmt[] = "cannot overwrite %sdirectory with %sdirectory";
extern int mv_main(int argc, char **argv)
{
@@ -44,20 +55,12 @@ extern int mv_main(int argc, char **argv)
const char *dest;
int dest_exists;
int source_exists;
- int opt;
- int flags = 0;
+ unsigned long flags;
int status = 0;
- while ((opt = getopt(argc, argv, "fi")) > 0) {
- flags &= ~(FILEUTILS_INTERACTIVE | FILEUTILS_FORCE);
- if (opt == 'i') {
- flags |= FILEUTILS_INTERACTIVE;
- } else if (opt == 'f') {
- flags |= FILEUTILS_FORCE;
- } else {
- bb_show_usage();
- }
- }
+ bb_applet_long_options = mv_long_options;
+ bb_opt_complementaly = "f-i:i-f";
+ flags = bb_getopt_ulflags(argc, argv, mv_getopt_short_option);
if (optind + 2 > argc)
bb_show_usage();
@@ -77,8 +80,7 @@ extern int mv_main(int argc, char **argv)
}
do {
- dest = concat_path_file(last,
- bb_get_last_path_component(*argv));
+ dest = concat_path_file(last, bb_get_last_path_component(*argv));
if ((dest_exists = cp_mv_stat(dest, &dest_stat)) < 0) {
goto RET_1;
@@ -86,9 +88,9 @@ extern int mv_main(int argc, char **argv)
DO_MOVE:
- if (dest_exists && !(flags & FILEUTILS_FORCE) &&
+ if (dest_exists && !(flags & OPT_FILEUTILS_FORCE) &&
((access(dest, W_OK) < 0 && isatty(0)) ||
- (flags & FILEUTILS_INTERACTIVE))) {
+ (flags & OPT_FILEUTILS_INTERACTIVE))) {
if (fprintf(stderr, "mv: overwrite `%s'? ", dest) < 0) {
goto RET_1; /* Ouch! fprintf failed! */
}
diff --git a/coreutils/rm.c b/coreutils/rm.c
index 5489350..39609e7 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -36,22 +36,16 @@ extern int rm_main(int argc, char **argv)
{
int status = 0;
int flags = 0;
- int opt;
+ unsigned long opt;
- while ((opt = getopt(argc, argv, "fiRr")) > 0) {
- if ((opt == 'r') || (opt == 'R')) {
- flags |= FILEUTILS_RECUR;
- } else {
- flags &= ~(FILEUTILS_INTERACTIVE | FILEUTILS_FORCE);
- if (opt == 'i') {
- flags |= FILEUTILS_INTERACTIVE;
- } else if (opt == 'f') {
+ bb_opt_complementaly = "f-i:i-f";
+ opt = bb_getopt_ulflags(argc, argv, "fiRr");
+ if(opt & 1)
flags |= FILEUTILS_FORCE;
- } else {
- bb_show_usage();
- }
- }
- }
+ if(opt & 2)
+ flags |= FILEUTILS_INTERACTIVE;
+ if(opt & 12)
+ flags |= FILEUTILS_RECUR;
if (*(argv += optind) != NULL) {
do {
diff --git a/coreutils/stty.c b/coreutils/stty.c
index a3a98d9..bd3a369 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -414,22 +414,25 @@ static int set_mode(const struct mode_info *info,
int reversed, struct termios *mode);
static speed_t string_to_baud(const char *arg);
static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode);
-static void display_all(struct termios *mode, int fd,
- const char *device_name);
-static void display_changed(struct termios *mode, int fd,
- const char *device_name);
-static void display_recoverable(struct termios *mode, int fd,
- const char *device_name);
+static void display_all(struct termios *mode, int fd);
+static void display_changed(struct termios *mode, int fd);
+static void display_recoverable(struct termios *mode, int fd);
static void display_speed(struct termios *mode, int fancy);
-static void display_window_size(int fancy, int fd,
- const char *device_name);
+static void display_window_size(int fancy, int fd);
static void sane_mode(struct termios *mode);
static void set_control_char(const struct control_info *info,
const char *arg, struct termios *mode);
static void set_speed(enum speed_setting type,
const char *arg, struct termios *mode);
-static void set_window_size(int rows, int cols, int fd,
- const char *device_name);
+static void set_window_size(int rows, int cols, int fd);
+
+static const char *device_name;
+
+static __attribute__ ((noreturn)) void perror_on_device(const char *fmt)
+{
+ bb_perror_msg_and_die(fmt, device_name);
+}
+
/* The width of the screen, for output wrapping. */
static int max_col;
@@ -477,7 +480,7 @@ extern int main(int argc, char **argv)
#endif
{
struct termios mode;
- void (*output_func)(struct termios *, int, const char *);
+ void (*output_func)(struct termios *, int);
int optc;
int require_set_attr;
int speed_was_set;
@@ -487,7 +490,7 @@ extern int main(int argc, char **argv)
int noargs = 1;
char * file_name = NULL;
int fd;
- const char *device_name;
+
output_func = display_changed;
verbose_output = 0;
@@ -543,13 +546,10 @@ extern int main(int argc, char **argv)
int fdflags;
device_name = file_name;
- fd = open(device_name, O_RDONLY | O_NONBLOCK);
- if (fd < 0)
- bb_perror_msg_and_die("%s", device_name);
+ fd = bb_xopen(device_name, O_RDONLY | O_NONBLOCK);
if ((fdflags = fcntl(fd, F_GETFL)) == -1
|| fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
- bb_perror_msg_and_die("%s: couldn't reset non-blocking mode",
- device_name);
+ perror_on_device("%s: couldn't reset non-blocking mode");
} else {
fd = 0;
device_name = bb_msg_standard_input;
@@ -559,12 +559,12 @@ extern int main(int argc, char **argv)
spurious difference in an uninitialized portion of the structure. */
memset(&mode, 0, sizeof(mode));
if (tcgetattr(fd, &mode))
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
if (verbose_output | recoverable_output | noargs) {
max_col = screen_columns();
current_col = 0;
- output_func(&mode, fd, device_name);
+ output_func(&mode, fd);
return EXIT_SUCCESS;
}
@@ -644,18 +644,18 @@ extern int main(int argc, char **argv)
bb_error_msg_and_die("missing argument to `%s'", argv[k]);
++k;
set_window_size((int) bb_xparse_number(argv[k], stty_suffixes),
- -1, fd, device_name);
+ -1, fd);
} else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) {
if (k == argc - 1)
bb_error_msg_and_die("missing argument to `%s'", argv[k]);
++k;
set_window_size(-1,
(int) bb_xparse_number(argv[k], stty_suffixes),
- fd, device_name);
+ fd);
} else if (STREQ(argv[k], "size")) {
max_col = screen_columns();
current_col = 0;
- display_window_size(0, fd, device_name);
+ display_window_size(0, fd);
}
#endif
#ifdef HAVE_C_LINE
@@ -685,7 +685,7 @@ extern int main(int argc, char **argv)
struct termios new_mode;
if (tcsetattr(fd, TCSADRAIN, &mode))
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
/* POSIX (according to Zlotnick's book) tcsetattr returns zero if
it performs *any* of the requested operations. This means it
@@ -698,7 +698,7 @@ extern int main(int argc, char **argv)
spurious difference in an uninitialized portion of the structure. */
memset(&new_mode, 0, sizeof(new_mode));
if (tcgetattr(fd, &new_mode))
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
/* Normally, one shouldn't use memcmp to compare structures that
may have `holes' containing uninitialized data, but we have been
@@ -721,8 +721,7 @@ extern int main(int argc, char **argv)
new_mode.c_cflag &= (~CIBAUD);
if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
#endif
- bb_error_msg_and_die ("%s: unable to perform all requested operations",
- device_name);
+ perror_on_device ("%s: unable to perform all requested operations");
}
}
@@ -948,13 +947,13 @@ static int get_win_size(int fd, struct winsize *win)
}
static void
-set_window_size(int rows, int cols, int fd, const char *device_name)
+set_window_size(int rows, int cols, int fd)
{
struct winsize win;
if (get_win_size(fd, &win)) {
if (errno != EINVAL)
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
memset(&win, 0, sizeof(win));
}
@@ -980,23 +979,23 @@ set_window_size(int rows, int cols, int fd, const char *device_name)
if ((ioctl(fd, TIOCSWINSZ, (char *) &win) != 0)
|| (ioctl(fd, TIOCSSIZE, (char *) &ttysz) != 0)) {
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
return;
}
# endif
if (ioctl(fd, TIOCSWINSZ, (char *) &win))
- bb_perror_msg_and_die("%s", device_name);
+ perror_on_device("%s");
}
-static void display_window_size(int fancy, int fd, const char *device_name)
+static void display_window_size(int fancy, int fd)
{
const char *fmt_str = "%s" "\0" "%s: no size information for this device";
struct winsize win;
if (get_win_size(fd, &win)) {
if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) {
- bb_perror_msg_and_die(fmt_str, device_name);
+ perror_on_device(fmt_str);
}
} else {
wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n",
@@ -1047,7 +1046,7 @@ static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode)
return NULL;
}
-static void display_changed(struct termios *mode, int fd, const char *device_name)
+static void display_changed(struct termios *mode, int fd)
{
int i;
int empty_line;
@@ -1122,7 +1121,7 @@ static void display_changed(struct termios *mode, int fd, const char *device_nam
}
static void
-display_all(struct termios *mode, int fd, const char *device_name)
+display_all(struct termios *mode, int fd)
{
int i;
tcflag_t *bitsp;
@@ -1131,7 +1130,7 @@ display_all(struct termios *mode, int fd, const char *device_name)
display_speed(mode, 1);
#ifdef TIOCGWINSZ
- display_window_size(1, fd, device_name);
+ display_window_size(1, fd);
#endif
#ifdef HAVE_C_LINE
wrapf("line = %d;", mode->c_line);
@@ -1202,7 +1201,7 @@ static void display_speed(struct termios *mode, int fancy)
current_col = 0;
}
-static void display_recoverable(struct termios *mode, int fd, const char *device_name)
+static void display_recoverable(struct termios *mode, int fd)
{
int i;
diff --git a/coreutils/test.c b/coreutils/test.c
index 0bce66e..31ac87f 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -452,10 +452,8 @@ static int getn(const char *s)
if (errno != 0)
bb_error_msg_and_die("%s: out of range", s);
- while (isspace(*p))
- p++;
-
- if (*p)
+ /* p = bb_skip_whitespace(p); avoid const warning */
+ if (*(bb_skip_whitespace(p)))
bb_error_msg_and_die("%s: bad number", s);
return (int) r;