summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/bbackupctl/bbackupctl.cpp1
-rw-r--r--bin/bbstoreaccounts/bbstoreaccounts.cpp1
-rw-r--r--infrastructure/buildenv-testmain-template.cpp7
-rw-r--r--lib/server/Daemon.cpp2
-rw-r--r--lib/win32/box_getopt.h14
-rwxr-xr-xlib/win32/bsd_getopt.h (renamed from lib/win32/getopt.h)7
-rwxr-xr-xlib/win32/getopt_long.cpp9
7 files changed, 27 insertions, 14 deletions
diff --git a/bin/bbackupctl/bbackupctl.cpp b/bin/bbackupctl/bbackupctl.cpp
index 39f15baf..643f0e8c 100644
--- a/bin/bbackupctl/bbackupctl.cpp
+++ b/bin/bbackupctl/bbackupctl.cpp
@@ -18,6 +18,7 @@
#include <cstdlib>
+#include "box_getopt.h"
#include "MainHelper.h"
#include "BoxPortsAndFiles.h"
#include "BackupDaemonConfigVerify.h"
diff --git a/bin/bbstoreaccounts/bbstoreaccounts.cpp b/bin/bbstoreaccounts/bbstoreaccounts.cpp
index 6a5c2e33..f2292ca1 100644
--- a/bin/bbstoreaccounts/bbstoreaccounts.cpp
+++ b/bin/bbstoreaccounts/bbstoreaccounts.cpp
@@ -24,6 +24,7 @@
#include <ostream>
#include <vector>
+#include "box_getopt.h"
#include "BackupStoreAccounts.h"
#include "BackupStoreAccountDatabase.h"
#include "BackupStoreCheck.h"
diff --git a/infrastructure/buildenv-testmain-template.cpp b/infrastructure/buildenv-testmain-template.cpp
index e5b1360d..933c3608 100644
--- a/infrastructure/buildenv-testmain-template.cpp
+++ b/infrastructure/buildenv-testmain-template.cpp
@@ -25,10 +25,6 @@
#include <stdio.h>
#include <unistd.h>
-#ifdef HAVE_GETOPT_H
- #include <getopt.h>
-#endif
-
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
@@ -43,6 +39,7 @@
#include <exception>
#include <string>
+#include "box_getopt.h"
#include "Logging.h"
#include "Test.h"
#include "Timer.h"
@@ -231,7 +228,6 @@ int main(int argc, char * const * argv)
Logging::SetProgramName(BOX_MODULE);
-#ifdef HAVE_GETOPT_H
#ifdef BOX_RELEASE_BUILD
int logLevel = Log::NOTICE; // need an int to do math with
#else
@@ -372,7 +368,6 @@ int main(int argc, char * const * argv)
argc -= optind - 1;
argv += optind - 1;
-#endif // HAVE_GETOPT_H
// If there is more than one argument, then the test is doing something advanced, so leave it alone
bool fulltestmode = (argc == 1);
diff --git a/lib/server/Daemon.cpp b/lib/server/Daemon.cpp
index 7419f973..1562b6e8 100644
--- a/lib/server/Daemon.cpp
+++ b/lib/server/Daemon.cpp
@@ -368,7 +368,7 @@ int Daemon::ProcessOptions(int argc, const char *argv[])
// reset getopt, just in case anybody used it before.
// unfortunately glibc and BSD differ on this point!
// http://www.ussg.iu.edu/hypermail/linux/kernel/0305.3/0262.html
- #if HAVE_DECL_OPTRESET == 1 || defined WIN32
+ #if HAVE_DECL_OPTRESET == 1 || defined BOX_BSD_GETOPT
optind = 1;
optreset = 1;
#elif defined __GLIBC__
diff --git a/lib/win32/box_getopt.h b/lib/win32/box_getopt.h
new file mode 100644
index 00000000..f18446d4
--- /dev/null
+++ b/lib/win32/box_getopt.h
@@ -0,0 +1,14 @@
+#if defined _MSC_VER || defined __MINGW32__
+#define REPLACE_GETOPT 1 /* use this getopt as the system getopt(3) */
+#else
+#define REPLACE_GETOPT 0 // force a conflict if included multiple times
+#endif
+
+#if REPLACE_GETOPT
+# include "bsd_getopt.h"
+# define BOX_BSD_GETOPT
+#else
+# include <getopt.h>
+# undef BOX_BSD_GETOPT
+#endif
+
diff --git a/lib/win32/getopt.h b/lib/win32/bsd_getopt.h
index 7c290343..9cfdd32e 100755
--- a/lib/win32/getopt.h
+++ b/lib/win32/bsd_getopt.h
@@ -37,6 +37,12 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#ifndef REPLACE_GETOPT
+#error You must include box_getopt.h, not bsd_getopt.h
+#endif
+
+#if REPLACE_GETOPT // defined in box_getopt.h; until end of file
+
#ifndef _GETOPT_H_
#define _GETOPT_H_
@@ -96,3 +102,4 @@ extern char *suboptarg; /* getsubopt(3) external variable */
__END_DECLS
#endif /* !_GETOPT_H_ */
+#endif // REPLACE_GETOPT
diff --git a/lib/win32/getopt_long.cpp b/lib/win32/getopt_long.cpp
index 31695aa0..941f23c1 100755
--- a/lib/win32/getopt_long.cpp
+++ b/lib/win32/getopt_long.cpp
@@ -68,16 +68,13 @@
#include "getopt.h"
-#if defined _MSC_VER || defined __MINGW32__
-#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
+#ifdef REPLACE_GETOPT // until end of file
-#ifdef REPLACE_GETOPT
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
-#endif
#define PRINT_ERROR ((opterr) && (*options != ':'))
@@ -499,7 +496,6 @@ start:
return (optchar);
}
-#ifdef REPLACE_GETOPT
/*
* getopt --
* Parse argc/argv argument vector.
@@ -520,7 +516,6 @@ getopt(int nargc, char * const *nargv, const char *options)
*/
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
-#endif /* REPLACE_GETOPT */
/*
* getopt_long --
@@ -548,4 +543,4 @@ getopt_long_only(int nargc, char * const *nargv, const char *options,
FLAG_PERMUTE|FLAG_LONGONLY));
}
-#endif // defined _MSC_VER || defined __MINGW32__
+#endif // REPLACE_GETOPT