diff --git a/Makefile.win b/Makefile.win new file mode 100644 index 0000000..e28db0a --- /dev/null +++ b/Makefile.win @@ -0,0 +1,40 @@ +########################################################################### +# +# Usage: NMAKE -f Makefile.win APR={apr installion dir} APRUTIL={aprutil installion dir} +# +!IF "$(APR)" == "" || "$(APRUTIL)" == "" +!ERROR NMAKE arguments: APR=dir and APRUTIL=dir are required to build modsec-sdbm-util for Windows +!ENDIF + +########################################################################### + +cc = cl + +link = link + +includes = -I$(APRUTIL)\include -I$(APR)\include + +libs = $(APR)\lib\libapr-1.lib $(APRUTIL)\lib\libaprutil-1.lib + +cflags= $(includes) /nologo /DWIN32 /DWINNT /D_WINDOWS /Dinline=APR_INLINE /w /Zf /Zi /FS /O2 /GL /MD /DNDEBUG + +ldflags = /nologo /Incremental:no /LTCG /debug /opt:ref,icf + +objs = modsec-sdbm-util.obj + +exe = modsec-sdbm-util.exe + +########################################################################### + +all: $(exe) + +exe: $(exe) + +.c.obj: + $(cc) $(cflags) -c $< -Fo$@ + +$(exe): $(objs) + $(link) $(ldflags) -out:$(exe) $(objs) $(libs) + +clean: + del $(objs) $(exe) *.exe *.pdb *.idb *.ilk *.exp *.res *.rc *.bin *.manifest diff --git a/modsec-sdbm-util.c b/modsec-sdbm-util.c index 420a493..250e638 100644 --- a/modsec-sdbm-util.c +++ b/modsec-sdbm-util.c @@ -20,7 +20,7 @@ #include #include #include -#include + #include #include #include @@ -32,11 +32,86 @@ #define VERSION "v1.0" #ifndef WIN32 +#include # define v(fmt, ARGS...) do { if (verbose) printf("%s:%d:%s(): " fmt, __FILE__, \ __LINE__, __func__, ## ARGS); } while (0) # define p(fmt, ARGS...) do { printf(fmt, ## ARGS); } while (0) #endif #ifdef WIN32 +#include +#include + +int opterr = 1, /* if error message should be printed */ + optind = 1, /* index into parent argv vector */ + optopt, /* character checked for validity */ + optreset; /* reset getopt */ +char *optarg; /* argument associated with option */ + +#define BADCH (int)'?' +#define BADARG (int)':' +#define EMSG "" + +/* +* getopt -- +* Parse argc/argv argument vector. +*/ +int + getopt(int nargc, char * const nargv[], const char *ostr) +{ + static char *place = EMSG; /* option letter processing */ + const char *oli; /* option letter list index */ + + if (optreset || !*place) { /* update scanning pointer */ + optreset = 0; + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (-1); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (-1); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + /* + * if the user didn't specify '-' as an option, + * assume it means -1. + */ + if (optopt == (int)'-') + return (-1); + if (!*place) + ++optind; + if (opterr && *ostr != ':') + (void)printf("illegal option -- %c\n", optopt); + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } + else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (*ostr == ':') + return (BADARG); + if (opterr) + (void)printf("option requires an argument -- %c\n", optopt); + return (BADCH); + } + else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} + +#define strndup strdup #define p printf #define v if (verbose) printf #endif