Cygwin: utils: convert usage() to proper noreturn function throughout

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2020-08-07 13:29:43 +02:00
parent 9beb7b9771
commit e7fca6f867
23 changed files with 55 additions and 111 deletions

View File

@ -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 ())

View File

@ -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, "\

View File

@ -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 ();

View File

@ -948,7 +948,7 @@ dumper::write_core_dump ()
return 1;
}
static void
static void __attribute__ ((__noreturn__))
usage (FILE *stream, int status)
{
fprintf (stream, "\

View File

@ -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,

View File

@ -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)

View File

@ -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 , ""

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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, "\

View File

@ -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;

View File

@ -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;

View File

@ -203,7 +203,7 @@ static struct option longopts[] =
static char opts[] = "acfhmpVo:";
static void
static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
char *options;

View File

@ -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, ""

View File

@ -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, "\

View File

@ -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;
}

View File

@ -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))
{

View File

@ -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 ();

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -29,7 +29,7 @@ struct option longopts[] =
char opts[] = "hUV";
static void
static void __attribute__ ((__noreturn__))
usage (FILE *where = stderr)
{
fprintf (where, "\