From 4927a1109d2825203a2078987f431cca77f89b16 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 10 Oct 2012 22:41:30 +0000 Subject: [PATCH] fixes for win32 (ported 2.3.99.0 patches). Thanks to LRN (from Mailing list). svn path=/icecast/trunk/icecast/; revision=18642 --- configure.in | 5 +++-- src/logging.c | 10 +++++++++- src/main.c | 10 +++++++--- src/util.c | 19 ++++++++++++++++--- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/configure.in b/configure.in index 940a1132..e83d7b62 100644 --- a/configure.in +++ b/configure.in @@ -34,8 +34,9 @@ AC_HEADER_STDC AC_HEADER_TIME AC_CHECK_HEADERS([alloca.h sys/timeb.h]) -AC_CHECK_HEADERS(pwd.h, AC_DEFINE(CHUID, 1, [Define if you have pwd.h]),,) -AC_CHECK_HEADERS(unistd.h, AC_DEFINE(CHROOT, 1, [Define if you have unistd.h]),,) +AC_CHECK_HEADERS([pwd.h, unistd.h, grp.h, sys/types.h]) +AC_CHECK_FUNC([chuid]) +AC_CHECK_FUNC([chown]) dnl Checks for typedefs, structures, and compiler characteristics. XIPH_C__FUNC__ diff --git a/src/logging.c b/src/logging.c index 86de27bc..0dc1a1f2 100644 --- a/src/logging.c +++ b/src/logging.c @@ -54,7 +54,15 @@ int get_clf_time (char *buffer, unsigned len, struct tm *t) struct tm *thetime; time_t now; - gmtime_r(&time1, &gmt); +#if !defined(_WIN32) + thetime = gmtime_r(&time1, &gmt) +#else + /* gmtime() on W32 breaks POSIX and IS thread-safe (uses TLS) */ + thetime = gmtime (&time1); + if (thetime) + memcpy (&gmt, thetime, sizeof (gmt)); +#endif + /* FIXME: bail out if gmtime* returns NULL */ time_days = t->tm_yday - gmt.tm_yday; diff --git a/src/main.c b/src/main.c index 99b8411d..2f9abb95 100644 --- a/src/main.c +++ b/src/main.c @@ -41,9 +41,13 @@ #include "net/resolver.h" #include "httpp/httpp.h" -#ifdef CHUID +#if HAVE_SYS_TYPES_H #include +#endif +#if HAVE_GRP_H #include +#endif +#if HAVE_PWD_H #include #endif @@ -362,7 +366,7 @@ static void _ch_root_uid_setup(void) } #endif -#ifdef CHROOT +#if HAVE_CHROOT if (conf->chroot) { if(getuid()) /* root check */ @@ -380,7 +384,7 @@ static void _ch_root_uid_setup(void) } #endif -#ifdef CHUID +#if HAVE_CHUID if(conf->chuid) { diff --git a/src/util.c b/src/util.c index c6f323d6..ed4a7a6a 100644 --- a/src/util.c +++ b/src/util.c @@ -494,7 +494,8 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, ice_config_t *config; time_t now; struct tm result; - char currenttime_buffer[50]; + struct tm *gmtime_result; + char currenttime_buffer[80]; char status_buffer[80]; char contenttype_buffer[80]; ssize_t ret; @@ -546,10 +547,22 @@ ssize_t util_http_build_header(char * out, size_t len, ssize_t offset, } time(&now); - strftime(currenttime_buffer, 50, "%a, %d-%b-%Y %X GMT", gmtime_r(&now, &result)); +#ifndef _WIN32 + gmtime_result = gmtime_r(&now, &result); +#else + /* gmtime() on W32 breaks POSIX and IS thread-safe (uses TLS) */ + gmtime_result = gmtime (&now); + if (gmtime_result) + memcpy (&result, gmtime_result, sizeof (result)); +#endif + + if (gmtime_result) + strftime(currenttime_buffer, sizeof(currenttime_buffer), "Date: %a, %d-%b-%Y %X GMT\r\n", gmtime_result); + else + currenttime_buffer[0] = '\0'; config = config_get_config(); - ret = snprintf (out, len, "%sServer: %s\r\nDate: %s\r\n%s%s%s%s%s", + ret = snprintf (out, len, "%sServer: %s\r\n%s%s%s%s%s%s", status_buffer, config->server_id, currenttime_buffer,