diff -uwrN cherokee.orig/ChangeLog cherokee/ChangeLog --- cherokee.orig/ChangeLog Sun Jul 22 15:58:32 2007 +++ cherokee/ChangeLog Wed Jul 25 00:08:50 2007 @@ -1,3 +1,8 @@ +2007-07-23 Ross Smith II + + * cherokee/post.c, cherokee/win32_misc.c, cherokee/win32_misc.h: + Add mkstemp() functionality missing in MinGW. + 2007-07-22 Alvaro Lopez Ortega * cherokee/handler_redir.c, cherokee/read_config_embedded.c, @@ -492,7 +497,7 @@ * cherokee/win32_cservice.h, cherokee/win32_cservice.c, cherokee/win32_cherokeeserv.c, windows/cherokee.reg: Added a Win32 - service. Code by Ross Smith II + service. Code by Ross Smith II * cherokee/Makefile.am (win32_cherokeeserv), windows/cherokee.reg: Created new binary target, and added win32_cservice.h, @@ -503,7 +508,7 @@ * cherokee/win32_misc.h, cherokee/win32_misc.c: Added new func cherokee_win32_shutdown_signaled(). Patch by Ross Smith II - + * cherokee/server.c (cherokee_server_step): Call cherokee_win32_shutdown_signaled() before checking if the server diff -uwrN cherokee.orig/cherokee/post.c cherokee/cherokee/post.c --- cherokee.orig/cherokee/post.c Wed Jul 4 13:23:51 2007 +++ cherokee/cherokee/post.c Tue Jul 24 23:54:04 2007 @@ -88,11 +88,16 @@ post->size = len; if (post->type == post_in_tmp_file) { +#ifndef __MINGW32__ cherokee_buffer_add_str (&post->tmp_file, "/tmp/cherokee_post_XXXXXX"); /* Generate a unique name */ post->tmp_file_fd = mkstemp (post->tmp_file.buf); +#else + post->tmp_file_fd = cherokee_win32_mkstemp (&post->tmp_file); +#endif + if (unlikely (post->tmp_file_fd < 0)) { return ret_error; } diff -uwrN cherokee.orig/cherokee/win32_misc.c cherokee/cherokee/win32_misc.c --- cherokee.orig/cherokee/win32_misc.c Sun Jul 22 15:58:32 2007 +++ cherokee/cherokee/win32_misc.c Tue Jul 24 23:58:09 2007 @@ -48,6 +48,10 @@ /* __declspec(dllexport) */ const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; #endif +#ifndef O_LARGEFILE +# define O_LARGEFILE 0 +#endif + #define _ctor #define EXIT_EVENT_NAME "cherokee_exit_1" #define CLEAR(x) memset(&(x), 0, sizeof(x)) @@ -1059,4 +1063,47 @@ } return WaitForSingleObject (exit_event, (DWORD) 0) == WAIT_OBJECT_0; +} + +int +cherokee_win32_mkstemp (cherokee_buffer_t *buffer) +{ + int fd = -1; + static char tmp_file[MAX_PATH + 14] = {0}; + + while (1) { + char buferr[ERROR_MAX_BUFSIZE]; + + static char tmp_path[MAX_PATH + 14] = {0}; + static UINT uUnique = 0; + + *tmp_file = '\0'; + + if (!*tmp_path) { + if (!GetTempPath (sizeof(tmp_path), tmp_path)) { + cherokee_strerror_r (GetLastError (), buferr, sizeof(buferr)); + PRINT_MSG ("Couldn't get temporary path: %s", buferr); + /* strcpy (tmp_path, "\\"); /* TODO FIXME use c:\Progra~\cherokee\var\tmp ? */ + break; + } + } + + if (!GetTempFileName (tmp_path, "chp", uUnique++, tmp_file)) { + cherokee_strerror_r (GetLastError(), buferr, sizeof(buferr)); + PRINT_MSG ("Couldn't generate temporary file name: %s", buferr); + break; + } + + fd = open (tmp_file, O_APPEND | O_WRONLY | O_CREAT | O_LARGEFILE | O_BINARY, 0600); + if (fd == -1) { + PRINT_MSG ("Couldn't create '%s': %s", tmp_file, strerror(errno)); + break; + } + + break; + } + + cherokee_buffer_add_str (buffer, tmp_file); + + return fd; } diff -uwrN cherokee.orig/cherokee/win32_misc.h cherokee/cherokee/win32_misc.h --- cherokee.orig/cherokee/win32_misc.h Tue Jul 3 06:22:27 2007 +++ cherokee/cherokee/win32_misc.h Tue Jul 24 23:57:07 2007 @@ -29,7 +29,7 @@ #include #include #include "common-internal.h" - +#include "buffer.h" #undef localtime_r /* in */ #define SHUT_WR SD_SEND @@ -42,5 +42,6 @@ int cherokee_win32_stat (const char *path, struct stat *buf); int cherokee_win32_shutdown_signaled(); +int cherokee_win32_mkstemp (cherokee_buffer_t *buffer); #endif /* CHEROKEE_WIN32_MISC_H */