Skip to content

Commit 1661606

Browse files
author
hewei.it
committed
fix F_OK for windows
1 parent cc20b66 commit 1661606

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ endif()
212212

213213
if(BUILD_EXAMPLES)
214214
add_subdirectory(examples)
215-
file(INSTALL etc DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
215+
# for httpd -c etc/httpd.conf
216+
file(INSTALL etc DESTINATION ${CMAKE_BINARY_DIR})
217+
file(INSTALL etc DESTINATION ${CMAKE_BINARY_DIR}/bin)
218+
file(INSTALL etc DESTINATION ${CMAKE_BINARY_DIR}/examples)
216219
endif()
217220

218221
if(BUILD_UNITTEST)

base/hbase.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,19 @@ int hv_rmdir_p(const char* dir) {
241241
}
242242

243243
bool hv_exists(const char* path) {
244-
return access(path, F_OK) == 0;
244+
return access(path, 0) == 0;
245245
}
246246

247247
bool hv_isdir(const char* path) {
248-
if (access(path, F_OK) != 0) return false;
248+
if (access(path, 0) != 0) return false;
249249
struct stat st;
250250
memset(&st, 0, sizeof(st));
251251
stat(path, &st);
252252
return S_ISDIR(st.st_mode);
253253
}
254254

255255
bool hv_isfile(const char* path) {
256-
if (access(path, F_OK) != 0) return false;
256+
if (access(path, 0) != 0) return false;
257257
struct stat st;
258258
memset(&st, 0, sizeof(st));
259259
stat(path, &st);

cpputil/hpath.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include "hpath.h"
22

33
bool HPath::exists(const char* path) {
4-
return access(path, F_OK) == 0;
4+
return access(path, 0) == 0;
55
}
66

77
bool HPath::isdir(const char* path) {
8-
if (access(path, F_OK) != 0) return false;
8+
if (access(path, 0) != 0) return false;
99
struct stat st;
1010
memset(&st, 0, sizeof(st));
1111
stat(path, &st);
1212
return S_ISDIR(st.st_mode);
1313
}
1414

1515
bool HPath::isfile(const char* path) {
16-
if (access(path, F_OK) != 0) return false;
16+
if (access(path, 0) != 0) return false;
1717
struct stat st;
1818
memset(&st, 0, sizeof(st));
1919
stat(path, &st);

http/server/FileCache.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,25 @@ file_cache_ptr FileCache::Open(const char* filepath, OpenParam* param) {
3434
#endif
3535
int fd = open(filepath, flags);
3636
if (fd < 0) {
37+
#ifdef OS_WIN
38+
// NOTE: open(dir) return -1 on windows
39+
if (!hv_isdir(filepath)) {
40+
param->error = ERR_OPEN_FILE;
41+
return NULL;
42+
}
43+
#else
3744
param->error = ERR_OPEN_FILE;
3845
return NULL;
46+
#endif
3947
}
40-
defer(close(fd);)
48+
defer(if (fd > 0) { close(fd); })
4149
if (fc == NULL) {
4250
struct stat st;
43-
fstat(fd, &st);
51+
if (fd > 0) {
52+
fstat(fd, &st);
53+
} else {
54+
stat(filepath, &st);
55+
}
4456
if (S_ISREG(st.st_mode) ||
4557
(S_ISDIR(st.st_mode) &&
4658
filepath[strlen(filepath)-1] == '/')) {

0 commit comments

Comments
 (0)