diff --git a/configure.in b/configure.in index 2fae47f5..3b2cddba 100644 --- a/configure.in +++ b/configure.in @@ -45,6 +45,8 @@ dnl AC_TYPE_SIGNAL dnl AC_FUNC_FORK AC_FUNC_MEMCMP AC_FUNC_STRFTIME +AC_CHECK_FUNCS(gmtime_r) +AC_CHECK_FUNCS(getpwuid_r) dnl use AC_REPLACE_FUNCS() for stuff in string.h dnl AC_HEADER_SYS_WAIT diff --git a/http/CHTTPProtocol.cpp b/http/CHTTPProtocol.cpp index a03011f1..e49bdd00 100644 --- a/http/CHTTPProtocol.cpp +++ b/http/CHTTPProtocol.cpp @@ -273,14 +273,18 @@ CHTTPProtocol::reply(IOutputStream* stream, CHTTPReply& reply) // get date // FIXME -- should use C++ locale stuff but VC++ time_put is broken. // FIXME -- double check that VC++ is broken - // FIXME -- should mutex gmtime() since the return value may not - // be thread safe char date[30]; { const char* oldLocale = setlocale(LC_TIME, "C"); time_t t = time(NULL); - struct tm* tm = gmtime(&t); - strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S GMT", tm); +#if HAVE_GMTIME_R + struct tm tm; + struct tm* tmp = &tm; + gmtime_r(&t, tmp); +#else + struct tm* tmp = gmtime(&t); +#endif + strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S GMT", tmp); setlocale(LC_TIME, oldLocale); } diff --git a/platform/CUnixPlatform.cpp b/platform/CUnixPlatform.cpp index 26110dd0..484bfb3e 100644 --- a/platform/CUnixPlatform.cpp +++ b/platform/CUnixPlatform.cpp @@ -161,10 +161,18 @@ CUnixPlatform::getBasename(const char* pathname) const CString CUnixPlatform::getUserDirectory() const { - // FIXME -- use geteuid? shouldn't run this setuid anyway. - struct passwd* pwent = getpwuid(getuid()); - if (pwent != NULL && pwent->pw_dir != NULL) { - return pwent->pw_dir; +#if HAVE_GETPWUID_R + struct passwd pwent; + struct passwd* pwentp; + long size = sysconf(_SC_GETPW_R_SIZE_MAX); + char* buffer = new char[size]; + getpwuid_r(getuid(), &pwent, buffer, size, &pwentp); + delete[] buffer; +#else + struct passwd* pwentp = getpwuid(getuid()); +#endif + if (pwentp != NULL && pwentp->pw_dir != NULL) { + return pwentp->pw_dir; } else { return CString();