Skip to content

Commit

Permalink
ext/getopt_long.c: rename and fix problematic macro
Browse files Browse the repository at this point in the history
Non-system-defined macro names may not begin with 2 underscores,
or an underscore followed by a capital letter.

A pointer is not guaranteed to be representable in `unsigned long'.
Use `uintptr_t' from <stdint.h> instead.

Fixes compiler diagnostic:

getopt_long.c:41:9: warning: macro name is a reserved identifier
    [-Wreserved-id-macro]
  • Loading branch information
aaronmdjones committed Jan 18, 2019
1 parent 3dfbdfa commit 8c26f03
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/libmowgli/ext/getopt_long.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int mowgli_optreset = 0;/* reset getopt */
char *mowgli_optarg = NULL; /* argument associated with option */

/* XXX: suppress const warnings */
#define __UNCONST(a) ((void *) (unsigned long) (const void *) (a))
#define PTR_UNCONSTIFY(a) ((void *)((uintptr_t)((const void *)(a))))

#define IGNORE_FIRST (*options == '-' || *options == '+')
#define PRINT_ERROR ((mowgli_opterr) && ((*options != ':') \
Expand Down Expand Up @@ -307,7 +307,7 @@ getopt_internal(int nargc, char **nargv, const char *options)

if (*place) /* no white space */
{
mowgli_optarg = __UNCONST(place);
mowgli_optarg = PTR_UNCONSTIFY(place);
}

/* XXX: disable test for :: if PC? (GNU doesn't) */
Expand Down Expand Up @@ -354,7 +354,7 @@ const char *options;
return_val_if_fail(nargv != NULL, -1);
return_val_if_fail(options != NULL, -1);

retval = getopt_internal(nargc, __UNCONST(nargv), options);
retval = getopt_internal(nargc, PTR_UNCONSTIFY(nargv), options);

if (retval == -2)
{
Expand All @@ -367,7 +367,7 @@ const char *options;
if (nonopt_end != -1)
{
permute_args(nonopt_start, nonopt_end, mowgli_optind,
__UNCONST(nargv));
PTR_UNCONSTIFY(nargv));
mowgli_optind -= nonopt_end - nonopt_start;
}

Expand Down Expand Up @@ -398,15 +398,15 @@ mowgli_getopt_long(int nargc, char *const *nargv, const char *options, const mow

/* idx may be NULL */

retval = getopt_internal(nargc, __UNCONST(nargv), options);
retval = getopt_internal(nargc, PTR_UNCONSTIFY(nargv), options);

if (retval == -2)
{
char *current_argv, *has_equal;
size_t current_argv_len;
int i, ambiguous, match;

current_argv = __UNCONST(place);
current_argv = PTR_UNCONSTIFY(place);
match = -1;
ambiguous = 0;

Expand All @@ -421,7 +421,7 @@ mowgli_getopt_long(int nargc, char *const *nargv, const char *options, const mow
if (nonopt_end != -1)
{
permute_args(nonopt_start, nonopt_end,
mowgli_optind, __UNCONST(nargv));
mowgli_optind, PTR_UNCONSTIFY(nargv));
mowgli_optind -= nonopt_end - nonopt_start;
}

Expand Down

0 comments on commit 8c26f03

Please sign in to comment.