Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit de36ea7

Browse files
committed
Fix yhirose#1933 on Linux and macOS
1 parent 9f8db2c commit de36ea7

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

‎httplib.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,12 +2470,12 @@ class mmap {
24702470
#if defined(_WIN32)
24712471
HANDLE hFile_ = NULL;
24722472
HANDLE hMapping_ = NULL;
2473-
bool is_open_empty_file_on_windows_ = false;
24742473
#else
24752474
int fd_ = -1;
24762475
#endif
24772476
size_t size_ = 0;
24782477
void *addr_ = nullptr;
2478+
bool is_open_empty_file = false;
24792479
};
24802480

24812481
} // namespace detail
@@ -2940,10 +2940,10 @@ inline bool mmap::open(const char *path) {
29402940
hMapping_ = ::CreateFileMappingW(hFile_, NULL, PAGE_READONLY, 0, 0, NULL);
29412941
#endif
29422942

2943-
// TODO: Special treatment for an empty file on Windows... (#1933)
2943+
// Special treatment for an empty file...
29442944
if (hMapping_ == NULL && size_ == 0) {
29452945
close();
2946-
is_open_empty_file_on_windows_ = true;
2946+
is_open_empty_file = true;
29472947
return true;
29482948
}
29492949

@@ -2975,8 +2975,10 @@ inline bool mmap::open(const char *path) {
29752975

29762976
addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0);
29772977

2978-
if (addr_ == MAP_FAILED) {
2978+
// Special treatment for an empty file...
2979+
if (addr_ == MAP_FAILED && size_ == 0) {
29792980
close();
2981+
is_open_empty_file = true;
29802982
return false;
29812983
}
29822984
#endif
@@ -2985,23 +2987,13 @@ inline bool mmap::open(const char *path) {
29852987
}
29862988

29872989
inline bool mmap::is_open() const {
2988-
#if defined(_WIN32)
2989-
if (is_open_empty_file_on_windows_) {
2990-
return true;
2991-
}
2992-
#endif
2993-
return addr_ != nullptr;
2990+
return is_open_empty_file ? true : addr_ != nullptr;
29942991
}
29952992

29962993
inline size_t mmap::size() const { return size_; }
29972994

29982995
inline const char *mmap::data() const {
2999-
#if defined(_WIN32)
3000-
if (is_open_empty_file_on_windows_) {
3001-
return "";
3002-
}
3003-
#endif
3004-
return static_cast<const char *>(addr_);
2996+
return is_open_empty_file ? "" : static_cast<const char *>(addr_);
30052997
}
30062998

30072999
inline void mmap::close() {
@@ -3021,7 +3013,7 @@ inline void mmap::close() {
30213013
hFile_ = INVALID_HANDLE_VALUE;
30223014
}
30233015

3024-
is_open_empty_file_on_windows_ = false;
3016+
is_open_empty_file = false;
30253017
#else
30263018
if (addr_ != nullptr) {
30273019
munmap(addr_, size_);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /