This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [1.7][python] File operation API to multibyte filenames fails.


2009/5/9 Corinna Vinschen <corinna-cygwin@cygwin.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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]