generrmap.c 849 Bytes
Newer Older
1 2 3
#include <windows.h>
#include <fcntl.h>
#include <io.h>
4 5 6 7 8 9 10
#include <stdio.h>
#include <errno.h>

/* Extract the mapping of Win32 error codes to errno */

int main()
{
11
    int i;
12
    _setmode(fileno(stdout), O_BINARY);
13 14
    printf("/* Generated file. Do not edit. */\n");
    printf("int winerror_to_errno(int winerror)\n");
15
    printf("{\n    switch(winerror) {\n");
16 17
    for(i=1; i < 65000; i++) {
        _dosmaperr(i);
18 19 20 21
        if (errno == EINVAL) {
            /* Issue #12802 */
            if (i == ERROR_DIRECTORY)
                errno = ENOTDIR;
22 23 24
            /* Issue #13063 */
            else if (i == ERROR_NO_DATA)
                errno = EPIPE;
25 26 27 28
            else
                continue;
        }
        printf("        case %d: return %d;\n", i, errno);
29
    }
30 31
    printf("        default: return EINVAL;\n");
    printf("    }\n}\n");
32
}