From cc6eb3d53deb4c739a16230136945c1a0dca05b0 Mon Sep 17 00:00:00 2001 From: Cameron Cawley <ccawley2011@gmail.com> Date: Sun, 1 Sep 2024 22:54:56 +0100 Subject: [PATCH] Allow getopt fallback to compile on non-Windows platforms --- include/compat/getopt.h | 2 ++ tools/compat/getopt.c | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/compat/getopt.h b/include/compat/getopt.h index 930e002a1..ad597691e 100644 --- a/include/compat/getopt.h +++ b/include/compat/getopt.h @@ -13,7 +13,9 @@ #define __GETOPT_H__ /* All the headers include this file. */ +#ifdef _WIN32 #include <crtdefs.h> +#endif #ifdef __cplusplus extern "C" { diff --git a/tools/compat/getopt.c b/tools/compat/getopt.c index ac1fda426..ab375bdb1 100644 --- a/tools/compat/getopt.c +++ b/tools/compat/getopt.c @@ -55,7 +55,11 @@ #include <getopt.h> #include <stdarg.h> #include <stdio.h> +#ifdef _WIN32 #include <windows.h> +#else +#include <err.h> +#endif #define REPLACE_GETOPT /* use this getopt as the system getopt(3) */ @@ -80,12 +84,6 @@ char *optarg; /* argument associated with option */ #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER (int)1 -#ifndef __CYGWIN__ -#define __progname __argv[0] -#else -extern char __declspec(dllimport) *__progname; -#endif - #ifdef __CYGWIN__ static char EMSG[] = ""; #else @@ -113,6 +111,13 @@ static const char noarg[] = "option doesn't take an argument -- %.*s"; static const char illoptchar[] = "unknown option -- %c"; static const char illoptstring[] = "unknown option -- %s"; +#ifdef _WIN32 +#ifndef __CYGWIN__ +#define __progname __argv[0] +#else +extern char __declspec(dllimport) *__progname; +#endif + static void _vwarnx(const char *fmt,va_list ap) { @@ -130,6 +135,7 @@ warnx(const char *fmt,...) _vwarnx(fmt,ap); va_end(ap); } +#endif /* * Compute the greatest common divisor of a and b. -- GitLab