* [PATCH] cygwin: add GNU basename(3)
@ 2015-03-26 5:25 Yaakov Selkowitz
2015-03-30 10:45 ` Corinna Vinschen
0 siblings, 1 reply; 2+ messages in thread
From: Yaakov Selkowitz @ 2015-03-26 5:25 UTC (permalink / raw)
To: cygwin-patches
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.
---
This depends on the newlib patch currently under discussion.
winsup/cygwin/common.din | 1 +
winsup/cygwin/path.cc | 28 ++++++++++++++++++++++++++++
winsup/doc/posix.xml | 6 +++++-
3 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/common.din b/winsup/cygwin/common.din
index 42098ff..f14b331 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 47c687f..b05333f 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/posix.xml b/winsup/doc/posix.xml
index 5df808b..95bc400 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>
--
2.1.4
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] cygwin: add GNU basename(3)
2015-03-26 5:25 [PATCH] cygwin: add GNU basename(3) Yaakov Selkowitz
@ 2015-03-30 10:45 ` Corinna Vinschen
0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2015-03-30 10:45 UTC (permalink / raw)
To: cygwin-patches
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
On Mar 26 00:25, Yaakov Selkowitz wrote:
> 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.
Patch is ok. Please apply after applying the newlib patch.
Thanks,
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-30 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 5:25 [PATCH] cygwin: add GNU basename(3) Yaakov Selkowitz
2015-03-30 10:45 ` Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).