Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/cxong/tinydir.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCong <congusbongus@gmail.com>2016-07-17 06:05:03 +0300
committerCong <congusbongus@gmail.com>2016-07-17 06:05:03 +0300
commite33a1dadc7d8f2cc80e50e992b2a596cde1f00e1 (patch)
treeacf87f08269b01fda60355dc3f76f69ef0ffa6c3
parentfe199959435f04931789ae98cad53a64148c856c (diff)
Fix tinydir_file_open with filename only failure in Windows (fixes #35)
Implement file_open_test for Windows
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/cbehave/cbehave.h2
-rw-r--r--tests/file_open_test.c28
-rw-r--r--tinydir.h6
4 files changed, 31 insertions, 7 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8322d7b..ddf4a6f 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -12,7 +12,7 @@ add_subdirectory(cbehave)
if(MSVC)
add_definitions(-W4 -WX -wd"4127" -wd"4102" -wd"4996")
else()
- add_definitions(-fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wno-unused-label -Wno-unused-parameter)
+ add_definitions(-fsigned-char -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Winline -Werror -Wno-unused-label)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wstrict-prototypes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
diff --git a/tests/cbehave/cbehave.h b/tests/cbehave/cbehave.h
index aeaea99..ae920a6 100644
--- a/tests/cbehave/cbehave.h
+++ b/tests/cbehave/cbehave.h
@@ -157,7 +157,7 @@ if (!(cond)) {\
} while(0)
#define CBEHAVE_RUN(_description, ...)\
-int main(int argc, char *argv[]) {\
+int main() {\
cbehave_feature _cfeatures[] = {__VA_ARGS__};\
return cbehave_runner(_description, _cfeatures);\
}
diff --git a/tests/file_open_test.c b/tests/file_open_test.c
index 0132ba0..dc238c3 100644
--- a/tests/file_open_test.c
+++ b/tests/file_open_test.c
@@ -1,16 +1,34 @@
#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#include <tinydir.h>
#include "cbehave.h"
+static void make_temp_file(const char *prefix, char *out)
+{
+#ifdef _MSC_VER
+ if (GetTempFileName(".", prefix, 0, out) != 0)
+ {
+ // Strip the ".\\" prefix
+ if (strncmp(out, ".\\", 2) == 0)
+ {
+ memmove(out, out + 2, strlen(out));
+ }
+ // Create file
+ fclose(fopen(out, "w"));
+ }
+#else
+ #include <stdlib.h>
+ #include <unistd.h>
+ sprintf(out, "%sXXXXXX", prefix);
+ close(mkstemp(out));
+#endif
+}
+
FEATURE(file_open, "File open")
SCENARIO("Open file in current directory")
GIVEN("a file in the current directory")
- char name[] = "fileXXXXXX";
- int fd = mkstemp(name);
- close(fd);
+ char name[4096];
+ make_temp_file("temp_file_", name);
WHEN("we open it")
tinydir_file file;
int r = tinydir_file_open(&file, name);
diff --git a/tinydir.h b/tinydir.h
index 8a76050..0a9da0c 100644
--- a/tinydir.h
+++ b/tinydir.h
@@ -641,6 +641,12 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
errno = EINVAL;
return -1;
}
+ /* Emulate the behavior of dirname by returning "." for dir name if it's
+ empty */
+ if (drive_buf[0] == '\0' && dir_name_buf[0] == '\0')
+ {
+ strcpy(dir_name_buf, ".");
+ }
/* Concatenate the drive letter and dir name to form full dir name */
_tinydir_strcat(drive_buf, dir_name_buf);
dir_name = drive_buf;