Skip to content

Commit

Permalink
Get rid of getenv declaration (there is no manual definition in our c…
Browse files Browse the repository at this point in the history
…ode) and check its presence in CMakeLists.txt; refactor conditions related to getopt (3 cases: defined in stdlib.h, defined in getopt.h, manually defined)
  • Loading branch information
valco1994 committed Feb 28, 2019
1 parent fc5bb22 commit b7ff761
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ if (NOT HAVE_UNISTD_H AND HAVE_SYS_TYPES_H)
check_symbol_exists(pid_t sys/types.h HAVE_PID_T_IN_SYS_TYPES_H)
endif()

check_function_exists(getopt HAVE_GETOPT)
check_symbol_exists(getopt stdlib.h STDLIB_HAS_GETOPT)
check_symbol_exists(getenv stdlib.h STDLIB_HAS_GETENV)
if (NOT STDLIB_HAS_GETENV)
message(FATAL_ERROR "getenv is required but not found")
endif()
#check_function_exists(getpid HAVE_GETPID)
#if (NOT HAVE_GETPID)
# check_function_exists(_getpid HAVE__GETPID)
Expand Down
9 changes: 6 additions & 3 deletions src/bm_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ static char alpha_num[65] =
#define PROTO(s) ()
#endif

char *getenv PROTO((const char *name));
#ifndef STDLIB_HAS_GETENV
#error "getenv is required but not found"
// char *getenv PROTO((const char *name));
#endif
void usage();
long *permute_dist(distribution *d, long stream);
extern long Seed[];
Expand Down Expand Up @@ -471,7 +474,7 @@ dsscasecmp(char *s1, char *s2)
return ((tolower(*s1) < tolower(*s2)) ? -1 : 1);
}

#ifndef STDLIB_HAS_GETOPT
#if (!defined(STDLIB_HAS_GETOPT) && !defined(HAVE_GETOPT_H))
int optind = 0;
int opterr = 0;
char *optarg = NULL;
Expand Down Expand Up @@ -533,7 +536,7 @@ getopt(int ac, char **av, char *opt)
return(*cp);
}
}
#endif /* STDLIB_HAS_GETOPT */
#endif /* (!defined(STDLIB_HAS_GETOPT) && !defined(HAVE_GETOPT_H)) */

char **
mk_ascdate(void)
Expand Down
8 changes: 3 additions & 5 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*
* The following #defines will effect the code:
* SEPARATOR -- character used to separate fields in flat files
* STDLIB_HAS_GETOPT -- to prevent confilcts with global getopt()
* MDY_DATE -- generate dates as MM-DD-YY
* WIN32 -- support for WindowsNT
* DSS_HUGE -- 64 bit data type
Expand Down Expand Up @@ -79,10 +78,9 @@
#define HUGE_COUNT 1
#define HUGE_DATE_FORMAT "%02" HUGE_FORMAT_SPECIFIER

#cmakedefine01 HAVE_GETOPT
#if (HAVE_GETOPT == 1)
#define STDLIB_HAS_GETOPT 1
#endif
#cmakedefine HAVE_GETOPT_H
#cmakedefine STDLIB_HAS_GETOPT
#cmakedefine STDLIB_HAS_GETENV

#cmakedefine01 HAVE_GETPID
#if (HAVE_GETPID == 1)
Expand Down
12 changes: 6 additions & 6 deletions src/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
#include <strings.h>
#endif

#ifndef STDLIB_HAS_GETOPT
#if defined(STDLIB_HAS_GETOPT)
/* do nothing */
#elif defined(HAVE_GETOPT_H)
#include <getopt.h>
#else
int getopt(int arg_cnt, char **arg_vect, char *options);
#endif /* STDLIB_HAS_GETOPT */
#endif /* defined(STDLIB_HAS_GETOPT) */

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
Expand All @@ -39,10 +43,6 @@ int getopt(int arg_cnt, char **arg_vect, char *options);
#include <sys/wait.h>
#endif

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

#if (defined(HAVE_PROCESS_H) && defined(HAVE_WINDOWS_H)) // Windows system
/* TODO: Do we really need all of these Windows-specific definitions? */
#include <process.h>
Expand Down
4 changes: 2 additions & 2 deletions src/dss.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ int pick_str PROTO((distribution * s, int c, char *target));
void agg_str PROTO((distribution *set, long count, long col, char *dest));
void read_dist PROTO((char *path, char *name, distribution * target));
void embed_str PROTO((distribution *d, int min, int max, int stream, char *dest));
#ifndef STDLIB_HAS_GETOPT
#if (!defined(STDLIB_HAS_GETOPT) && !defined(HAVE_GETOPT_H))
int getopt PROTO((int arg_cnt, char **arg_vect, char *options));
#endif /* STDLIB_HAS_GETOPT */
#endif /* (!defined(STDLIB_HAS_GETOPT) && !defined(HAVE_GETOPT_H)) */
long set_state PROTO((int t, long scale, long procs, long step, long *e));

/* rnd.c */
Expand Down
4 changes: 4 additions & 0 deletions src/qgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "tpcd.h"
#include "permute.h"

#if (!defined(STDLIB_HAS_GETOPT) && defined(HAVE_GETOPT_H))
#include <getopt.h>
#endif


#define LINE_SIZE 512

Expand Down

0 comments on commit b7ff761

Please sign in to comment.