diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-01 03:12:21 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-02-01 03:12:21 +0000 |
commit | e4b53b22228d935847b72e8f9ab0f49a15b54215 (patch) | |
tree | ae6cd78921bf626d54145b5485474bf59c3dceb4 /dir.c | |
parent | 005f12582975d8382851b740690f97dba35aaa2a (diff) |
2000-02-01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -510,7 +510,7 @@ extract_path(p, pend) len = pend - p; alloc = ALLOC_N(char, len+1); memcpy(alloc, p, len); - if (len > 0 && pend[-1] == '/') { + if (len > 1 && pend[-1] == '/') { alloc[len-1] = 0; } else { @@ -584,19 +584,21 @@ glob(path, func, arg) free(base); break; } +#define BASE (*base && !(*base == '/' && !base[1])) + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { if (recursive) { if (strcmp(".", dp->d_name) == 0 || strcmp("..", dp->d_name) == 0) continue; buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+strlen(m)+6); - sprintf(buf, "%s%s%s/**%s", base, (*base)?"/":"", dp->d_name, m); + sprintf(buf, "%s%s%s/**%s", base, (BASE)?"/":"", dp->d_name, m); glob(buf, func, arg); free(buf); continue; } if (fnmatch(magic, dp->d_name, FNM_PERIOD|FNM_PATHNAME) == 0) { buf = ALLOC_N(char, strlen(base)+NAMLEN(dp)+2); - sprintf(buf, "%s%s%s", base, (*base)?"/":"", dp->d_name); + sprintf(buf, "%s%s%s", base, (BASE)?"/":"", dp->d_name); if (!m) { (*func)(buf, arg); free(buf); |