aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2020-08-07 13:29:43 +0200
committerCorinna Vinschen <corinna@vinschen.de>2020-08-07 15:09:56 +0200
commite7fca6f867f441aaf54061545b297a62ce93708f (patch)
treeb36ba6baec69f39ef26d2ed8502fadca721d96fb /winsup
parent9beb7b977162bd576da325ce8e23152e70989f78 (diff)
downloadnewlib-e7fca6f867f441aaf54061545b297a62ce93708f.zip
newlib-e7fca6f867f441aaf54061545b297a62ce93708f.tar.gz
newlib-e7fca6f867f441aaf54061545b297a62ce93708f.tar.bz2
Cygwin: utils: convert usage() to proper noreturn function throughout
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/utils/chattr.c9
-rw-r--r--winsup/utils/cygcheck.cc4
-rw-r--r--winsup/utils/cygpath.cc3
-rw-r--r--winsup/utils/dumper.cc2
-rw-r--r--winsup/utils/getconf.c2
-rw-r--r--winsup/utils/getfacl.c10
-rw-r--r--winsup/utils/kill.cc2
-rw-r--r--winsup/utils/ldd.cc4
-rw-r--r--winsup/utils/locale.cc4
-rw-r--r--winsup/utils/lsattr.c5
-rw-r--r--winsup/utils/minidumper.cc2
-rw-r--r--winsup/utils/mkgroup.c5
-rw-r--r--winsup/utils/mkpasswd.c5
-rw-r--r--winsup/utils/mount.cc2
-rw-r--r--winsup/utils/passwd.c3
-rw-r--r--winsup/utils/ps.cc2
-rw-r--r--winsup/utils/regtool.cc24
-rw-r--r--winsup/utils/setfacl.c44
-rw-r--r--winsup/utils/setmetamode.c16
-rw-r--r--winsup/utils/ssp.c3
-rw-r--r--winsup/utils/strace.cc4
-rw-r--r--winsup/utils/tzset.c9
-rw-r--r--winsup/utils/umount.cc2
23 files changed, 55 insertions, 111 deletions
diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c
index c21d4b7..98f693a 100644
--- a/winsup/utils/chattr.c
+++ b/winsup/utils/chattr.c
@@ -224,7 +224,7 @@ print_version ()
strrchr (__DATE__, ' ') + 1);
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream)
{
fprintf (stream, "Usage: %s [-RVfhv] [+-=mode]... [file]...\n",
@@ -264,6 +264,7 @@ usage (FILE *stream)
" 'C', 'Casesensitive': directory is handled case sensitive\n"
" (Windows 10 1803 or later, local NTFS only,\n"
" WSL must be installed)\n");
+ exit (stream == stdout ? 0 : 1);
}
int
@@ -303,7 +304,6 @@ main (int argc, char **argv)
/*FALLTHRU*/
case 'h':
usage (c == 'h' ? stdout : stderr);
- return 1;
}
}
next:
@@ -318,10 +318,7 @@ next:
if (!opt)
break;
if (argv[optind][1] == '\0' || get_flags (argv[optind]))
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
++optind;
}
if (sanity_check ())
diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc
index 2cc25d9..a45ab5d 100644
--- a/winsup/utils/cygcheck.cc
+++ b/winsup/utils/cygcheck.cc
@@ -62,8 +62,6 @@ void package_find (int, char **);
void package_list (int, char **);
/* In bloda.cc */
void dump_dodgy_apps (int verbose);
-/* Forward declaration */
-static void usage (FILE *, int);
static const char *known_env_vars[] = {
"c_include_path",
@@ -2110,7 +2108,7 @@ package_grep (char *search)
return 0;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream, int status)
{
fprintf (stream, "\
diff --git a/winsup/utils/cygpath.cc b/winsup/utils/cygpath.cc
index bf77bb2..aa9df3a 100644
--- a/winsup/utils/cygpath.cc
+++ b/winsup/utils/cygpath.cc
@@ -76,7 +76,7 @@ static struct option long_options[] = {
static char options[] = "ac:df:hilmMopst:uUVwAC:DHOPSWF:";
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream, int status)
{
if (!ignore_flag || !status)
@@ -971,7 +971,6 @@ do_options (int argc, char **argv, int from_file)
case 'h':
usage (stdout, 0);
- break;
case 'V':
print_version ();
diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc
index 5f8121a..25fd080 100644
--- a/winsup/utils/dumper.cc
+++ b/winsup/utils/dumper.cc
@@ -948,7 +948,7 @@ dumper::write_core_dump ()
return 1;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream, int status)
{
fprintf (stream, "\
diff --git a/winsup/utils/getconf.c b/winsup/utils/getconf.c
index 5ac84ab..bc37bfb 100644
--- a/winsup/utils/getconf.c
+++ b/winsup/utils/getconf.c
@@ -501,7 +501,7 @@ printvar (const struct conf_variable *cp, const char *pathname)
}
}
-static void
+static void __attribute__ ((__noreturn__))
usage (int ret)
{
fprintf (ret ? stderr : stdout,
diff --git a/winsup/utils/getfacl.c b/winsup/utils/getfacl.c
index a6fac97..5a3730b 100644
--- a/winsup/utils/getfacl.c
+++ b/winsup/utils/getfacl.c
@@ -11,6 +11,7 @@ details. */
#include <pwd.h>
#include <grp.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/acl.h>
@@ -48,7 +49,7 @@ groupname (gid_t gid)
return gbuf;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream)
{
fprintf (stream, "Usage: %s [-adn] FILE [FILE2...]\n"
@@ -97,6 +98,7 @@ usage (FILE * stream)
" default:other::perm\n"
"\n");
}
+ exit (stream == stdout ? 0 : 1);
}
struct option longopts[] = {
@@ -165,7 +167,6 @@ main (int argc, char **argv)
break;
case 'h':
usage (stdout);
- return 0;
case 'n':
nopt = 1;
break;
@@ -177,10 +178,7 @@ main (int argc, char **argv)
return 1;
}
if (optind > argc - 1)
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (nopt)
options |= TEXT_NUMERIC_IDS;
if (eopt > 0)
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
index a22d702..d0fb547 100644
--- a/winsup/utils/kill.cc
+++ b/winsup/utils/kill.cc
@@ -33,7 +33,7 @@ static struct option longopts[] =
static char opts[] = "hl::fs:WV";
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where , ""
diff --git a/winsup/utils/ldd.cc b/winsup/utils/ldd.cc
index a74054f..e1af99e 100644
--- a/winsup/utils/ldd.cc
+++ b/winsup/utils/ldd.cc
@@ -69,7 +69,7 @@ error (const char *fmt, ...)
exit (1);
}
-static void
+static void __attribute__ ((__noreturn__))
usage ()
{
printf ("Usage: %s [OPTION]... FILE...\n\
@@ -85,6 +85,7 @@ Print shared library dependencies\n\
-v, --verbose print all information\n\
(currently unimplemented)\n",
program_invocation_short_name);
+ exit (0);
}
static void
@@ -444,7 +445,6 @@ main (int argc, char **argv)
exit (1);
case 'h':
usage ();
- exit (0);
case 'V':
print_version ();
return 0;
diff --git a/winsup/utils/locale.cc b/winsup/utils/locale.cc
index 1cd0433..1eee9d2 100644
--- a/winsup/utils/locale.cc
+++ b/winsup/utils/locale.cc
@@ -42,7 +42,7 @@
#define LOCALE_ALIAS "/usr/share/locale/locale.alias"
#define LOCALE_ALIAS_LINE_LEN 255
-void
+static void __attribute__ ((__noreturn__))
usage ()
{
printf (
@@ -78,6 +78,7 @@ usage ()
" -h, --help This text\n"
" -V, --version Print program version and exit\n\n",
program_invocation_short_name);
+ exit (0);
}
void
@@ -811,7 +812,6 @@ main (int argc, char **argv)
break;
case 'h':
usage ();
- return 0;
case 'V':
print_version ();
return 0;
diff --git a/winsup/utils/lsattr.c b/winsup/utils/lsattr.c
index ee72043..7002280 100644
--- a/winsup/utils/lsattr.c
+++ b/winsup/utils/lsattr.c
@@ -180,7 +180,7 @@ print_version ()
strrchr (__DATE__, ' ') + 1);
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream)
{
fprintf (stream, "Usage: %s [-RVadhln] [file]...\n",
@@ -221,6 +221,7 @@ usage (FILE *stream)
" 'C', 'Casesensitive': directory is handled case sensitive\n"
" (Windows 10 1803 or later, local NTFS only,\n"
" WSL must be installed)\n");
+ exit (stream == stdout ? 0 : 1);
}
int
@@ -254,7 +255,7 @@ main (int argc, char **argv)
case 'h':
default:
usage (c == 'h' ? stdout : stderr);
- return 1;
+ break;
}
}
if (optind > argc - 1)
diff --git a/winsup/utils/minidumper.cc b/winsup/utils/minidumper.cc
index bc46358..9331b73 100644
--- a/winsup/utils/minidumper.cc
+++ b/winsup/utils/minidumper.cc
@@ -134,7 +134,7 @@ minidump(DWORD pid, MINIDUMP_TYPE dump_type, const char *minidump_file)
CloseHandle(dump_file);
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream, int status)
{
fprintf (stream, "\
diff --git a/winsup/utils/mkgroup.c b/winsup/utils/mkgroup.c
index fc36e27..3e99438 100644
--- a/winsup/utils/mkgroup.c
+++ b/winsup/utils/mkgroup.c
@@ -471,7 +471,7 @@ enum_groups (domlist_t *mach, const char *sep, DWORD id_offset,
while (rc == ERROR_MORE_DATA);
}
-static int
+static int __attribute__ ((__noreturn__))
usage (FILE * stream)
{
fprintf (stream,
@@ -510,7 +510,7 @@ usage (FILE * stream)
"groups on domain controllers and domain member machines.\n"
"\n", program_invocation_short_name,
(const char *) cygwin_internal (CW_GETNSSSEP));
- return 1;
+ exit (0);
}
struct option longopts[] = {
@@ -703,7 +703,6 @@ main (int argc, char **argv)
break;
case 'h':
usage (stdout);
- return 0;
case 'V':
print_version ();
return 0;
diff --git a/winsup/utils/mkpasswd.c b/winsup/utils/mkpasswd.c
index 9562eac..3bbdb1c 100644
--- a/winsup/utils/mkpasswd.c
+++ b/winsup/utils/mkpasswd.c
@@ -358,7 +358,7 @@ enum_users (domlist_t *mach, const char *sep, const char *passed_home_path,
return 0;
}
-static int
+static int __attribute__ ((__noreturn__))
usage (FILE * stream)
{
fprintf (stream,
@@ -399,7 +399,7 @@ usage (FILE * stream)
"on domain controllers and domain member machines.\n"
"\n", program_invocation_short_name,
(const char *) cygwin_internal (CW_GETNSSSEP));
- return 1;
+ exit (stream == stdout ? 0 : 1);
}
static struct option longopts[] = {
@@ -606,7 +606,6 @@ main (int argc, char **argv)
break;
case 'h':
usage (stdout);
- return 0;
case 'V':
print_version ();
return 0;
diff --git a/winsup/utils/mount.cc b/winsup/utils/mount.cc
index bd26751..a65a6e5 100644
--- a/winsup/utils/mount.cc
+++ b/winsup/utils/mount.cc
@@ -203,7 +203,7 @@ static struct option longopts[] =
static char opts[] = "acfhmpVo:";
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
char *options;
diff --git a/winsup/utils/passwd.c b/winsup/utils/passwd.c
index aa8e8cc..c3210e4 100644
--- a/winsup/utils/passwd.c
+++ b/winsup/utils/passwd.c
@@ -266,8 +266,7 @@ SetModals (int xarg, int narg, int iarg, int Larg, PCWSTR server)
return EvalRet (ret, NULL);
}
-static void usage (FILE * stream, int status) __attribute__ ((noreturn));
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream, int status)
{
fprintf (stream, ""
diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc
index 4d7a56d..f3eb9e8 100644
--- a/winsup/utils/ps.cc
+++ b/winsup/utils/ps.cc
@@ -103,7 +103,7 @@ ttynam (int ntty, char buf[9])
return buf;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream, int status)
{
fprintf (stream, "\
diff --git a/winsup/utils/regtool.cc b/winsup/utils/regtool.cc
index f91e61d..1697229 100644
--- a/winsup/utils/regtool.cc
+++ b/winsup/utils/regtool.cc
@@ -89,7 +89,7 @@ char **argv;
HKEY key;
wchar_t *value;
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where, ""
@@ -835,10 +835,7 @@ int
cmd_load ()
{
if (!argv[1])
- {
- usage ();
- return 1;
- }
+ usage ();
find_key (1, 0);
return 0;
}
@@ -847,10 +844,7 @@ int
cmd_unload ()
{
if (argv[1])
- {
- usage ();
- return 1;
- }
+ usage ();
find_key (1, 0);
return 0;
}
@@ -859,10 +853,7 @@ int
cmd_save ()
{
if (!argv[1])
- {
- usage ();
- return 1;
- }
+ usage ();
/* REG_OPTION_BACKUP_RESTORE is necessary to save /HKLM/SECURITY */
find_key (1, KEY_QUERY_VALUE, REG_OPTION_BACKUP_RESTORE);
ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, argv[1], NULL, 0);
@@ -880,10 +871,7 @@ int
cmd_restore ()
{
if (!argv[1])
- {
- usage ();
- return 1;
- }
+ usage ();
/* REG_OPTION_BACKUP_RESTORE is necessary to restore /HKLM/SECURITY */
find_key (1, KEY_ALL_ACCESS, REG_OPTION_BACKUP_RESTORE);
ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, argv[1], NULL, 0);
@@ -1009,6 +997,4 @@ main (int argc, char **_argv)
return commands[i].func ();
}
usage ();
-
- return 0;
}
diff --git a/winsup/utils/setfacl.c b/winsup/utils/setfacl.c
index 926581a..eb4ad6c 100644
--- a/winsup/utils/setfacl.c
+++ b/winsup/utils/setfacl.c
@@ -525,7 +525,7 @@ setfacl (action_t action, const char *path, aclent_t *acls, int cnt)
return 0;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream)
{
fprintf (stream, ""
@@ -647,6 +647,7 @@ usage (FILE *stream)
}
else
fprintf(stream, "Try '%s --help' for more information.\n", prog_name);
+ exit (stream == stdout ? 0 : 1);
}
struct option longopts[] = {
@@ -702,10 +703,7 @@ main (int argc, char **argv)
else if (action == DeleteDef)
action = DeleteAll;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
break;
case 'd': /* Backward compat */
case 'x':
@@ -714,10 +712,7 @@ main (int argc, char **argv)
else if (action == Modify)
action = ModNDel;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (! getaclentries (Delete, optarg, acls, &aclidx))
{
fprintf (stderr, "%s: illegal acl entries\n", prog_name);
@@ -728,10 +723,7 @@ main (int argc, char **argv)
if (action == NoAction)
action = Set;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (! getaclentries (SetFromFile, optarg, acls, &aclidx))
{
fprintf (stderr, "%s: illegal acl entries\n", prog_name);
@@ -740,17 +732,13 @@ main (int argc, char **argv)
break;
case 'h':
usage (stdout);
- return 0;
case 'k':
if (action == NoAction)
action = DeleteDef;
else if (action == DeleteExt)
action = DeleteAll;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
break;
case 'm':
if (action == NoAction)
@@ -758,10 +746,7 @@ main (int argc, char **argv)
else if (action == Delete)
action = ModNDel;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (! getaclentries (Modify, optarg, acls, &aclidx))
{
fprintf (stderr, "%s: illegal acl entries\n", prog_name);
@@ -780,10 +765,7 @@ main (int argc, char **argv)
if (action == NoAction)
action = Set;
else
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (! getaclentries (Set, optarg, acls, &aclidx))
{
fprintf (stderr, "%s: illegal acl entries\n", prog_name);
@@ -798,15 +780,9 @@ main (int argc, char **argv)
return 1;
}
if (action == NoAction)
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (optind > argc - 1)
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
if (action == Set)
switch (aclcheck (acls, aclidx, NULL))
{
diff --git a/winsup/utils/setmetamode.c b/winsup/utils/setmetamode.c
index 7ec6cf0..7d034cb 100644
--- a/winsup/utils/setmetamode.c
+++ b/winsup/utils/setmetamode.c
@@ -10,16 +10,17 @@ details. */
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <sys/ioctl.h>
#include <cygwin/kd.h>
#include <cygwin/version.h>
-static void
-usage (void)
+static void __attribute__ ((__noreturn__))
+usage (FILE *stream)
{
- fprintf (stderr, "Usage: %s [metabit|escprefix]\n"
+ fprintf (stream, "Usage: %s [metabit|escprefix]\n"
"\n"
"Get or set keyboard meta mode\n"
"\n"
@@ -32,6 +33,7 @@ usage (void)
" -h, --help This text\n"
" -V, --version Print program version and exit\n\n",
program_invocation_short_name);
+ exit (stream == stdout ? 0 : 1);
}
static void
@@ -87,8 +89,7 @@ main (int ac, char *av[])
switch (opt)
{
case 'h':
- usage ();
- return 0;
+ usage (stdout);
case 'V':
print_version ();
return 0;
@@ -105,10 +106,7 @@ main (int ac, char *av[])
|| !strcmp ("escprefix", av[1]))
param = 0x04;
else
- {
- usage ();
- return 1;
- }
+ usage (stderr);
if (ioctl (0, KDSKBMETA, param) < 0)
{
error ();
diff --git a/winsup/utils/ssp.c b/winsup/utils/ssp.c
index 548b89a..779b317 100644
--- a/winsup/utils/ssp.c
+++ b/winsup/utils/ssp.c
@@ -674,7 +674,7 @@ run_program (char *cmdline)
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE * stream)
{
fprintf (stream , ""
@@ -880,7 +880,6 @@ main (int argc, char **argv)
break;
case 'h':
usage (stdout);
- break;
case 'l':
printf ("profiling dll usage\n");
dll_counts = 1;
diff --git a/winsup/utils/strace.cc b/winsup/utils/strace.cc
index c8b2e2c..9b6569a 100644
--- a/winsup/utils/strace.cc
+++ b/winsup/utils/strace.cc
@@ -957,7 +957,7 @@ parse_mask (const char *ms, char **endptr)
return retval;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where, "\
@@ -1102,9 +1102,7 @@ main2 (int argc, char **argv)
forkdebug ^= 1;
break;
case 'h':
- // Print help and exit
usage (stdout);
- break;
case 'H':
include_hex ^= 1;
break;
diff --git a/winsup/utils/tzset.c b/winsup/utils/tzset.c
index b7fd1ae..8e1ba09 100644
--- a/winsup/utils/tzset.c
+++ b/winsup/utils/tzset.c
@@ -78,7 +78,7 @@ reg_enum (HKEY hkey, int idx, PWCHAR name, DWORD size)
== ERROR_SUCCESS;
}
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *stream)
{
fprintf (stream, ""
@@ -99,6 +99,7 @@ usage (FILE *stream)
"\n"
" setenv TZ `%1$s`\n"
"\n", program_invocation_short_name);
+ exit (stream == stdout ? 0 : 1);
};
static void
@@ -130,7 +131,6 @@ main (int argc, char **argv)
{
case 'h':
usage (stdout);
- return 0;
case 'V':
print_version ();
return 0;
@@ -140,10 +140,7 @@ main (int argc, char **argv)
return 1;
}
if (optind < argc)
- {
- usage (stderr);
- return 1;
- }
+ usage (stderr);
/* First fetch current timezone information from registry. */
hkey = reg_open (HKEY_LOCAL_MACHINE, REG_TZINFO, "timezone information");
diff --git a/winsup/utils/umount.cc b/winsup/utils/umount.cc
index 100f36f..f60933d 100644
--- a/winsup/utils/umount.cc
+++ b/winsup/utils/umount.cc
@@ -29,7 +29,7 @@ struct option longopts[] =
char opts[] = "hUV";
-static void
+static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where, "\