X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/1f2f436a38f7ae2d39a943ad2898d8fed4ed2e58..aa54d2fad3d9038b43475aa93c76795c5141a993:/gen/FreeBSD/dirname.c diff --git a/gen/FreeBSD/dirname.c b/gen/FreeBSD/dirname.c index 551d068..7def49a 100644 --- a/gen/FreeBSD/dirname.c +++ b/gen/FreeBSD/dirname.c @@ -26,17 +26,10 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/dirname.c,v 1.8 2008/11/03 05:19:45 delphij #include char * -dirname(const char *path) +dirname_r(const char *path, char *dname) { - static char *dname = NULL; - size_t len; const char *endp; - - if (dname == NULL) { - dname = (char *)malloc(MAXPATHLEN); - if (dname == NULL) - return(NULL); - } + size_t len; /* Empty or NULL string gets treated as "." */ if (path == NULL || *path == '\0') { @@ -71,7 +64,24 @@ dirname(const char *path) errno = ENAMETOOLONG; return (NULL); } - memcpy(dname, path, len); + memmove(dname, path, len); dname[len] = '\0'; return (dname); } + +#if __DARWIN_UNIX03 +#define const /**/ +#endif + +char * +dirname(const char *path) +{ + static char *dname = NULL; + + if (dname == NULL) { + dname = (char *)malloc(MAXPATHLEN); + if (dname == NULL) + return (NULL); + } + return (dirname_r(path, dname)); +}