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:
authorYaakov Selkowitz <yselkowi@redhat.com>2015-03-26 08:20:15 +0300
committerCorinna Vinschen <corinna@vinschen.de>2015-04-23 22:57:08 +0300
commit75d5f68aabf62c42884ff935f888b12bbcd00001 (patch)
tree9ca1bf01504bd31f3a182b317d8c2791dfa94dbc /winsup
parentd67052321ec17d82bd7da35ae3fd87eecd7b376f (diff)
cygwin: add GNU basename(3)
winsup/cygwin/ * common.din (__gnu_basename): Export. * path.cc (__gnu_basename): New function. winsup/doc/ * posix.xml (std-gnu): Add basename. (std-notes): Add note about two forms of basename.
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/ChangeLog5
-rw-r--r--winsup/cygwin/common.din1
-rw-r--r--winsup/cygwin/path.cc28
-rw-r--r--winsup/doc/ChangeLog5
-rw-r--r--winsup/doc/posix.xml6
5 files changed, 44 insertions, 1 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 7e925995f..72d15278c 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-30 Yaakov Selkowitz <yselkowi@redhat.com>
+
+ * common.din (__gnu_basename): Export.
+ * path.cc (__gnu_basename): New function.
+
2015-03-30 Corinna Vinschen <corinna@vinschen.de>
* cygheap.h (cygheap_domain_info::add_domain): Add prototype.
diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 42098ff30..f14b33107 100644
--- a/winsup/cygwin/common.din
+++ b/winsup/cygwin/common.din
@@ -61,6 +61,7 @@ __fsetlocking SIGFE
__fwritable NOSIGFE
__fwriting NOSIGFE
__getreent NOSIGFE
+__gnu_basename NOSIGFE
__infinity NOSIGFE
__isinfd NOSIGFE
__isinff NOSIGFE
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 47c687fb7..b05333fd7 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -48,6 +48,7 @@
c: means c:\.
*/
+#define _BASENAME_DEFINED
#include "winsup.h"
#include "miscfuncs.h"
#include <ctype.h>
@@ -4767,6 +4768,33 @@ basename (char *path)
return path;
}
+/* The differences with the POSIX version above:
+ - declared in <string.h> (instead of <libgen.h>);
+ - the argument is never modified, and therefore is marked const;
+ - the empty string is returned if path is an empty string, "/", or ends
+ with a trailing slash. */
+extern "C" char *
+__gnu_basename (const char *path)
+{
+ static char buf[1];
+ char *c, *d, *bs = (char *)path;
+
+ if (!path || !*path)
+ return strcpy (buf, "");
+ if (isalpha (path[0]) && path[1] == ':')
+ bs += 2;
+ else if (strspn (path, "/\\") > 1)
+ ++bs;
+ c = strrchr (bs, '/');
+ if ((d = strrchr (c ?: bs, '\\')) > c)
+ c = d;
+ if (c)
+ return c + 1;
+ else if (!bs[0])
+ return strcpy (buf, "");
+ return (char *)path;
+}
+
/* 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
diff --git a/winsup/doc/ChangeLog b/winsup/doc/ChangeLog
index 814e65156..4f923b6e2 100644
--- a/winsup/doc/ChangeLog
+++ b/winsup/doc/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-30 Yaakov Selkowitz <yselkowi@redhat.com>
+
+ * posix.xml (std-gnu): Add basename.
+ (std-notes): Add note about two forms of basename.
+
2015-03-13 Jon TURNEY <jon.turney@dronecode.org.uk>
* Makefile.in (prefix): Define.
diff --git a/winsup/doc/posix.xml b/winsup/doc/posix.xml
index 5df808b58..95bc4008c 100644
--- a/winsup/doc/posix.xml
+++ b/winsup/doc/posix.xml
@@ -50,7 +50,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
atoi
atol
atoll
- basename
+ basename (see chapter "Implementation Notes")
bind
bsearch
btowc
@@ -1139,6 +1139,7 @@ also IEEE Std 1003.1-2008 (POSIX.1-2008).</para>
asnprintf
asprintf
asprintf_r
+ basename (see chapter "Implementation Notes")
canonicalize_file_name
dremf
dup3
@@ -1603,6 +1604,9 @@ group quotas, no inode quotas, no time constraints.</para>
<para><function>qsort_r</function> is available in both BSD and GNU flavors,
depending on whether _BSD_SOURCE or _GNU_SOURCE is defined when compiling.</para>
+<para><function>basename</function> is available in both POSIX and GNU flavors,
+depending on whether libgen.h is included or not.</para>
+
</sect1>
</chapter>