delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/05/08/15:22:21

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <20090508160415.GM21324@calimero.vinschen.de>
References: <3f0ad08d0905080602s36a9eddg852eaa3ea3a2a69f AT mail DOT gmail DOT com> <20090508130901 DOT GL21324 AT calimero DOT vinschen DOT de> <3f0ad08d0905080621j2b1f97b9p317ee1df0f1dfc76 AT mail DOT gmail DOT com> <20090508160415 DOT GM21324 AT calimero DOT vinschen DOT de>
Date: Sat, 9 May 2009 04:21:58 +0900
Message-ID: <3f0ad08d0905081221s670f165ap507d74f129954579@mail.gmail.com>
Subject: Re: [1.7][python] File operation API to multibyte filenames fails.
From: IWAMURO Motonori <deenheart AT gmail DOT com>
To: cygwin AT cygwin DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

2009/5/9 Corinna Vinschen <corinna-cygwin AT cygwin DOT com>:
> can't see a fault in Cygwin. Neither from strace, nor in a GDB session.
> The readdir calls return the filenames using the SO sequences so that
> a valid byte-stream is created which also works in the C locale.
> However, for some reason there's a EILSEQ (138) errno generated, but
> from what I can tell it's not generated in Cygwin or newlib code.

I think that I found Cygwin-1.7's bug.

> int bytes = f_wctomb (_REENT, buf, pw, charset, &ps);

f_wctomb is __ascii_wctomb when not using setlocale(LC_CTYPE).
If return value of __ascii_wctomb == -1, errno == EILSEQ.

I think that it is necessary to reset errno after wctomb.

--- a/winsup/cygwin/strfuncs.cc Thu May 07 12:29:17 2009 +0900
+++ b/winsup/cygwin/strfuncs.cc Sat May 09 04:01:33 2009 +0900
@@ -432,6 +432,7 @@
          ASCII SO; UTF-8 representation of invalid char. */
       if (bytes == -1 && *charset != 'U'/*TF-8*/)
         {
+         errno = 0;
          buf[0] = 0x0e; /* ASCII SO */
          bytes = __utf8_wctomb (_REENT, buf + 1, pw, charset, &ps);
          if (bytes == -1)

[test code]
#include <stdio.h>
#include <dirent.h>
#include <errno.h>

int main(void) {
  DIR *dir;
  struct dirent *ent;
  dir = opendir(".");
  while ((ent = readdir(dir)) != NULL)
    printf("%d\n", ent->d_name, errno);
  printf("%d\n", errno);
  closedir(dir);
  return 0;
}

[result 1.7.0-47]
0
0
138
138
138

[result applied above patch]
0
0
0
0
0
-- 
IWAMURO Motnori <http://vmi.jp/>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019