diff options
author | Cong <congusbongus@gmail.com> | 2019-11-29 02:18:08 +0300 |
---|---|---|
committer | Cong <congusbongus@gmail.com> | 2019-11-29 02:18:08 +0300 |
commit | 19a8148c3cc3e8ed941287072dd4f981e019fb11 (patch) | |
tree | 60222ec2342f4003b64e366fd731d60ab7e7da18 | |
parent | 5d907978e1e6f2a3b0ad8d51fa186d6fda863ea6 (diff) |
Implement tinydir_file_open for drive root (fixes #66)
-rw-r--r-- | samples/.gitignore | 2 | ||||
-rw-r--r-- | tinydir.h | 53 |
2 files changed, 34 insertions, 21 deletions
diff --git a/samples/.gitignore b/samples/.gitignore index bc406f8..da0c473 100644 --- a/samples/.gitignore +++ b/samples/.gitignore @@ -24,7 +24,9 @@ CMakeCache.txt cmake_install.cmake # Visual Studio +.vs/ Debug/ +out/ Win32/ *.opensdf *.sdf @@ -1,5 +1,5 @@ /* -Copyright (c) 2013-2018, tinydir authors: +Copyright (c) 2013-2019, tinydir authors: - Cong Xu - Lautis Sun - Baudouin Feildel @@ -657,32 +657,32 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path) /* Get the parent path */ #if (defined _MSC_VER || defined __MINGW32__) #if ((defined _MSC_VER) && (_MSC_VER >= 1400)) - errno = _tsplitpath_s( - path, - drive_buf, _TINYDIR_DRIVE_MAX, - dir_name_buf, _TINYDIR_FILENAME_MAX, - file_name_buf, _TINYDIR_FILENAME_MAX, - ext_buf, _TINYDIR_FILENAME_MAX); + errno = _tsplitpath_s( + path, + drive_buf, _TINYDIR_DRIVE_MAX, + dir_name_buf, _TINYDIR_FILENAME_MAX, + file_name_buf, _TINYDIR_FILENAME_MAX, + ext_buf, _TINYDIR_FILENAME_MAX); #else - _tsplitpath( - path, - drive_buf, - dir_name_buf, - file_name_buf, - ext_buf); + _tsplitpath( + path, + drive_buf, + dir_name_buf, + file_name_buf, + ext_buf); #endif -if (errno) -{ - return -1; -} + if (errno) + { + return -1; + } /* _splitpath_s not work fine with only filename and widechar support */ #ifdef _UNICODE - if (drive_buf[0] == L'\xFEFE') - drive_buf[0] = '\0'; - if (dir_name_buf[0] == L'\xFEFE') - dir_name_buf[0] = '\0'; + if (drive_buf[0] == L'\xFEFE') + drive_buf[0] = '\0'; + if (dir_name_buf[0] == L'\xFEFE') + dir_name_buf[0] = '\0'; #endif /* Emulate the behavior of dirname by returning "." for dir name if it's @@ -704,6 +704,17 @@ if (errno) base_name =basename(file_name_buf); #endif + /* Special case: if the path is a root dir, open the parent dir as the file */ + if (_tinydir_strlen(base_name) == 0) + { + memset(file, 0, sizeof * file); + file->is_dir = 1; + file->is_reg = 0; + _tinydir_strcpy(file->path, dir_name); + file->extension = file->path + _tinydir_strlen(file->path); + return 0; + } + /* Open the parent directory */ if (tinydir_open(&dir, dir_name) == -1) { |