From: tismer at appliedbiometrics.com (Christian Tismer)
Date: Tue, 20 Apr 1999 20:09:42 GMT
Subject: Win32: os.listdir() on a non-existent directory
References: <335a0ac6.114790@news.demon.co.uk>
Message-ID: <371CDF06.9166182D@appliedbiometrics.com>
Content-Length: 2540
X-UID: 1310                                                  

Responding to a thread which is slightly
out of date (exactly 2 years old),
but today we stepped into this again, and nobody
really seemed to take care about it.
Anyway, something must be done, it cannot stay as it is.

Paul Moore wrote:
> 
> I'm running Python 1.4 on Windows 95. If I do
> 
>    import os
>    p = os.listdir("C:\\banana")
> 
> I get
> 
>    Traceback (innermost last):
>      File "<stdin>", line 1, in ?
>    nt.error: (3, 'No such process')

Well, meanwhile this has been changed to os.error, but
the same wrong error message is still there.

The os returns an error message number 3.
This is defined in the Windows Syserr.c file as

#ifdef _WIN32

char *_sys_errlist[] =
{
    /*  0              */  "No error",
    /*  1 EPERM        */  "Operation not permitted",
    /*  2 ENOENT       */  "No such file or directory",
    /*  3 ESRCH        */  "No such process",
    /*  4 EINTR        */  "Interrupted function call",

But, the meaning is different.
What is meant instead is a Unix error message which is mapped
to DOS error messages in the Windows Dosmap.c file:


static struct errentry errtable[] = {
        {  ERROR_INVALID_FUNCTION,       EINVAL    },  /* 1 */
        {  ERROR_FILE_NOT_FOUND,         ENOENT    },  /* 2 */
        {  ERROR_PATH_NOT_FOUND,         ENOENT    },  /* 3 */
        {  ERROR_TOO_MANY_OPEN_FILES,    EMFILE    },  /* 4 */
        {  ERROR_ACCESS_DENIED,          EACCES    },  /* 5 */

What we really get is a correct Unix System V error number.
The error is to take it as-is, without translation to
the internal DOS errors.

Now, MSDN says in "_doserrno, errno, _sys_errlist, and _sys_nerr":

On an error, errno is not necessarily set to the same value as the error
code returned by a system call. For I/O operations only, use _doserrno
to access the operating-system error-code equivalents of errno codes.
For other operations the value of _doserrno is undefined.

For me this means we must either output our own posix message
or map the error code to a DOS code.

I'd like to correct this.
What is "the right thing"(tm) ?

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home




