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.


Corinna Vinschen wrote:
> On May  9 05:02, IWAMURO Motonori wrote:

>> When the last readdir returns NULL, python detects the error because
>> readdir keeps previous errno.
>>
>> 1) ep = readdir(dirp); // ep->d_name == ".", errno == 0
>>    Python check only ep != NULL. -> OK
>> 2) ep = readdir(dirp); // ep->d_name == "..", errno == 0
>>    Python check only ep != NULL. -> OK
>> 3) ep = readdir(dirp); // ep->d_name == "\xe3\x82...", errno == 138
>>    Python check only ep != NULL. -> OK
>> 4) ep = readdir(dirp); // ep->d_name == "\xe3\x83...", errno == 138
>>    Python check only ep != NULL. -> OK
>> 5) ep = readdir(dirp); // ep == NULL, errno == 138
>>    Python check ep == NULL and errno != 0. -> Fail!
> 
> Ouch, right.  It shows that I'm tired.

  It shows that python is buggy then.  It should be resetting errno itself
before calling readdir, so that it can distinguish between the EOF and error
conditions.

http://www.opengroup.org/onlinepubs/009695399/functions/readdir.html

"  Upon successful completion, readdir() shall return a pointer to an object
of type struct dirent. When an error is encountered, a null pointer shall be
returned and errno shall be set to indicate the error. When the end of the
directory is encountered, a null pointer shall be returned and errno is not
changed.  "

  ... note particularly the "not changed".

  Or perhaps python should test feof/ferror before deciding whether to inspect
errno, but either way it shouldn't just assume that because readdir returns
NULL that implies errno is valid.

    cheers,
      DaveK

--
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]