summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Braun <bbraun@FreeBSD.org>2002-12-21 07:12:35 +0000
committerRob Braun <bbraun@FreeBSD.org>2002-12-21 07:12:35 +0000
commit5fb691beab21abbda50f3c51287b0f89f8a2fc85 (patch)
tree9c962dee5055fb86b745dbe0a830289cfeb0419f /lib
parent2226ce021abb5b86c67ac085787cebfa41f7489a (diff)
Notes
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/basename.c10
-rw-r--r--lib/libc/gen/dirname.c10
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/libc/gen/basename.c b/lib/libc/gen/basename.c
index cbeb1d52ce79..9bd2dc2b2ad4 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);
}
diff --git a/lib/libc/gen/dirname.c b/lib/libc/gen/dirname.c
index 8e287af8ae7e..4e5ecb4ced49 100644
--- a/lib/libc/gen/dirname.c
+++ b/lib/libc/gen/dirname.c
@@ -42,9 +42,15 @@ char *
dirname(path)
const char *path;
{
- static char bname[MAXPATHLEN];
+ static char *bname = NULL;
const char *endp;
+ 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, ".");
@@ -70,7 +76,7 @@ dirname(path)
} while (endp > path && *endp == '/');
}
- if (endp - path + 2 > sizeof(bname)) {
+ if (endp - path + 2 > MAXPATHLEN) {
errno = ENAMETOOLONG;
return(NULL);
}