diff options
Diffstat (limited to 'lib/libc/gen/basename.c')
-rw-r--r-- | lib/libc/gen/basename.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/libc/gen/basename.c b/lib/libc/gen/basename.c index cbeb1d5..9bd2dc2 100644 --- a/lib/libc/gen/basename.c +++ b/lib/libc/gen/basename.c @@ -42,9 +42,15 @@ char * basename(path) const char *path; { - static char bname[MAXPATHLEN]; + static char *bname = NULL; const char *endp, *startp; + if (bname == NULL) { + bname = (char *)malloc(MAXPATHLEN); + if (bname == NULL) + return(NULL); + } + /* Empty or NULL string gets treated as "." */ if (path == NULL || *path == '\0') { (void)strcpy(bname, "."); @@ -67,7 +73,7 @@ basename(path) while (startp > path && *(startp - 1) != '/') startp--; - if (endp - startp + 2 > sizeof(bname)) { + if (endp - startp + 2 > MAXPATHLEN) { errno = ENAMETOOLONG; return(NULL); } |