diff options
author | peter <peter@FreeBSD.org> | 2001-03-28 10:56:11 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2001-03-28 10:56:11 +0000 |
commit | f55b249c528fddf3e03935640093f9f2179592d9 (patch) | |
tree | ccca62d7fe2febd6b8ad2b16701afd46d8a90df7 /lib/libc/gen/glob.c | |
parent | 4291c583b1931d0cb00695193e0d5f3800010a13 (diff) | |
download | FreeBSD-src-f55b249c528fddf3e03935640093f9f2179592d9.zip FreeBSD-src-f55b249c528fddf3e03935640093f9f2179592d9.tar.gz |
OpenBSD's g_Ctoc() returned a false error when the target buffer was
exactly the right size. Do it differently - pass a length rather than an
end-of-string+1 pointer as this is more convenient anyway. Get rid of
the bogus +1's.
Diffstat (limited to 'lib/libc/gen/glob.c')
-rw-r--r-- | lib/libc/gen/glob.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 9603496..7d5eaab 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -131,7 +131,7 @@ typedef char Char; static int compare __P((const void *, const void *)); -static int g_Ctoc __P((const Char *, char *, char *)); +static int g_Ctoc __P((const Char *, char *, u_int)); static int g_lstat __P((Char *, struct stat *, glob_t *)); static DIR *g_opendir __P((Char *, glob_t *)); static Char *g_strchr __P((Char *, int)); @@ -603,7 +603,7 @@ glob3(pathbuf, pathend, pattern, restpattern, pglob, limit) if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { /* TODO: don't call for ENOENT or ENOTDIR? */ if (pglob->gl_errfunc) { - if (g_Ctoc(pathbuf, buf, buf + sizeof(buf))) + if (g_Ctoc(pathbuf, buf, sizeof(buf))) return (GLOB_ABEND); if (pglob->gl_errfunc(buf, errno) || pglob->gl_flags & GLOB_ERR) @@ -698,8 +698,8 @@ globextend(path, pglob, limit) for (p = path; *p++;) continue; len = (size_t)(p - path); - if ((copy = malloc(len + 1)) != NULL) { - if (g_Ctoc(path, copy, copy + len + 1)) { + if ((copy = malloc(len)) != NULL) { + if (g_Ctoc(path, copy, len)) { free(copy); return (GLOB_NOSPACE); } @@ -792,7 +792,7 @@ g_opendir(str, pglob) if (!*str) strcpy(buf, "."); else { - if (g_Ctoc(str, buf, buf + sizeof(buf))) + if (g_Ctoc(str, buf, sizeof(buf))) return (NULL); } @@ -810,7 +810,7 @@ g_lstat(fn, sb, pglob) { char buf[MAXPATHLEN]; - if (g_Ctoc(fn, buf, buf + sizeof(buf))) { + if (g_Ctoc(fn, buf, sizeof(buf))) { errno = ENAMETOOLONG; return (-1); } @@ -827,7 +827,7 @@ g_stat(fn, sb, pglob) { char buf[MAXPATHLEN]; - if (g_Ctoc(fn, buf, buf + sizeof(buf))) { + if (g_Ctoc(fn, buf, sizeof(buf))) { errno = ENAMETOOLONG; return (-1); } @@ -867,17 +867,17 @@ g_strcat(dst, src) #endif static int -g_Ctoc(str, buf, ebuf) - register const Char *str; - char *buf, *ebuf; +g_Ctoc(str, buf, len) + const Char *str; + char *buf; + u_int len; { - register char *dc; - for (dc = buf; dc < ebuf && (*dc++ = *str++) != EOS;) - continue; - if (dc >= ebuf) - return (1); - return (0); + while (len--) { + if ((*buf++ = *str++) == '\0') + return (0); + } + return (1); } #ifdef DEBUG |