Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* |
michael@0 | 3 | * This file essentially replicates NSPR's source for the functions that |
michael@0 | 4 | * map system-specific error codes to NSPR error codes. We would use |
michael@0 | 5 | * NSPR's functions, instead of duplicating them, but they're private. |
michael@0 | 6 | * As long as SSL's server session cache code must do platform native I/O |
michael@0 | 7 | * to accomplish its job, and NSPR's error mapping functions remain private, |
michael@0 | 8 | * this code will continue to need to be replicated. |
michael@0 | 9 | * |
michael@0 | 10 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 13 | |
michael@0 | 14 | #include "prerror.h" |
michael@0 | 15 | #include "prlog.h" |
michael@0 | 16 | #include <errno.h> |
michael@0 | 17 | |
michael@0 | 18 | |
michael@0 | 19 | /* |
michael@0 | 20 | * Based on win32err.c |
michael@0 | 21 | * OS2TODO Stub everything for now to build. HCT |
michael@0 | 22 | */ |
michael@0 | 23 | |
michael@0 | 24 | /* forward declaration. */ |
michael@0 | 25 | void nss_MD_os2_map_default_error(PRInt32 err); |
michael@0 | 26 | |
michael@0 | 27 | void nss_MD_os2_map_opendir_error(PRInt32 err) |
michael@0 | 28 | { |
michael@0 | 29 | nss_MD_os2_map_default_error(err); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void nss_MD_os2_map_closedir_error(PRInt32 err) |
michael@0 | 33 | { |
michael@0 | 34 | nss_MD_os2_map_default_error(err); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void nss_MD_os2_map_readdir_error(PRInt32 err) |
michael@0 | 38 | { |
michael@0 | 39 | nss_MD_os2_map_default_error(err); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | void nss_MD_os2_map_delete_error(PRInt32 err) |
michael@0 | 43 | { |
michael@0 | 44 | nss_MD_os2_map_default_error(err); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | /* The error code for stat() is in errno. */ |
michael@0 | 48 | void nss_MD_os2_map_stat_error(PRInt32 err) |
michael@0 | 49 | { |
michael@0 | 50 | nss_MD_os2_map_default_error(err); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | void nss_MD_os2_map_fstat_error(PRInt32 err) |
michael@0 | 54 | { |
michael@0 | 55 | nss_MD_os2_map_default_error(err); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | void nss_MD_os2_map_rename_error(PRInt32 err) |
michael@0 | 59 | { |
michael@0 | 60 | nss_MD_os2_map_default_error(err); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | /* The error code for access() is in errno. */ |
michael@0 | 64 | void nss_MD_os2_map_access_error(PRInt32 err) |
michael@0 | 65 | { |
michael@0 | 66 | nss_MD_os2_map_default_error(err); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | void nss_MD_os2_map_mkdir_error(PRInt32 err) |
michael@0 | 70 | { |
michael@0 | 71 | nss_MD_os2_map_default_error(err); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void nss_MD_os2_map_rmdir_error(PRInt32 err) |
michael@0 | 75 | { |
michael@0 | 76 | nss_MD_os2_map_default_error(err); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void nss_MD_os2_map_read_error(PRInt32 err) |
michael@0 | 80 | { |
michael@0 | 81 | nss_MD_os2_map_default_error(err); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | void nss_MD_os2_map_transmitfile_error(PRInt32 err) |
michael@0 | 85 | { |
michael@0 | 86 | nss_MD_os2_map_default_error(err); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | void nss_MD_os2_map_write_error(PRInt32 err) |
michael@0 | 90 | { |
michael@0 | 91 | nss_MD_os2_map_default_error(err); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | void nss_MD_os2_map_lseek_error(PRInt32 err) |
michael@0 | 95 | { |
michael@0 | 96 | nss_MD_os2_map_default_error(err); |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | void nss_MD_os2_map_fsync_error(PRInt32 err) |
michael@0 | 100 | { |
michael@0 | 101 | nss_MD_os2_map_default_error(err); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | /* |
michael@0 | 105 | * For both CloseHandle() and closesocket(). |
michael@0 | 106 | */ |
michael@0 | 107 | void nss_MD_os2_map_close_error(PRInt32 err) |
michael@0 | 108 | { |
michael@0 | 109 | nss_MD_os2_map_default_error(err); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | void nss_MD_os2_map_socket_error(PRInt32 err) |
michael@0 | 113 | { |
michael@0 | 114 | // PR_ASSERT(err != WSANOTINITIALISED); |
michael@0 | 115 | nss_MD_os2_map_default_error(err); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | void nss_MD_os2_map_recv_error(PRInt32 err) |
michael@0 | 119 | { |
michael@0 | 120 | nss_MD_os2_map_default_error(err); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | void nss_MD_os2_map_recvfrom_error(PRInt32 err) |
michael@0 | 124 | { |
michael@0 | 125 | nss_MD_os2_map_default_error(err); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | void nss_MD_os2_map_send_error(PRInt32 err) |
michael@0 | 129 | { |
michael@0 | 130 | PRErrorCode prError; |
michael@0 | 131 | switch (err) { |
michael@0 | 132 | // case WSAEMSGSIZE: prError = PR_INVALID_ARGUMENT_ERROR; break; |
michael@0 | 133 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 134 | } |
michael@0 | 135 | PR_SetError(prError, err); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | void nss_MD_os2_map_sendto_error(PRInt32 err) |
michael@0 | 139 | { |
michael@0 | 140 | PRErrorCode prError; |
michael@0 | 141 | switch (err) { |
michael@0 | 142 | // case WSAEMSGSIZE: prError = PR_INVALID_ARGUMENT_ERROR; break; |
michael@0 | 143 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 144 | } |
michael@0 | 145 | PR_SetError(prError, err); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | void nss_MD_os2_map_accept_error(PRInt32 err) |
michael@0 | 149 | { |
michael@0 | 150 | PRErrorCode prError; |
michael@0 | 151 | switch (err) { |
michael@0 | 152 | // case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break; |
michael@0 | 153 | // case WSAEINVAL: prError = PR_INVALID_STATE_ERROR; break; |
michael@0 | 154 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 155 | } |
michael@0 | 156 | PR_SetError(prError, err); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | void nss_MD_os2_map_acceptex_error(PRInt32 err) |
michael@0 | 160 | { |
michael@0 | 161 | nss_MD_os2_map_default_error(err); |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | void nss_MD_os2_map_connect_error(PRInt32 err) |
michael@0 | 165 | { |
michael@0 | 166 | PRErrorCode prError; |
michael@0 | 167 | switch (err) { |
michael@0 | 168 | // case WSAEWOULDBLOCK: prError = PR_IN_PROGRESS_ERROR; break; |
michael@0 | 169 | // case WSAEINVAL: prError = PR_ALREADY_INITIATED_ERROR; break; |
michael@0 | 170 | // case WSAETIMEDOUT: prError = PR_IO_TIMEOUT_ERROR; break; |
michael@0 | 171 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 172 | } |
michael@0 | 173 | PR_SetError(prError, err); |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | void nss_MD_os2_map_bind_error(PRInt32 err) |
michael@0 | 177 | { |
michael@0 | 178 | PRErrorCode prError; |
michael@0 | 179 | switch (err) { |
michael@0 | 180 | // case WSAEINVAL: prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; break; |
michael@0 | 181 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 182 | } |
michael@0 | 183 | PR_SetError(prError, err); |
michael@0 | 184 | } |
michael@0 | 185 | |
michael@0 | 186 | void nss_MD_os2_map_listen_error(PRInt32 err) |
michael@0 | 187 | { |
michael@0 | 188 | PRErrorCode prError; |
michael@0 | 189 | switch (err) { |
michael@0 | 190 | // case WSAEOPNOTSUPP: prError = PR_NOT_TCP_SOCKET_ERROR; break; |
michael@0 | 191 | // case WSAEINVAL: prError = PR_INVALID_STATE_ERROR; break; |
michael@0 | 192 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 193 | } |
michael@0 | 194 | PR_SetError(prError, err); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | void nss_MD_os2_map_shutdown_error(PRInt32 err) |
michael@0 | 198 | { |
michael@0 | 199 | nss_MD_os2_map_default_error(err); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | void nss_MD_os2_map_getsockname_error(PRInt32 err) |
michael@0 | 203 | { |
michael@0 | 204 | PRErrorCode prError; |
michael@0 | 205 | switch (err) { |
michael@0 | 206 | // case WSAEINVAL: prError = PR_INVALID_STATE_ERROR; break; |
michael@0 | 207 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 208 | } |
michael@0 | 209 | PR_SetError(prError, err); |
michael@0 | 210 | } |
michael@0 | 211 | |
michael@0 | 212 | void nss_MD_os2_map_getpeername_error(PRInt32 err) |
michael@0 | 213 | { |
michael@0 | 214 | nss_MD_os2_map_default_error(err); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | void nss_MD_os2_map_getsockopt_error(PRInt32 err) |
michael@0 | 218 | { |
michael@0 | 219 | nss_MD_os2_map_default_error(err); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | void nss_MD_os2_map_setsockopt_error(PRInt32 err) |
michael@0 | 223 | { |
michael@0 | 224 | nss_MD_os2_map_default_error(err); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | void nss_MD_os2_map_open_error(PRInt32 err) |
michael@0 | 228 | { |
michael@0 | 229 | nss_MD_os2_map_default_error(err); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | void nss_MD_os2_map_gethostname_error(PRInt32 err) |
michael@0 | 233 | { |
michael@0 | 234 | nss_MD_os2_map_default_error(err); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | /* Win32 select() only works on sockets. So in this |
michael@0 | 238 | ** context, WSAENOTSOCK is equivalent to EBADF on Unix. |
michael@0 | 239 | */ |
michael@0 | 240 | void nss_MD_os2_map_select_error(PRInt32 err) |
michael@0 | 241 | { |
michael@0 | 242 | PRErrorCode prError; |
michael@0 | 243 | switch (err) { |
michael@0 | 244 | // case WSAENOTSOCK: prError = PR_BAD_DESCRIPTOR_ERROR; break; |
michael@0 | 245 | default: nss_MD_os2_map_default_error(err); return; |
michael@0 | 246 | } |
michael@0 | 247 | PR_SetError(prError, err); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | void nss_MD_os2_map_lockf_error(PRInt32 err) |
michael@0 | 251 | { |
michael@0 | 252 | nss_MD_os2_map_default_error(err); |
michael@0 | 253 | } |
michael@0 | 254 | |
michael@0 | 255 | |
michael@0 | 256 | |
michael@0 | 257 | void nss_MD_os2_map_default_error(PRInt32 err) |
michael@0 | 258 | { |
michael@0 | 259 | PRErrorCode prError; |
michael@0 | 260 | |
michael@0 | 261 | switch (err) { |
michael@0 | 262 | // case ENOENT: prError = PR_FILE_NOT_FOUND_ERROR; break; |
michael@0 | 263 | // case ERROR_ACCESS_DENIED: prError = PR_NO_ACCESS_RIGHTS_ERROR; break; |
michael@0 | 264 | // case ERROR_ALREADY_EXISTS: prError = PR_FILE_EXISTS_ERROR; break; |
michael@0 | 265 | // case ERROR_DISK_CORRUPT: prError = PR_IO_ERROR; break; |
michael@0 | 266 | // case ERROR_DISK_FULL: prError = PR_NO_DEVICE_SPACE_ERROR; break; |
michael@0 | 267 | // case ERROR_DISK_OPERATION_FAILED: prError = PR_IO_ERROR; break; |
michael@0 | 268 | // case ERROR_DRIVE_LOCKED: prError = PR_FILE_IS_LOCKED_ERROR; break; |
michael@0 | 269 | // case ERROR_FILENAME_EXCED_RANGE: prError = PR_NAME_TOO_LONG_ERROR; break; |
michael@0 | 270 | // case ERROR_FILE_CORRUPT: prError = PR_IO_ERROR; break; |
michael@0 | 271 | // case ERROR_FILE_EXISTS: prError = PR_FILE_EXISTS_ERROR; break; |
michael@0 | 272 | // case ERROR_FILE_INVALID: prError = PR_BAD_DESCRIPTOR_ERROR; break; |
michael@0 | 273 | #if ERROR_FILE_NOT_FOUND != ENOENT |
michael@0 | 274 | // case ERROR_FILE_NOT_FOUND: prError = PR_FILE_NOT_FOUND_ERROR; break; |
michael@0 | 275 | #endif |
michael@0 | 276 | default: prError = PR_UNKNOWN_ERROR; break; |
michael@0 | 277 | } |
michael@0 | 278 | PR_SetError(prError, err); |
michael@0 | 279 | } |
michael@0 | 280 |