X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4A04A227.9080505@gmail.com> Date: Fri, 08 May 2009 22:20:39 +0100 From: Dave Korn User-Agent: Thunderbird 2.0.0.17 (Windows/20080914) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: [1.7][python] File operation API to multibyte filenames fails. 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> <3f0ad08d0905081221s670f165ap507d74f129954579 AT mail DOT gmail DOT com> <20090508193905 DOT GO21324 AT calimero DOT vinschen DOT de> <3f0ad08d0905081302p12091827r44e99f04c067df9f AT mail DOT gmail DOT com> <20090508203010 DOT GP21324 AT calimero DOT vinschen DOT de> In-Reply-To: <20090508203010.GP21324@calimero.vinschen.de> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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/