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-04-02 15:42:32 +0300
committerCong <congusbongus@gmail.com>2016-04-02 15:42:32 +0300
commit70a380bf70824bb7e0a819f7da08c49f6bd4083c (patch)
treea4e3d891d0804ce97f65b9a15d44b201c0c4819f /tinydir.h
parent65dc3812c25df15247224fdd4994f865caba6bb2 (diff)
Remove trailing slashes from path
Diffstat (limited to 'tinydir.h')
-rwxr-xr-xtinydir.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/tinydir.h b/tinydir.h
index 72bb4bc..275e605 100755
--- a/tinydir.h
+++ b/tinydir.h
@@ -175,7 +175,10 @@ int tinydir_open(tinydir_dir *dir, const char *path)
int error;
int size; /* using int size */
#endif
+#else
+ char path_buf[_TINYDIR_PATH_MAX];
#endif
+ char *pathp;
if (dir == NULL || path == NULL || strlen(path) == 0)
{
@@ -201,10 +204,17 @@ int tinydir_open(tinydir_dir *dir, const char *path)
tinydir_close(dir);
strcpy(dir->path, path);
+ /* Remove trailing slashes */
+ pathp = &dir->path[strlen(dir->path) - 1];
+ while (pathp != dir->path && (*pathp == '\\' || *pathp == '/'))
+ {
+ *pathp = '\0';
+ pathp++;
+ }
#ifdef _MSC_VER
- strcat(dir->path, "\\*");
- dir->_h = FindFirstFileA(dir->path, &dir->_f);
- dir->path[strlen(dir->path) - 2] = '\0';
+ strcpy(path_buf, dir->path);
+ strcat(path_buf, "\\*");
+ dir->_h = FindFirstFileA(path_buf, &dir->_f);
if (dir->_h == INVALID_HANDLE_VALUE)
{
errno = ENOENT;