#include "swapprober.h"
#include "swapon-common.h"
-#ifndef SWAPON_HAS_TWO_ARGS
-/* libc is insane, let's call the kernel */
+#if !defined(HAVE_SWAPOFF) && defined(SYS_swapoff)
# include <sys/syscall.h>
# define swapoff(path) syscall(SYS_swapoff, path)
#endif
return special ? do_swapoff(special, quiet, CANONIC) : cannot_find(value);
}
-static void __attribute__ ((__noreturn__)) usage(FILE * out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out, _(" %s [options] [<spec>]\n"), program_invocation_short_name);
" -v, --verbose verbose mode\n"), out);
fputs(USAGE_SEPARATOR, out);
- fputs(USAGE_HELP, out);
- fputs(USAGE_VERSION, out);
+ printf(USAGE_HELP_OPTIONS(24));
fputs(_("\nThe <spec> parameter:\n" \
" -L <label> LABEL of device to be used\n" \
" <device> name of device to be used\n" \
" <file> name of file to be used\n"), out);
- fprintf(out, USAGE_MAN_TAIL("swapoff(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ printf(USAGE_MAN_TAIL("swapoff(8)"));
+ exit(EXIT_SUCCESS);
}
static int swapoff_all(void)
size_t i;
static const struct option long_opts[] = {
- { "all", 0, 0, 'a' },
- { "help", 0, 0, 'h' },
- { "verbose", 0, 0, 'v' },
- { "version", 0, 0, 'V' },
- { NULL, 0, 0, 0 }
+ { "all", no_argument, NULL, 'a' },
+ { "help", no_argument, NULL, 'h' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, NULL, 0 }
};
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
while ((c = getopt_long(argc, argv, "ahvVL:U:",
long_opts, NULL)) != -1) {
case 'a': /* all */
++all;
break;
- case 'h': /* help */
- usage(stdout);
- break;
case 'v': /* be chatty */
++verbose;
break;
- case 'V': /* version */
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
case 'L':
add_label(optarg);
break;
case 'U':
add_uuid(optarg);
break;
+
+ case 'h': /* help */
+ usage();
+ case 'V': /* version */
+ print_version(EXIT_SUCCESS);
default:
errtryhelp(EXIT_FAILURE);
}
}
argv += optind;
- if (!all && !numof_labels() && !numof_uuids() && *argv == NULL)
- usage(stderr);
+ if (!all && !numof_labels() && !numof_uuids() && *argv == NULL) {
+ warnx(_("bad usage"));
+ errtryhelp(EXIT_FAILURE);
+ }
mnt_init_debug(0);
mntcache = mnt_new_cache();