Skip to content
Snippets Groups Projects
Commit 0263e395 authored by Sergey Lyubka's avatar Sergey Lyubka
Browse files

Minor refactoring

parent d8424726
No related branches found
No related tags found
No related merge requests found
......@@ -10,14 +10,9 @@
#include <io.h>
#define strtoll strtol
typedef __int64 int64_t;
#define O_CLOEXEC 0
#define O_EXLOCK 0
#else
#include <inttypes.h>
#include <unistd.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
#endif // !_WIN32
#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");
} else if (cl <= 0) {
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
// there is no other thread can save into the same file simultaneously.
mg_printf(conn, "%s%s", HTTP_500, "Cannot open file");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment