Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2007-10-11 20:26:19 +0400
committerCorinna Vinschen <corinna@vinschen.de>2007-10-11 20:26:19 +0400
commit2da0e375199d43e545eb445765c11527cbaa6ad3 (patch)
treed6771d4eeb74896f2f5d976c30f678934da1f3b9 /winsup
parent044b62c7676d56bcabea5956cae38771eb5b2179 (diff)
* path.cc (basename): Return pointer into the path argument itself.
Shrink buf to 4 bytes. Use buf only for border cases. (dirname): Ditto.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/path.cc36
2 files changed, 27 insertions, 15 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index b47e7529e..3a2e9c274 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,9 @@
+2007-10-11 Corinna Vinschen <corinna@vinschen.de>
+
+ * path.cc (basename): Return pointer into the path argument itself.
+ Shrink buf to 4 bytes. Use buf only for border cases.
+ (dirname): Ditto.
+
2007-10-10 Corinna Vinschen <corinna@vinschen.de>
* path.cc (struct symlink_info): Change size of contents member to
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 82be4df3e..aacf0578e 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -4694,15 +4694,14 @@ etc::file_changed (int n)
extern "C" char *
basename (char *path)
{
- static char buf[CYG_MAX_PATH];
- char *c, *d, *bs = buf;
+ static char buf[4];
+ char *c, *d, *bs = path;
if (!path || !*path)
return strcpy (buf, ".");
- strncpy (buf, path, CYG_MAX_PATH);
- if (isalpha (buf[0]) && buf[1] == ':')
+ if (isalpha (path[0]) && path[1] == ':')
bs += 2;
- else if (strspn (buf, "/\\") > 1)
+ else if (strspn (path, "/\\") > 1)
++bs;
c = strrchr (bs, '/');
if ((d = strrchr (c ?: bs, '\\')) > c)
@@ -4720,9 +4719,13 @@ basename (char *path)
if (c && (c > bs || c[1]))
return c + 1;
}
- else if (!bs[0])
- strcpy (bs, ".");
- return buf;
+ else if (!bs[0])
+ {
+ stpncpy (buf, path, bs - path);
+ stpcpy (buf + (bs - path), ".");
+ return buf;
+ }
+ return path;
}
/* No need to be reentrant or thread-safe according to SUSv3.
@@ -4732,15 +4735,14 @@ basename (char *path)
extern "C" char *
dirname (char *path)
{
- static char buf[CYG_MAX_PATH];
- char *c, *d, *bs = buf;
+ static char buf[4];
+ char *c, *d, *bs = path;
if (!path || !*path)
return strcpy (buf, ".");
- strncpy (buf, path, CYG_MAX_PATH);
- if (isalpha (buf[0]) && buf[1] == ':')
+ if (isalpha (path[0]) && path[1] == ':')
bs += 2;
- else if (strspn (buf, "/\\") > 1)
+ else if (strspn (path, "/\\") > 1)
++bs;
c = strrchr (bs, '/');
if ((d = strrchr (c ?: bs, '\\')) > c)
@@ -4767,6 +4769,10 @@ dirname (char *path)
c[1] = '\0';
}
else
- strcpy (bs, ".");
- return buf;
+ {
+ stpncpy (buf, path, bs - path);
+ stpcpy (buf + (bs - path), ".");
+ return buf;
+ }
+ return path;
}