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:
Diffstat (limited to 'tinydir.h')
-rw-r--r--tinydir.h53
1 files changed, 32 insertions, 21 deletions
diff --git a/tinydir.h b/tinydir.h
index d819700..80e362e 100644
--- a/tinydir.h
+++ b/tinydir.h
@@ -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)
{