[Python-Dev] Special file "nul" in Windows and os.stat

Thomas Heller theller at ctypes.org
Tue Oct 30 21:41:22 CET 2007


Chris Mellon schrieb:
> On Oct 24, 2007 11:05 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
>> > So, the question is what we should do?:
>>
>> Before this question can be answered, I think we need to fully
>> understand what precisely is happening in 2.4, and what precisely
>> is happening in 2.5.
>>
>> AFAICT, it is *not* the case that Python 2.4 (indirectly) has
>> hard-coded the names CON, PRN, NUL etc. in the C library. Instead,
>> Python 2.4 *also* relies on kernel32 functions to determine that
>> these files "exist".
>>
>> My question now is what specific kernel32 functions Python 2.4
>> calls to determine that NUL is a file; before that question
>> is sufficiently answered, I don't think any action should be
>> taken.
>>
> 
> 
> os.path.exist() in win32 just calls os.stat() and decides it doesn't
> exist if an error is returned. os.stat() uses the vcrt stat()in 2.4,
> but 2.5 implements it directly in terms of win32 api to deal with
> limitations in the vcrt implementation.
> 
> The hand-rolled stat uses GetFileAttributesEx, which returns 0 for the
> special filenames, with an error code of "The parameter is incorrect"
> (87), which is why os.path.exists() claims it doesn't exist.
> 
> Interestingly, plain old GetFileAttributes() works, and returns
> FILE_ATTRIBUTE_ARCHIVE for them.

See also a recent blog entry of Raymond Chen at
http://blogs.msdn.com/oldnewthing/archive/2007/10/23/5612082.aspx

Thomas



More information about the Python-Dev mailing list