multiple-local-realms-fix-20051210
[openafs.git] / src / util / errmap_nt.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <windows.h>
17 #include <afs/errmap_nt.h>
18
19 int nterr_lastNTError = 0;      /* Useful for core dumps from LWP based binaries */
20
21 /*
22  * nterr_nt2unix() -- convert NT error code to a Unix-ish value.
23  *
24  * RETURN CODES: translated code, or 'defaultErr' if no translation available.
25  */
26
27 int
28 nterr_nt2unix(long ntErr, int defaultErr)
29 {
30     int ucode;
31
32     nterr_lastNTError = ntErr;
33     switch (ntErr) {
34     case ERROR_SUCCESS:
35         ucode = 0;
36         break;
37     case ERROR_INVALID_PARAMETER:
38     case ERROR_BAD_COMMAND:
39         ucode = EINVAL;
40         break;
41     case ERROR_FILE_NOT_FOUND:
42     case ERROR_PATH_NOT_FOUND:
43     case ERROR_INVALID_DRIVE:
44         ucode = ENOENT;
45         break;
46     case ERROR_FILE_EXISTS:
47     case ERROR_ALREADY_EXISTS:
48         ucode = EEXIST;
49         break;
50     case ERROR_ACCESS_DENIED:
51         ucode = EACCES;
52         break;
53     case ERROR_WRITE_PROTECT:
54         ucode = EROFS;
55         break;
56     case ERROR_NOT_SUPPORTED:
57         ucode = ENOTTY;
58         break;
59     case ERROR_INVALID_HANDLE:
60         ucode = EBADF;
61         break;
62     case ERROR_TOO_MANY_OPEN_FILES:
63         ucode = EMFILE;
64         break;
65     case ERROR_DISK_FULL:
66     case ERROR_HANDLE_DISK_FULL:
67         ucode = ENOSPC;
68         break;
69     case ERROR_OUTOFMEMORY:
70     case ERROR_NOT_ENOUGH_MEMORY:
71         ucode = ENOMEM;
72         break;
73     case ERROR_SHARING_VIOLATION:
74     case ERROR_PIPE_BUSY:
75         ucode = EBUSY;
76         break;
77     case ERROR_BROKEN_PIPE:
78     case ERROR_BAD_PIPE:
79     case ERROR_PIPE_NOT_CONNECTED:
80         ucode = EPIPE;
81         break;
82     default:
83         ucode = defaultErr;
84         break;
85     }
86
87     return ucode;
88 }