Skip to content

Commit

Permalink
optlist.h
Browse files Browse the repository at this point in the history
Currently, options.c is the only file that #includes "optlist.h".

In theory, if a source file did want to include optlist.h (perhaps
for the struct allopt_t declaration so they could deal with a
pointer to such a struct), they wouldn't be able to include it
because of a static function prototype that it contains.

Add some protection to only include that static function
prototype when optlist.h is included from options.c.
  • Loading branch information
nhmall committed Dec 2, 2023
1 parent 4a00b66 commit 8ee8d89
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/optlist.h
Expand Up @@ -4,6 +4,10 @@
#ifndef OPTLIST_H
#define OPTLIST_H

#ifdef OPTIONS_C
static int optfn_boolean(int, int, boolean, char *, char *);
#endif

/*
* NOTE: If you add (or delete) an option, please review:
* doc/options.txt
Expand All @@ -12,7 +16,6 @@
* updates that should accompany your change.
*/

static int optfn_boolean(int, int, boolean, char *, char *);
enum OptType { BoolOpt, CompOpt, OthrOpt };
enum Y_N { No, Yes };
enum Off_On { Off, On };
Expand Down
3 changes: 3 additions & 0 deletions src/options.c
Expand Up @@ -50,6 +50,8 @@ NEARDATA struct instance_flags iflags; /* provide linkage */
*
*/

#define OPTIONS_C

#define NHOPT_PROTO
#include "optlist.h"
#undef NHOPT_PROTO
Expand All @@ -72,6 +74,7 @@ static struct allopt_t allopt_init[] = {
};
#undef NHOPT_PARSE

#undef OPTIONS_C

#define PILE_LIMIT_DFLT 5
#define rolestring(val, array, field) \
Expand Down

0 comments on commit 8ee8d89

Please sign in to comment.