+#include <wincompat.h>
+
+float fmaxf(float a, float b)
+{
+ return a < b ? b : a;
+}
+
+/* ----------------------------------------------------------------------------------
+ usleep
+ ---------------------------------------------------------------------------------- */
+
+#include <windows.h>
+
+int usleep(unsigned int useconds)
+{
+ HANDLE timer;
+ LARGE_INTEGER due;
+
+ due.QuadPart = -(10 * (__int64)useconds);
+
+ timer = CreateWaitableTimer(NULL, TRUE, NULL);
+ SetWaitableTimer(timer, &due, 0, NULL, NULL, 0);
+ WaitForSingleObject(timer, INFINITE);
+ CloseHandle(timer);
+ return 0;
+}
+
+/* ----------------------------------------------------------------------------------
+ getopt
+ ---------------------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <string.h>
+
+int opterr = 0;
+int optind = 1;
+int optopt = 0;
+char *optarg = 0;
+
+int optreset = 0;
+
+int
+getopt(
+ int nargc,
+ char *const * nargv,
+ const char *ostr
+)
+{
+ static char *place = EMSG; /* option letter processing */
+ 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 == '-' && place[1] == '\0')
+ { /* found "--" */
+ ++optind;
+ place = EMSG;
+ return -1;
+ }
+ } /* option letter okay? */
+ if ((optopt = (int) *place++) == (int) ':' ||
+ !(oli = strchr((char *) 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) fprintf(stderr,
+ "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) fprintf(stderr,
+ "option requires an argument -- %c\n",
+ optopt);
+ return BADCH;
+ }
+ else
+ /* white space */
+ optarg = nargv[optind];
+ place = EMSG;
+ ++optind;
+ }
+ return optopt; /* dump back option letter */
+}
\ No newline at end of file