[PATCH] cygwin: add GNU basename(3)

2015-03-25 Thread Yaakov Selkowitz
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 
@@ -4767,6 +4768,33 @@ basename (char *path)
   return path;
 }
 
+/* The differences with the POSIX version above:
+   - declared in  (instead of );
+   - 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).
 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).
 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.
 qsort_r is available in both BSD and GNU flavors,
 depending on whether _BSD_SOURCE or _GNU_SOURCE is defined when 
compiling.
 
+basename is available in both POSIX and GNU flavors,
+depending on whether libgen.h is included or not.
+
 
 
 
-- 
2.1.4



Re: TIOCPKT mode of PTY is broken if ONLCR bit is cleared.

2015-03-25 Thread Corinna Vinschen
On Mar 25 20:42, Takashi Yano wrote:
> Dear cygwin developers,
> 
> Regarding this (http://cygwin.com/ml/cygwin/2015-02/msg00929.html)
> problem, I made a patch attached.

Patch applied, thank you.  Btw., there's a Freenode IRC channel
#cygwin-developers.  Feel free to join.


Thanks,
Corinna

-- 
Corinna Vinschen  Please, send mails regarding Cygwin to
Cygwin Maintainer cygwin AT cygwin DOT com
Red Hat


pgpYS39MDks1r.pgp
Description: PGP signature


Re: TIOCPKT mode of PTY is broken if ONLCR bit is cleared.

2015-03-25 Thread Takashi Yano
Dear cygwin developers,

Regarding this (http://cygwin.com/ml/cygwin/2015-02/msg00929.html)
problem, I made a patch attached.

I have posted the patch to this ML with Corinna's directions.

On Mon, 23 Mar 2015 11:08:23 +0100
Corinna Vinschen  wrote:

> However, due to the changes in fhandler_tty.cc, this patch doesn't
> apply cleanly anymore.  Any chance you could resend it (ideally to the
> cygwin-patches ML) diff'ed against git HEAD?

Please find a revised patch attached to this mail.

ChangeLog is as follows:

2015-03-25  Takashi Yano 

* tty.h (class tty_min): Remove variable "write_error" to which any
errors are not currently set at anywhere.
(class tty): Add variable "column" for handling ONOCR.
* tty.cc (tty::init): Add initialization code for variable "column".
* fhandler.h (class fhandler_pty_master): Remove variable "need_nl"
which is not necessary any more. "need_nl" was needed by OPOST process
in fhandler_pty_master::process_slave_output().
(class fhandler_pty_common): Add function process_opost_output() for
handling post processing for OPOST in write process.
* fhandler_tty.cc (fhandler_pty_master::process_slave_output): Count
TIOCPKT control byte into length to be read in TIOCPKT mode. Move
post processing for OPOST to write process. Remove code related to
variable "write_error". Return with EIO error if slave is already
closed.
(fhandler_pty_master::fhandler_pty_master): Remove initialization
code for variable "need_nl".
(fhandler_pty_common::process_opost_output): Add this function for
handling of OPOST in write process. Add code to avoid blocking in
non-blocking mode when output is suspended by ^S.
(fhandler_pty_slave::write): Call fhandler_pty_common::
process_opost_output() instead of WriteFile(). Remove code related to
variable "write_error". 
(fhandler_pty_master::doecho): Call fhandler_pty_common::
 process_opost_output() instead of WriteFile().
* select.cc (peek_pipe): Remove code related to variable "need_nl".

Best regards,
Takashi Yano

-- 
Takashi Yano 


cygwin.patch.20150325
Description: Binary data