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:
authorLautis Sun <lautis0503@gmail.com>2019-12-08 16:04:22 +0300
committerLautis Sun <lautis0503@gmail.com>2019-12-08 16:04:22 +0300
commit97a6032ddb2a8f8033e73be5c4a25b0e3be648f1 (patch)
tree847e766a16efec5d9137eec9370af310cedb446b
parent19a8148c3cc3e8ed941287072dd4f981e019fb11 (diff)
Fix tinydir_file_open for root or subfolder of root in Linux.
-rw-r--r--tinydir.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/tinydir.h b/tinydir.h
index 80e362e..e08eb84 100644
--- a/tinydir.h
+++ b/tinydir.h
@@ -534,7 +534,8 @@ int tinydir_readfile(const tinydir_dir *dir, tinydir_file *file)
}
_tinydir_strcpy(file->path, dir->path);
- _tinydir_strcat(file->path, TINYDIR_STRING("/"));
+ if (_tinydir_strcmp(dir->path, TINYDIR_STRING("/")) != 0)
+ _tinydir_strcat(file->path, TINYDIR_STRING("/"));
_tinydir_strcpy(file->name, filename);
_tinydir_strcat(file->path, filename);
#ifndef _MSC_VER
@@ -701,11 +702,15 @@ int tinydir_file_open(tinydir_file *file, const _tinydir_char_t *path)
_tinydir_strcpy(dir_name_buf, path);
dir_name = dirname(dir_name_buf);
_tinydir_strcpy(file_name_buf, path);
- base_name =basename(file_name_buf);
+ base_name = basename(file_name_buf);
#endif
/* Special case: if the path is a root dir, open the parent dir as the file */
+#if (defined _MSC_VER || defined __MINGW32__)
if (_tinydir_strlen(base_name) == 0)
+#else
+ if ((_tinydir_strcmp(base_name, TINYDIR_STRING("/"))) == 0)
+#endif
{
memset(file, 0, sizeof * file);
file->is_dir = 1;