summaryrefslogtreecommitdiffstats
path: root/winsup
diff options
context:
space:
mode:
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/cygwin.din2
-rw-r--r--winsup/cygwin/include/cygwin/version.h3
-rw-r--r--winsup/cygwin/include/libgen.h23
-rw-r--r--winsup/cygwin/path.cc85
5 files changed, 121 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 1752775cb..9aec7efa0 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,14 @@
2005-02-22 Corinna Vinschen <corinna@vinschen.de>
+ * cygwin.din (basename): Export.
+ (dirname): Export.
+ * path.cc (basename): New function.
+ (dirname): New function.
+ * include/libgen.h: New file.
+ * include/cygwin/version.h: Bump API minor version.
+
+2005-02-22 Corinna Vinschen <corinna@vinschen.de>
+
* select.cc (peek_pipe): Disable new pipe code until there's
a working substitute.
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index fe4730ed8..877a544dc 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -210,6 +210,7 @@ _atoi = atoi NOSIGFE
atol NOSIGFE
_atol = atol NOSIGFE
atoll NOSIGFE
+basename SIGFE
bcmp NOSIGFE
_bcmp = bcmp NOSIGFE
bcopy NOSIGFE
@@ -369,6 +370,7 @@ difftime NOSIGFE
_difftime = difftime NOSIGFE
dirfd SIGFE
_dirfd = dirfd SIGFE
+dirname SIGFE
div NOSIGFE
_div = div NOSIGFE
dlclose SIGFE
diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h
index cb1294f0a..fac4ea2ea 100644
--- a/winsup/cygwin/include/cygwin/version.h
+++ b/winsup/cygwin/include/cygwin/version.h
@@ -247,12 +247,13 @@ details. */
117: Export utmpx functions, Return utmp * from pututent.
118: Export getpriority, setpriority.
119: Export fdatasync.
+ 120: Export basename, dirname.
*/
/* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
#define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 119
+#define CYGWIN_VERSION_API_MINOR 120
/* There is also a compatibity version number associated with the
shared memory regions. It is incremented when incompatible
diff --git a/winsup/cygwin/include/libgen.h b/winsup/cygwin/include/libgen.h
new file mode 100644
index 000000000..f5c24a8cc
--- /dev/null
+++ b/winsup/cygwin/include/libgen.h
@@ -0,0 +1,23 @@
+/* libgen.h
+
+ Copyright 2005 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _LIBGEN_H
+#define _LIBGEN_H
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+extern char *basename (char *path);
+extern char *dirname (char *path);
+
+__END_DECLS
+
+#endif /* _LIBGEN_H */
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index c7f8721bd..0615077b8 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -53,6 +53,7 @@ details. */
#include <sys/mount.h>
#include <mntent.h>
#include <unistd.h>
+#include <libgen.h>
#include <ctype.h>
#include <winioctl.h>
#include <wingdi.h>
@@ -3930,3 +3931,87 @@ etc::file_changed (int n)
paranoid_printf ("fn[%d] %s res %d", n, fn[n], res);
return res;
}
+
+/* No need to be reentrant or thread-safe according to SUSv3.
+ / and \\ are treated equally. Leading drive specifiers are
+ kept intact as far as it makes sense. Everything else is
+ POSIX compatible. */
+extern "C" char *
+basename (char *path)
+{
+ static char buf[CYG_MAX_PATH + 1];
+ char *c, *d, *bs = buf;
+
+ if (!path || !*path)
+ return strcpy (buf, ".");
+ strncpy (buf, path, CYG_MAX_PATH);
+ if (isalpha (buf[0]) && buf[1] == ':')
+ bs += 2;
+ else if (strspn (buf, "/\\") > 1)
+ ++bs;
+ c = strrchr (bs, '/');
+ if ((d = strrchr (c ?: bs, '\\')) > c)
+ c = d;
+ if (c)
+ {
+ /* Trailing (back)slashes are eliminated. */
+ while (c && c > bs && c[1] == '\0')
+ {
+ *c = '\0';
+ c = strrchr (bs, '/');
+ if ((d = strrchr (c ?: bs, '\\')) > c)
+ c = d;
+ }
+ if (c && (c > bs || c[1]))
+ return c + 1;
+ }
+ else if (!bs[0])
+ strcpy (bs, ".");
+ return buf;
+}
+
+/* No need to be reentrant or thread-safe according to SUSv3.
+ / and \\ are treated equally. Leading drive specifiers and
+ leading double (back)slashes are kept intact as far as it
+ makes sense. Everything else is POSIX compatible. */
+extern "C" char *
+dirname (char *path)
+{
+ static char buf[CYG_MAX_PATH + 1];
+ char *c, *d, *bs = buf;
+
+ if (!path || !*path)
+ return strcpy (buf, ".");
+ strncpy (buf, path, CYG_MAX_PATH);
+ if (isalpha (buf[0]) && buf[1] == ':')
+ bs += 2;
+ else if (strspn (buf, "/\\") > 1)
+ ++bs;
+ c = strrchr (bs, '/');
+ if ((d = strrchr (c ?: bs, '\\')) > c)
+ c = d;
+ if (c)
+ {
+ /* Trailing (back)slashes are eliminated. */
+ while (c && c > bs && c[1] == '\0')
+ {
+ *c = '\0';
+ c = strrchr (bs, '/');
+ if ((d = strrchr (c ?: bs, '\\')) > c)
+ c = d;
+ }
+ if (!c)
+ strcpy (bs, ".");
+ else if (c > bs)
+ {
+ /* More trailing (back)slashes are eliminated. */
+ while (c > bs && (*c == '/' || *c == '\\'))
+ *c-- = '\0';
+ }
+ else
+ c[1] = '\0';
+ }
+ else
+ strcpy (bs, ".");
+ return buf;
+}