diff options
author | Cong <congusbongus@gmail.com> | 2016-04-02 15:42:32 +0300 |
---|---|---|
committer | Cong <congusbongus@gmail.com> | 2016-04-02 15:42:32 +0300 |
commit | 70a380bf70824bb7e0a819f7da08c49f6bd4083c (patch) | |
tree | a4e3d891d0804ce97f65b9a15d44b201c0c4819f | |
parent | 65dc3812c25df15247224fdd4994f865caba6bb2 (diff) |
Remove trailing slashes from path
-rw-r--r-- | samples/.gitignore | 4 | ||||
-rwxr-xr-x | tinydir.h | 16 |
2 files changed, 17 insertions, 3 deletions
diff --git a/samples/.gitignore b/samples/.gitignore index a74f38d..a948f88 100644 --- a/samples/.gitignore +++ b/samples/.gitignore @@ -36,3 +36,7 @@ Win32/ # Linux Makefile + +# OS X +CMakeScripts/ +*.xcodeproj @@ -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; |