From 7323ad2f228fd1efbddd5a81ef7de552be9fceee Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 18 Aug 2026 16:40:34 +0900 Subject: [PATCH] fix mingw32 build errors and warnings - define usleep() as Sleep() on Win32 so the #ifdef branches around each sleep call can go away. usleep() was undeclared on mingw32 because unistd.h is only included on non-Windows. - memset(tm, 0, sizeof(tm)) cleared only the size of the pointer, not the struct it points at. - drop the unused loop counter n in res_popen(). - print the read size with %lld instead of %I64d; current mingw-w64 uses ANSI stdio. - drop -mtune=i686 from Makefile.w32. Claude-Session: https://claude.ai/code/session_015AgpKrpE6ejPM4MWRWb8HQ --- Makefile.w32 | 4 ++-- httpd.cxx | 15 +++------------ httpd.h | 3 +++ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Makefile.w32 b/Makefile.w32 index 67718fb..a4a638a 100644 --- a/Makefile.w32 +++ b/Makefile.w32 @@ -3,10 +3,10 @@ all : tthttpd.exe tthttpd.exe : main.o httpd.o utils.o - g++ -O2 -mtune=i686 -mthreads -o $@ main.o httpd.o utils.o -lws2_32 + g++ -O2 -mthreads -o $@ main.o httpd.o utils.o -lws2_32 .cxx.o : - g++ -O2 -mtune=i686 -mthreads -Wall -c $< + g++ -O2 -mthreads -Wall -c $< clean : rm *.o tthttpd diff --git a/httpd.cxx b/httpd.cxx index 45eef48..01d00a7 100644 --- a/httpd.cxx +++ b/httpd.cxx @@ -360,7 +360,7 @@ static bool filetime2unixtime(const FILETIME* ft, struct tm* tm) { if (!FileTimeToLocalFileTime(ft, <)) return false; if (!FileTimeToSystemTime(<, &st)) return false; - memset(tm, 0, sizeof(tm)); + memset(tm, 0, sizeof(*tm)); tm->tm_year = st.wYear - 1900; tm->tm_mon = st.wMonth - 1; tm->tm_mday = st.wDay; @@ -644,7 +644,6 @@ static long long res_read(RES_INFO* res_info, char* data, unsigned long size) { static RES_INFO* res_popen(std::vector& args, std::vector& envs) { int envs_len = 1; - int n; char *envs_ptr; char *ptr; std::vector::const_iterator it; @@ -700,7 +699,7 @@ static RES_INFO* res_popen(std::vector& args, std::vector 0) { if (VERBOSE(3)) -#ifdef _WIN32 - printf(" reading part %I64d bytes\n", res); -#else - printf(" reading part %lld bytes\n", res); -#endif + printf(" reading part %lld bytes\n", (long long)res); send(msgsock, buf, res, 0); if (total > 0) { total -= res; } } else { -#ifdef _WIN32 - Sleep(1); -#else usleep(10); -#endif } } } diff --git a/httpd.h b/httpd.h index 841f0c0..a1c8e13 100644 --- a/httpd.h +++ b/httpd.h @@ -38,6 +38,9 @@ #include #include #include +/* Sleep() takes milliseconds. round up so that sub-millisecond waits + * still yield the cpu. */ +#define usleep(usec) Sleep(((usec) + 999) / 1000) #else #include #include