mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-11 21:53:57 +00:00
Fix #1933 on Linux and macOS
This commit is contained in:
parent
9f8db2c230
commit
de36ea7755
26
httplib.h
26
httplib.h
@ -2470,12 +2470,12 @@ private:
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
HANDLE hFile_ = NULL;
|
HANDLE hFile_ = NULL;
|
||||||
HANDLE hMapping_ = NULL;
|
HANDLE hMapping_ = NULL;
|
||||||
bool is_open_empty_file_on_windows_ = false;
|
|
||||||
#else
|
#else
|
||||||
int fd_ = -1;
|
int fd_ = -1;
|
||||||
#endif
|
#endif
|
||||||
size_t size_ = 0;
|
size_t size_ = 0;
|
||||||
void *addr_ = nullptr;
|
void *addr_ = nullptr;
|
||||||
|
bool is_open_empty_file = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@ -2940,10 +2940,10 @@ inline bool mmap::open(const char *path) {
|
|||||||
hMapping_ = ::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, 0, 0, NULL);
|
hMapping_ = ::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: Special treatment for an empty file on Windows... (#1933)
|
// Special treatment for an empty file...
|
||||||
if (hMapping_ == NULL && size_ == 0) {
|
if (hMapping_ == NULL && size_ == 0) {
|
||||||
close();
|
close();
|
||||||
is_open_empty_file_on_windows_ = true;
|
is_open_empty_file = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2975,8 +2975,10 @@ inline bool mmap::open(const char *path) {
|
|||||||
|
|
||||||
addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);
|
addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);
|
||||||
|
|
||||||
if (addr_ == MAP_FAILED) {
|
// Special treatment for an empty file...
|
||||||
|
if (addr_ == MAP_FAILED && size_ == 0) {
|
||||||
close();
|
close();
|
||||||
|
is_open_empty_file = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2985,23 +2987,13 @@ inline bool mmap::open(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline bool mmap::is_open() const {
|
inline bool mmap::is_open() const {
|
||||||
#if defined(_WIN32)
|
return is_open_empty_file ? true : addr_ != nullptr;
|
||||||
if (is_open_empty_file_on_windows_) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return addr_ != nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t mmap::size() const { return size_; }
|
inline size_t mmap::size() const { return size_; }
|
||||||
|
|
||||||
inline const char *mmap::data() const {
|
inline const char *mmap::data() const {
|
||||||
#if defined(_WIN32)
|
return is_open_empty_file ? "" : static_cast<const char *>(addr_);
|
||||||
if (is_open_empty_file_on_windows_) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return static_cast<const char *>(addr_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void mmap::close() {
|
inline void mmap::close() {
|
||||||
@ -3021,7 +3013,7 @@ inline void mmap::close() {
|
|||||||
hFile_ = INVALID_HANDLE_VALUE;
|
hFile_ = INVALID_HANDLE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_open_empty_file_on_windows_ = false;
|
is_open_empty_file = false;
|
||||||
#else
|
#else
|
||||||
if (addr_ != nullptr) {
|
if (addr_ != nullptr) {
|
||||||
munmap(addr_, size_);
|
munmap(addr_, size_);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user