public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: utils: convert usage() to proper noreturn function throughout
@ 2020-08-07 13:16 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-08-07 13:16 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=e7fca6f867f441aaf54061545b297a62ce93708f
commit e7fca6f867f441aaf54061545b297a62ce93708f
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Fri Aug 7 13:29:43 2020 +0200
Cygwin: utils: convert usage() to proper noreturn function throughout
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/utils/chattr.c | 9 +++------
winsup/utils/cygcheck.cc | 4 +---
winsup/utils/cygpath.cc | 3 +--
winsup/utils/dumper.cc | 2 +-
winsup/utils/getconf.c | 2 +-
winsup/utils/getfacl.c | 10 ++++------
winsup/utils/kill.cc | 2 +-
winsup/utils/ldd.cc | 4 ++--
winsup/utils/locale.cc | 4 ++--
winsup/utils/lsattr.c | 5 +++--
winsup/utils/minidumper.cc | 2 +-
winsup/utils/mkgroup.c | 5 ++---
winsup/utils/mkpasswd.c | 5 ++---
winsup/utils/mount.cc | 2 +-
winsup/utils/passwd.c | 3 +--
winsup/utils/ps.cc | 2 +-
winsup/utils/regtool.cc | 24 +++++-------------------
winsup/utils/setfacl.c | 44 ++++++++++----------------------------------
winsup/utils/setmetamode.c | 16 +++++++---------
winsup/utils/ssp.c | 3 +--
winsup/utils/strace.cc | 4 +---
winsup/utils/tzset.c | 9 +++------
winsup/utils/umount.cc | 2 +-
23 files changed, 55 insertions(+), 111 deletions(-)
diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c
index c21d4b7a5..98f693aab 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 2cc25d985..a45ab5d4d 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 bf77bb2a9..aa9df3a21 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 5f8121aa3..25fd080c8 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 5ac84abd2..bc37bfb47 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 a6fac9762..5a3730bd6 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 a22d70253..d0fb54737 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 a74054f4d..e1af99e12 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 1cd04337c..1eee9d240 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 ee72043f0..70022803d 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 bc46358fb..9331b735a 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 fc36e274c..3e99438c9 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 9562eacbd..3bbdb1c71 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 bd267511d..a65a6e577 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 aa8e8cc3a..c3210e412 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 4d7a56d3d..f3eb9e847 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 f91e61d00..16972291f 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 926581a39..eb4ad6c65 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 7ec6cf0c1..7d034cb1f 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 548b89ac8..779b31775 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 c8b2e2cf5..9b6569a70 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 b7fd1aec2..8e1ba09d1 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 100f36f9c..f60933d71 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, "\
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-07 13:16 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 13:16 [newlib-cygwin] Cygwin: utils: convert usage() to proper noreturn function throughout Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).