#define RAW_NR_MINORS 8192
-int do_query;
-int do_query_all;
+static int do_query;
+static int do_query_all;
-int master_fd;
-int raw_minor;
+static int master_fd;
+static int raw_minor;
void open_raw_ctl(void);
static int query(int minor_raw, const char *raw_name, int quiet);
static int bind(int minor_raw, int block_major, int block_minor);
-static void __attribute__ ((__noreturn__)) usage(int err)
+static void __attribute__((__noreturn__)) usage(void)
{
- FILE *out = err == EXIT_SUCCESS ? stdout : stderr;
-
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %1$s %2$srawN <major> <minor>\n"
fputs(USAGE_OPTIONS, out);
fputs(_(" -q, --query set query mode\n"), out);
fputs(_(" -a, --all query all raw devices\n"), out);
- fputs(USAGE_HELP, out);
- fputs(USAGE_VERSION, out);
- fprintf(out, USAGE_MAN_TAIL("raw(8)"));
- exit(err);
+ printf(USAGE_HELP_OPTIONS(16));
+ printf(USAGE_MAN_TAIL("raw(8)"));
+ exit(EXIT_SUCCESS);
}
static long strtol_octal_or_err(const char *str, const char *errmesg)
struct stat statbuf;
static const struct option longopts[] = {
- {"query", no_argument, 0, 'q'},
- {"all", no_argument, 0, 'a'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, 'h'},
- {NULL, no_argument, 0, '0'},
+ {"query", no_argument, NULL, 'q'},
+ {"all", no_argument, NULL, 'a'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, '0'},
};
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
while ((c = getopt_long(argc, argv, "qaVh", longopts, NULL)) != -1)
switch (c) {
do_query_all = 1;
break;
case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
+ print_version(EXIT_SUCCESS);
case 'h':
- usage(EXIT_SUCCESS);
+ usage();
default:
errtryhelp(EXIT_FAILURE);
}
open_raw_ctl();
if (do_query_all) {
- if (optind < argc)
- usage(EXIT_FAILURE);
+ if (optind < argc) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
for (i = 1; i < RAW_NR_MINORS; i++)
query(i, NULL, 1);
exit(EXIT_SUCCESS);
* It's a bind or a single query. Either way we need a raw device.
*/
- if (optind >= argc)
- usage(EXIT_FAILURE);
+ if (optind >= argc) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
raw_name = argv[optind++];
/*
* causes udev to *remove* /dev/rawctl
*/
rc = sscanf(raw_name, _PATH_RAWDEVDIR "raw%d", &raw_minor);
- if (rc != 1)
- usage(EXIT_FAILURE);
-
+ if (rc != 1) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
if (raw_minor == 0)
errx(EXIT_RAW_ACCESS,
_("Device '%s' is the control raw device "
break;
default:
- usage(EXIT_FAILURE);
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
}
return bind(raw_minor, block_major, block_minor);