|  | @@ -10,14 +10,9 @@
 | 
											
												
													
														|  |  #include <io.h>
 |  |  #include <io.h>
 | 
											
												
													
														|  |  #define strtoll strtol
 |  |  #define strtoll strtol
 | 
											
												
													
														|  |  typedef __int64 int64_t;
 |  |  typedef __int64 int64_t;
 | 
											
												
													
														|  | -#define O_CLOEXEC 0
 |  | 
 | 
											
												
													
														|  | -#define O_EXLOCK 0
 |  | 
 | 
											
												
													
														|  |  #else
 |  |  #else
 | 
											
												
													
														|  |  #include <inttypes.h>
 |  |  #include <inttypes.h>
 | 
											
												
													
														|  |  #include <unistd.h>
 |  |  #include <unistd.h>
 | 
											
												
													
														|  | -#ifndef O_BINARY
 |  | 
 | 
											
												
													
														|  | -#define O_BINARY 0
 |  | 
 | 
											
												
													
														|  | -#endif
 |  | 
 | 
											
												
													
														|  |  #endif // !_WIN32
 |  |  #endif // !_WIN32
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  #include "mongoose.h"
 |  |  #include "mongoose.h"
 | 
											
										
											
												
													
														|  | @@ -85,8 +80,13 @@ static void handle_file_upload(struct mg_connection *conn) {
 | 
											
												
													
														|  |      mg_printf(conn, "%s%s", HTTP_500, "Can't get file name");
 |  |      mg_printf(conn, "%s%s", HTTP_500, "Can't get file name");
 | 
											
												
													
														|  |    } else if (cl <= 0) {
 |  |    } else if (cl <= 0) {
 | 
											
												
													
														|  |      mg_printf(conn, "%s%s", HTTP_500, "Empty file");
 |  |      mg_printf(conn, "%s%s", HTTP_500, "Empty file");
 | 
											
												
													
														|  | -  } else if ((fd = open(path, O_CREAT | O_TRUNC | O_BINARY |
 |  | 
 | 
											
												
													
														|  | -                        O_WRONLY | O_EXLOCK | O_CLOEXEC)) < 0) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +  } else if ((fd = open(path, O_CREAT | O_TRUNC |
 | 
											
												
													
														|  | 
 |  | +#ifdef _WIN32
 | 
											
												
													
														|  | 
 |  | +                        O_BINARY |
 | 
											
												
													
														|  | 
 |  | +#else
 | 
											
												
													
														|  | 
 |  | +                        O_EXLOCK | O_CLOEXEC |
 | 
											
												
													
														|  | 
 |  | +#endif
 | 
											
												
													
														|  | 
 |  | +                        O_WRONLY)) < 0) {
 | 
											
												
													
														|  |      // We're opening the file with exclusive lock held. This guarantee us that
 |  |      // We're opening the file with exclusive lock held. This guarantee us that
 | 
											
												
													
														|  |      // there is no other thread can save into the same file simultaneously.
 |  |      // there is no other thread can save into the same file simultaneously.
 | 
											
												
													
														|  |      mg_printf(conn, "%s%s", HTTP_500, "Cannot open file");
 |  |      mg_printf(conn, "%s%s", HTTP_500, "Cannot open file");
 |