Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "primpl.h" |
michael@0 | 7 | #if defined(_PR_POLL_AVAILABLE) |
michael@0 | 8 | #include <poll.h> |
michael@0 | 9 | #endif |
michael@0 | 10 | #include <errno.h> |
michael@0 | 11 | |
michael@0 | 12 | void _MD_unix_map_default_error(int err) |
michael@0 | 13 | { |
michael@0 | 14 | PRErrorCode prError; |
michael@0 | 15 | |
michael@0 | 16 | switch (err ) { |
michael@0 | 17 | case EACCES: |
michael@0 | 18 | prError = PR_NO_ACCESS_RIGHTS_ERROR; |
michael@0 | 19 | break; |
michael@0 | 20 | case EADDRINUSE: |
michael@0 | 21 | prError = PR_ADDRESS_IN_USE_ERROR; |
michael@0 | 22 | break; |
michael@0 | 23 | case EADDRNOTAVAIL: |
michael@0 | 24 | prError = PR_ADDRESS_NOT_AVAILABLE_ERROR; |
michael@0 | 25 | break; |
michael@0 | 26 | case EAFNOSUPPORT: |
michael@0 | 27 | prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; |
michael@0 | 28 | break; |
michael@0 | 29 | case EAGAIN: |
michael@0 | 30 | prError = PR_WOULD_BLOCK_ERROR; |
michael@0 | 31 | break; |
michael@0 | 32 | /* |
michael@0 | 33 | * On QNX and Neutrino, EALREADY is defined as EBUSY. |
michael@0 | 34 | */ |
michael@0 | 35 | #if EALREADY != EBUSY |
michael@0 | 36 | case EALREADY: |
michael@0 | 37 | prError = PR_ALREADY_INITIATED_ERROR; |
michael@0 | 38 | break; |
michael@0 | 39 | #endif |
michael@0 | 40 | case EBADF: |
michael@0 | 41 | prError = PR_BAD_DESCRIPTOR_ERROR; |
michael@0 | 42 | break; |
michael@0 | 43 | #ifdef EBADMSG |
michael@0 | 44 | case EBADMSG: |
michael@0 | 45 | prError = PR_IO_ERROR; |
michael@0 | 46 | break; |
michael@0 | 47 | #endif |
michael@0 | 48 | case EBUSY: |
michael@0 | 49 | prError = PR_FILESYSTEM_MOUNTED_ERROR; |
michael@0 | 50 | break; |
michael@0 | 51 | case ECONNABORTED: |
michael@0 | 52 | prError = PR_CONNECT_ABORTED_ERROR; |
michael@0 | 53 | break; |
michael@0 | 54 | case ECONNREFUSED: |
michael@0 | 55 | prError = PR_CONNECT_REFUSED_ERROR; |
michael@0 | 56 | break; |
michael@0 | 57 | case ECONNRESET: |
michael@0 | 58 | prError = PR_CONNECT_RESET_ERROR; |
michael@0 | 59 | break; |
michael@0 | 60 | case EDEADLK: |
michael@0 | 61 | prError = PR_DEADLOCK_ERROR; |
michael@0 | 62 | break; |
michael@0 | 63 | #ifdef EDIRCORRUPTED |
michael@0 | 64 | case EDIRCORRUPTED: |
michael@0 | 65 | prError = PR_DIRECTORY_CORRUPTED_ERROR; |
michael@0 | 66 | break; |
michael@0 | 67 | #endif |
michael@0 | 68 | #ifdef EDQUOT |
michael@0 | 69 | case EDQUOT: |
michael@0 | 70 | prError = PR_NO_DEVICE_SPACE_ERROR; |
michael@0 | 71 | break; |
michael@0 | 72 | #endif |
michael@0 | 73 | case EEXIST: |
michael@0 | 74 | prError = PR_FILE_EXISTS_ERROR; |
michael@0 | 75 | break; |
michael@0 | 76 | case EFAULT: |
michael@0 | 77 | prError = PR_ACCESS_FAULT_ERROR; |
michael@0 | 78 | break; |
michael@0 | 79 | case EFBIG: |
michael@0 | 80 | prError = PR_FILE_TOO_BIG_ERROR; |
michael@0 | 81 | break; |
michael@0 | 82 | case EHOSTUNREACH: |
michael@0 | 83 | case EHOSTDOWN: |
michael@0 | 84 | prError = PR_HOST_UNREACHABLE_ERROR; |
michael@0 | 85 | break; |
michael@0 | 86 | case EINPROGRESS: |
michael@0 | 87 | prError = PR_IN_PROGRESS_ERROR; |
michael@0 | 88 | break; |
michael@0 | 89 | case EINTR: |
michael@0 | 90 | prError = PR_PENDING_INTERRUPT_ERROR; |
michael@0 | 91 | break; |
michael@0 | 92 | case EINVAL: |
michael@0 | 93 | prError = PR_INVALID_ARGUMENT_ERROR; |
michael@0 | 94 | break; |
michael@0 | 95 | case EIO: |
michael@0 | 96 | prError = PR_IO_ERROR; |
michael@0 | 97 | break; |
michael@0 | 98 | case EISCONN: |
michael@0 | 99 | prError = PR_IS_CONNECTED_ERROR; |
michael@0 | 100 | break; |
michael@0 | 101 | case EISDIR: |
michael@0 | 102 | prError = PR_IS_DIRECTORY_ERROR; |
michael@0 | 103 | break; |
michael@0 | 104 | case ELOOP: |
michael@0 | 105 | prError = PR_LOOP_ERROR; |
michael@0 | 106 | break; |
michael@0 | 107 | case EMFILE: |
michael@0 | 108 | prError = PR_PROC_DESC_TABLE_FULL_ERROR; |
michael@0 | 109 | break; |
michael@0 | 110 | case EMLINK: |
michael@0 | 111 | prError = PR_MAX_DIRECTORY_ENTRIES_ERROR; |
michael@0 | 112 | break; |
michael@0 | 113 | case EMSGSIZE: |
michael@0 | 114 | prError = PR_INVALID_ARGUMENT_ERROR; |
michael@0 | 115 | break; |
michael@0 | 116 | #ifdef EMULTIHOP |
michael@0 | 117 | case EMULTIHOP: |
michael@0 | 118 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 119 | break; |
michael@0 | 120 | #endif |
michael@0 | 121 | case ENAMETOOLONG: |
michael@0 | 122 | prError = PR_NAME_TOO_LONG_ERROR; |
michael@0 | 123 | break; |
michael@0 | 124 | case ENETUNREACH: |
michael@0 | 125 | prError = PR_NETWORK_UNREACHABLE_ERROR; |
michael@0 | 126 | break; |
michael@0 | 127 | case ENFILE: |
michael@0 | 128 | prError = PR_SYS_DESC_TABLE_FULL_ERROR; |
michael@0 | 129 | break; |
michael@0 | 130 | /* |
michael@0 | 131 | * On SCO OpenServer 5, ENOBUFS is defined as ENOSR. |
michael@0 | 132 | */ |
michael@0 | 133 | #if defined(ENOBUFS) && (ENOBUFS != ENOSR) |
michael@0 | 134 | case ENOBUFS: |
michael@0 | 135 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 136 | break; |
michael@0 | 137 | #endif |
michael@0 | 138 | case ENODEV: |
michael@0 | 139 | prError = PR_FILE_NOT_FOUND_ERROR; |
michael@0 | 140 | break; |
michael@0 | 141 | case ENOENT: |
michael@0 | 142 | prError = PR_FILE_NOT_FOUND_ERROR; |
michael@0 | 143 | break; |
michael@0 | 144 | case ENOLCK: |
michael@0 | 145 | prError = PR_FILE_IS_LOCKED_ERROR; |
michael@0 | 146 | break; |
michael@0 | 147 | #ifdef ENOLINK |
michael@0 | 148 | case ENOLINK: |
michael@0 | 149 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 150 | break; |
michael@0 | 151 | #endif |
michael@0 | 152 | case ENOMEM: |
michael@0 | 153 | prError = PR_OUT_OF_MEMORY_ERROR; |
michael@0 | 154 | break; |
michael@0 | 155 | case ENOPROTOOPT: |
michael@0 | 156 | prError = PR_INVALID_ARGUMENT_ERROR; |
michael@0 | 157 | break; |
michael@0 | 158 | case ENOSPC: |
michael@0 | 159 | prError = PR_NO_DEVICE_SPACE_ERROR; |
michael@0 | 160 | break; |
michael@0 | 161 | #ifdef ENOSR |
michael@0 | 162 | case ENOSR: |
michael@0 | 163 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 164 | break; |
michael@0 | 165 | #endif |
michael@0 | 166 | case ENOSYS: |
michael@0 | 167 | prError = PR_NOT_IMPLEMENTED_ERROR; |
michael@0 | 168 | break; |
michael@0 | 169 | case ENOTCONN: |
michael@0 | 170 | prError = PR_NOT_CONNECTED_ERROR; |
michael@0 | 171 | break; |
michael@0 | 172 | case ENOTDIR: |
michael@0 | 173 | prError = PR_NOT_DIRECTORY_ERROR; |
michael@0 | 174 | break; |
michael@0 | 175 | case ENOTSOCK: |
michael@0 | 176 | prError = PR_NOT_SOCKET_ERROR; |
michael@0 | 177 | break; |
michael@0 | 178 | case ENXIO: |
michael@0 | 179 | prError = PR_FILE_NOT_FOUND_ERROR; |
michael@0 | 180 | break; |
michael@0 | 181 | case EOPNOTSUPP: |
michael@0 | 182 | prError = PR_NOT_TCP_SOCKET_ERROR; |
michael@0 | 183 | break; |
michael@0 | 184 | #ifdef EOVERFLOW |
michael@0 | 185 | case EOVERFLOW: |
michael@0 | 186 | prError = PR_BUFFER_OVERFLOW_ERROR; |
michael@0 | 187 | break; |
michael@0 | 188 | #endif |
michael@0 | 189 | case EPERM: |
michael@0 | 190 | prError = PR_NO_ACCESS_RIGHTS_ERROR; |
michael@0 | 191 | break; |
michael@0 | 192 | case EPIPE: |
michael@0 | 193 | prError = PR_CONNECT_RESET_ERROR; |
michael@0 | 194 | break; |
michael@0 | 195 | #ifdef EPROTO |
michael@0 | 196 | case EPROTO: |
michael@0 | 197 | prError = PR_IO_ERROR; |
michael@0 | 198 | break; |
michael@0 | 199 | #endif |
michael@0 | 200 | case EPROTONOSUPPORT: |
michael@0 | 201 | prError = PR_PROTOCOL_NOT_SUPPORTED_ERROR; |
michael@0 | 202 | break; |
michael@0 | 203 | case EPROTOTYPE: |
michael@0 | 204 | prError = PR_ADDRESS_NOT_SUPPORTED_ERROR; |
michael@0 | 205 | break; |
michael@0 | 206 | case ERANGE: |
michael@0 | 207 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 208 | break; |
michael@0 | 209 | case EROFS: |
michael@0 | 210 | prError = PR_READ_ONLY_FILESYSTEM_ERROR; |
michael@0 | 211 | break; |
michael@0 | 212 | case ESPIPE: |
michael@0 | 213 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 214 | break; |
michael@0 | 215 | case ETIMEDOUT: |
michael@0 | 216 | prError = PR_IO_TIMEOUT_ERROR; |
michael@0 | 217 | break; |
michael@0 | 218 | #if EWOULDBLOCK != EAGAIN |
michael@0 | 219 | case EWOULDBLOCK: |
michael@0 | 220 | prError = PR_WOULD_BLOCK_ERROR; |
michael@0 | 221 | break; |
michael@0 | 222 | #endif |
michael@0 | 223 | case EXDEV: |
michael@0 | 224 | prError = PR_NOT_SAME_DEVICE_ERROR; |
michael@0 | 225 | break; |
michael@0 | 226 | default: |
michael@0 | 227 | prError = PR_UNKNOWN_ERROR; |
michael@0 | 228 | break; |
michael@0 | 229 | } |
michael@0 | 230 | PR_SetError(prError, err); |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | void _MD_unix_map_opendir_error(int err) |
michael@0 | 234 | { |
michael@0 | 235 | _MD_unix_map_default_error(err); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | void _MD_unix_map_closedir_error(int err) |
michael@0 | 239 | { |
michael@0 | 240 | PRErrorCode prError; |
michael@0 | 241 | |
michael@0 | 242 | switch (err) { |
michael@0 | 243 | case EINVAL: |
michael@0 | 244 | prError = PR_BAD_DESCRIPTOR_ERROR; |
michael@0 | 245 | break; |
michael@0 | 246 | default: |
michael@0 | 247 | _MD_unix_map_default_error(err); |
michael@0 | 248 | return; |
michael@0 | 249 | } |
michael@0 | 250 | PR_SetError(prError, err); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | void _MD_unix_readdir_error(int err) |
michael@0 | 254 | { |
michael@0 | 255 | PRErrorCode prError; |
michael@0 | 256 | |
michael@0 | 257 | switch (err) { |
michael@0 | 258 | case 0: |
michael@0 | 259 | case ENOENT: |
michael@0 | 260 | prError = PR_NO_MORE_FILES_ERROR; |
michael@0 | 261 | break; |
michael@0 | 262 | #ifdef EOVERFLOW |
michael@0 | 263 | case EOVERFLOW: |
michael@0 | 264 | prError = PR_IO_ERROR; |
michael@0 | 265 | break; |
michael@0 | 266 | #endif |
michael@0 | 267 | case EINVAL: |
michael@0 | 268 | prError = PR_IO_ERROR; |
michael@0 | 269 | break; |
michael@0 | 270 | case ENXIO: |
michael@0 | 271 | prError = PR_IO_ERROR; |
michael@0 | 272 | break; |
michael@0 | 273 | default: |
michael@0 | 274 | _MD_unix_map_default_error(err); |
michael@0 | 275 | return; |
michael@0 | 276 | } |
michael@0 | 277 | PR_SetError(prError, err); |
michael@0 | 278 | } |
michael@0 | 279 | |
michael@0 | 280 | void _MD_unix_map_unlink_error(int err) |
michael@0 | 281 | { |
michael@0 | 282 | PRErrorCode prError; |
michael@0 | 283 | |
michael@0 | 284 | switch (err) { |
michael@0 | 285 | case EPERM: |
michael@0 | 286 | prError = PR_IS_DIRECTORY_ERROR; |
michael@0 | 287 | break; |
michael@0 | 288 | default: |
michael@0 | 289 | _MD_unix_map_default_error(err); |
michael@0 | 290 | return; |
michael@0 | 291 | } |
michael@0 | 292 | PR_SetError(prError, err); |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | void _MD_unix_map_stat_error(int err) |
michael@0 | 296 | { |
michael@0 | 297 | PRErrorCode prError; |
michael@0 | 298 | |
michael@0 | 299 | switch (err) { |
michael@0 | 300 | case ETIMEDOUT: |
michael@0 | 301 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 302 | break; |
michael@0 | 303 | default: |
michael@0 | 304 | _MD_unix_map_default_error(err); |
michael@0 | 305 | return; |
michael@0 | 306 | } |
michael@0 | 307 | PR_SetError(prError, err); |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | void _MD_unix_map_fstat_error(int err) |
michael@0 | 311 | { |
michael@0 | 312 | PRErrorCode prError; |
michael@0 | 313 | |
michael@0 | 314 | switch (err) { |
michael@0 | 315 | case ETIMEDOUT: |
michael@0 | 316 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 317 | break; |
michael@0 | 318 | default: |
michael@0 | 319 | _MD_unix_map_default_error(err); |
michael@0 | 320 | return; |
michael@0 | 321 | } |
michael@0 | 322 | PR_SetError(prError, err); |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | void _MD_unix_map_rename_error(int err) |
michael@0 | 326 | { |
michael@0 | 327 | PRErrorCode prError; |
michael@0 | 328 | |
michael@0 | 329 | switch (err) { |
michael@0 | 330 | case EEXIST: |
michael@0 | 331 | prError = PR_DIRECTORY_NOT_EMPTY_ERROR; |
michael@0 | 332 | break; |
michael@0 | 333 | default: |
michael@0 | 334 | _MD_unix_map_default_error(err); |
michael@0 | 335 | return; |
michael@0 | 336 | } |
michael@0 | 337 | PR_SetError(prError, err); |
michael@0 | 338 | } |
michael@0 | 339 | |
michael@0 | 340 | void _MD_unix_map_access_error(int err) |
michael@0 | 341 | { |
michael@0 | 342 | PRErrorCode prError; |
michael@0 | 343 | |
michael@0 | 344 | switch (err) { |
michael@0 | 345 | case ETIMEDOUT: |
michael@0 | 346 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 347 | break; |
michael@0 | 348 | default: |
michael@0 | 349 | _MD_unix_map_default_error(err); |
michael@0 | 350 | return; |
michael@0 | 351 | } |
michael@0 | 352 | PR_SetError(prError, err); |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | void _MD_unix_map_mkdir_error(int err) |
michael@0 | 356 | { |
michael@0 | 357 | _MD_unix_map_default_error(err); |
michael@0 | 358 | } |
michael@0 | 359 | |
michael@0 | 360 | void _MD_unix_map_rmdir_error(int err) |
michael@0 | 361 | { |
michael@0 | 362 | PRErrorCode prError; |
michael@0 | 363 | |
michael@0 | 364 | switch (err) { |
michael@0 | 365 | /* |
michael@0 | 366 | * On AIX 4.3, ENOTEMPTY is defined as EEXIST. |
michael@0 | 367 | */ |
michael@0 | 368 | #if ENOTEMPTY != EEXIST |
michael@0 | 369 | case ENOTEMPTY: |
michael@0 | 370 | prError = PR_DIRECTORY_NOT_EMPTY_ERROR; |
michael@0 | 371 | break; |
michael@0 | 372 | #endif |
michael@0 | 373 | case EEXIST: |
michael@0 | 374 | prError = PR_DIRECTORY_NOT_EMPTY_ERROR; |
michael@0 | 375 | break; |
michael@0 | 376 | case EINVAL: |
michael@0 | 377 | prError = PR_DIRECTORY_NOT_EMPTY_ERROR; |
michael@0 | 378 | break; |
michael@0 | 379 | case ETIMEDOUT: |
michael@0 | 380 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 381 | break; |
michael@0 | 382 | default: |
michael@0 | 383 | _MD_unix_map_default_error(err); |
michael@0 | 384 | return; |
michael@0 | 385 | } |
michael@0 | 386 | PR_SetError(prError, err); |
michael@0 | 387 | } |
michael@0 | 388 | |
michael@0 | 389 | void _MD_unix_map_read_error(int err) |
michael@0 | 390 | { |
michael@0 | 391 | PRErrorCode prError; |
michael@0 | 392 | |
michael@0 | 393 | switch (err) { |
michael@0 | 394 | case EINVAL: |
michael@0 | 395 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 396 | break; |
michael@0 | 397 | case ENXIO: |
michael@0 | 398 | prError = PR_INVALID_ARGUMENT_ERROR; |
michael@0 | 399 | break; |
michael@0 | 400 | default: |
michael@0 | 401 | _MD_unix_map_default_error(err); |
michael@0 | 402 | return; |
michael@0 | 403 | } |
michael@0 | 404 | PR_SetError(prError, err); |
michael@0 | 405 | } |
michael@0 | 406 | |
michael@0 | 407 | void _MD_unix_map_write_error(int err) |
michael@0 | 408 | { |
michael@0 | 409 | PRErrorCode prError; |
michael@0 | 410 | |
michael@0 | 411 | switch (err) { |
michael@0 | 412 | case EINVAL: |
michael@0 | 413 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 414 | break; |
michael@0 | 415 | case ENXIO: |
michael@0 | 416 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 417 | break; |
michael@0 | 418 | case ETIMEDOUT: |
michael@0 | 419 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 420 | break; |
michael@0 | 421 | default: |
michael@0 | 422 | _MD_unix_map_default_error(err); |
michael@0 | 423 | return; |
michael@0 | 424 | } |
michael@0 | 425 | PR_SetError(prError, err); |
michael@0 | 426 | } |
michael@0 | 427 | |
michael@0 | 428 | void _MD_unix_map_lseek_error(int err) |
michael@0 | 429 | { |
michael@0 | 430 | _MD_unix_map_default_error(err); |
michael@0 | 431 | } |
michael@0 | 432 | |
michael@0 | 433 | void _MD_unix_map_fsync_error(int err) |
michael@0 | 434 | { |
michael@0 | 435 | PRErrorCode prError; |
michael@0 | 436 | |
michael@0 | 437 | switch (err) { |
michael@0 | 438 | case ETIMEDOUT: |
michael@0 | 439 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 440 | break; |
michael@0 | 441 | case EINVAL: |
michael@0 | 442 | prError = PR_INVALID_METHOD_ERROR; |
michael@0 | 443 | break; |
michael@0 | 444 | default: |
michael@0 | 445 | _MD_unix_map_default_error(err); |
michael@0 | 446 | return; |
michael@0 | 447 | } |
michael@0 | 448 | PR_SetError(prError, err); |
michael@0 | 449 | } |
michael@0 | 450 | |
michael@0 | 451 | void _MD_unix_map_close_error(int err) |
michael@0 | 452 | { |
michael@0 | 453 | PRErrorCode prError; |
michael@0 | 454 | |
michael@0 | 455 | switch (err) { |
michael@0 | 456 | case ETIMEDOUT: |
michael@0 | 457 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 458 | break; |
michael@0 | 459 | default: |
michael@0 | 460 | _MD_unix_map_default_error(err); |
michael@0 | 461 | return; |
michael@0 | 462 | } |
michael@0 | 463 | PR_SetError(prError, err); |
michael@0 | 464 | } |
michael@0 | 465 | |
michael@0 | 466 | void _MD_unix_map_socket_error(int err) |
michael@0 | 467 | { |
michael@0 | 468 | PRErrorCode prError; |
michael@0 | 469 | |
michael@0 | 470 | switch (err) { |
michael@0 | 471 | case ENOMEM: |
michael@0 | 472 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 473 | break; |
michael@0 | 474 | default: |
michael@0 | 475 | _MD_unix_map_default_error(err); |
michael@0 | 476 | return; |
michael@0 | 477 | } |
michael@0 | 478 | PR_SetError(prError, err); |
michael@0 | 479 | } |
michael@0 | 480 | |
michael@0 | 481 | void _MD_unix_map_socketavailable_error(int err) |
michael@0 | 482 | { |
michael@0 | 483 | PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err); |
michael@0 | 484 | } |
michael@0 | 485 | |
michael@0 | 486 | void _MD_unix_map_recv_error(int err) |
michael@0 | 487 | { |
michael@0 | 488 | _MD_unix_map_default_error(err); |
michael@0 | 489 | } |
michael@0 | 490 | |
michael@0 | 491 | void _MD_unix_map_recvfrom_error(int err) |
michael@0 | 492 | { |
michael@0 | 493 | _MD_unix_map_default_error(err); |
michael@0 | 494 | } |
michael@0 | 495 | |
michael@0 | 496 | void _MD_unix_map_send_error(int err) |
michael@0 | 497 | { |
michael@0 | 498 | _MD_unix_map_default_error(err); |
michael@0 | 499 | } |
michael@0 | 500 | |
michael@0 | 501 | void _MD_unix_map_sendto_error(int err) |
michael@0 | 502 | { |
michael@0 | 503 | _MD_unix_map_default_error(err); |
michael@0 | 504 | } |
michael@0 | 505 | |
michael@0 | 506 | void _MD_unix_map_writev_error(int err) |
michael@0 | 507 | { |
michael@0 | 508 | _MD_unix_map_default_error(err); |
michael@0 | 509 | } |
michael@0 | 510 | |
michael@0 | 511 | void _MD_unix_map_accept_error(int err) |
michael@0 | 512 | { |
michael@0 | 513 | PRErrorCode prError; |
michael@0 | 514 | |
michael@0 | 515 | switch (err) { |
michael@0 | 516 | case ENODEV: |
michael@0 | 517 | prError = PR_NOT_TCP_SOCKET_ERROR; |
michael@0 | 518 | break; |
michael@0 | 519 | default: |
michael@0 | 520 | _MD_unix_map_default_error(err); |
michael@0 | 521 | return; |
michael@0 | 522 | } |
michael@0 | 523 | PR_SetError(prError, err); |
michael@0 | 524 | } |
michael@0 | 525 | |
michael@0 | 526 | void _MD_unix_map_connect_error(int err) |
michael@0 | 527 | { |
michael@0 | 528 | PRErrorCode prError; |
michael@0 | 529 | |
michael@0 | 530 | switch (err) { |
michael@0 | 531 | #if defined(UNIXWARE) |
michael@0 | 532 | /* |
michael@0 | 533 | * On some platforms, if we connect to a port on the local host |
michael@0 | 534 | * (the loopback address) that no process is listening on, we get |
michael@0 | 535 | * EIO instead of ECONNREFUSED. |
michael@0 | 536 | */ |
michael@0 | 537 | case EIO: |
michael@0 | 538 | prError = PR_CONNECT_REFUSED_ERROR; |
michael@0 | 539 | break; |
michael@0 | 540 | #endif |
michael@0 | 541 | case ENXIO: |
michael@0 | 542 | prError = PR_IO_ERROR; |
michael@0 | 543 | break; |
michael@0 | 544 | default: |
michael@0 | 545 | _MD_unix_map_default_error(err); |
michael@0 | 546 | return; |
michael@0 | 547 | } |
michael@0 | 548 | PR_SetError(prError, err); |
michael@0 | 549 | } |
michael@0 | 550 | |
michael@0 | 551 | void _MD_unix_map_bind_error(int err) |
michael@0 | 552 | { |
michael@0 | 553 | PRErrorCode prError; |
michael@0 | 554 | |
michael@0 | 555 | switch (err) { |
michael@0 | 556 | case EINVAL: |
michael@0 | 557 | prError = PR_SOCKET_ADDRESS_IS_BOUND_ERROR; |
michael@0 | 558 | break; |
michael@0 | 559 | default: |
michael@0 | 560 | _MD_unix_map_default_error(err); |
michael@0 | 561 | return; |
michael@0 | 562 | } |
michael@0 | 563 | PR_SetError(prError, err); |
michael@0 | 564 | } |
michael@0 | 565 | |
michael@0 | 566 | void _MD_unix_map_listen_error(int err) |
michael@0 | 567 | { |
michael@0 | 568 | _MD_unix_map_default_error(err); |
michael@0 | 569 | } |
michael@0 | 570 | |
michael@0 | 571 | void _MD_unix_map_shutdown_error(int err) |
michael@0 | 572 | { |
michael@0 | 573 | _MD_unix_map_default_error(err); |
michael@0 | 574 | } |
michael@0 | 575 | |
michael@0 | 576 | void _MD_unix_map_socketpair_error(int err) |
michael@0 | 577 | { |
michael@0 | 578 | PRErrorCode prError; |
michael@0 | 579 | |
michael@0 | 580 | switch (err) { |
michael@0 | 581 | case ENOMEM: |
michael@0 | 582 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 583 | break; |
michael@0 | 584 | default: |
michael@0 | 585 | _MD_unix_map_default_error(err); |
michael@0 | 586 | return; |
michael@0 | 587 | } |
michael@0 | 588 | PR_SetError(prError, err); |
michael@0 | 589 | } |
michael@0 | 590 | |
michael@0 | 591 | void _MD_unix_map_getsockname_error(int err) |
michael@0 | 592 | { |
michael@0 | 593 | PRErrorCode prError; |
michael@0 | 594 | |
michael@0 | 595 | switch (err) { |
michael@0 | 596 | case ENOMEM: |
michael@0 | 597 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 598 | break; |
michael@0 | 599 | default: |
michael@0 | 600 | _MD_unix_map_default_error(err); |
michael@0 | 601 | return; |
michael@0 | 602 | } |
michael@0 | 603 | PR_SetError(prError, err); |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | void _MD_unix_map_getpeername_error(int err) |
michael@0 | 607 | { |
michael@0 | 608 | PRErrorCode prError; |
michael@0 | 609 | |
michael@0 | 610 | switch (err) { |
michael@0 | 611 | case ENOMEM: |
michael@0 | 612 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 613 | break; |
michael@0 | 614 | default: |
michael@0 | 615 | _MD_unix_map_default_error(err); |
michael@0 | 616 | return; |
michael@0 | 617 | } |
michael@0 | 618 | PR_SetError(prError, err); |
michael@0 | 619 | } |
michael@0 | 620 | |
michael@0 | 621 | void _MD_unix_map_getsockopt_error(int err) |
michael@0 | 622 | { |
michael@0 | 623 | PRErrorCode prError; |
michael@0 | 624 | |
michael@0 | 625 | switch (err) { |
michael@0 | 626 | case EINVAL: |
michael@0 | 627 | prError = PR_BUFFER_OVERFLOW_ERROR; |
michael@0 | 628 | break; |
michael@0 | 629 | case ENOMEM: |
michael@0 | 630 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 631 | break; |
michael@0 | 632 | default: |
michael@0 | 633 | _MD_unix_map_default_error(err); |
michael@0 | 634 | return; |
michael@0 | 635 | } |
michael@0 | 636 | PR_SetError(prError, err); |
michael@0 | 637 | } |
michael@0 | 638 | |
michael@0 | 639 | void _MD_unix_map_setsockopt_error(int err) |
michael@0 | 640 | { |
michael@0 | 641 | PRErrorCode prError; |
michael@0 | 642 | |
michael@0 | 643 | switch (err) { |
michael@0 | 644 | case EINVAL: |
michael@0 | 645 | prError = PR_BUFFER_OVERFLOW_ERROR; |
michael@0 | 646 | break; |
michael@0 | 647 | case ENOMEM: |
michael@0 | 648 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 649 | break; |
michael@0 | 650 | default: |
michael@0 | 651 | _MD_unix_map_default_error(err); |
michael@0 | 652 | return; |
michael@0 | 653 | } |
michael@0 | 654 | PR_SetError(prError, err); |
michael@0 | 655 | } |
michael@0 | 656 | |
michael@0 | 657 | void _MD_unix_map_open_error(int err) |
michael@0 | 658 | { |
michael@0 | 659 | PRErrorCode prError; |
michael@0 | 660 | |
michael@0 | 661 | switch (err) { |
michael@0 | 662 | case EAGAIN: |
michael@0 | 663 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 664 | break; |
michael@0 | 665 | case EBUSY: |
michael@0 | 666 | prError = PR_IO_ERROR; |
michael@0 | 667 | break; |
michael@0 | 668 | case ENODEV: |
michael@0 | 669 | prError = PR_FILE_NOT_FOUND_ERROR; |
michael@0 | 670 | break; |
michael@0 | 671 | case ENOMEM: |
michael@0 | 672 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 673 | break; |
michael@0 | 674 | #ifdef EOVERFLOW |
michael@0 | 675 | case EOVERFLOW: |
michael@0 | 676 | prError = PR_FILE_TOO_BIG_ERROR; |
michael@0 | 677 | break; |
michael@0 | 678 | #endif |
michael@0 | 679 | case ETIMEDOUT: |
michael@0 | 680 | prError = PR_REMOTE_FILE_ERROR; |
michael@0 | 681 | break; |
michael@0 | 682 | default: |
michael@0 | 683 | _MD_unix_map_default_error(err); |
michael@0 | 684 | return; |
michael@0 | 685 | } |
michael@0 | 686 | PR_SetError(prError, err); |
michael@0 | 687 | } |
michael@0 | 688 | |
michael@0 | 689 | void _MD_unix_map_mmap_error(int err) |
michael@0 | 690 | { |
michael@0 | 691 | PRErrorCode prError; |
michael@0 | 692 | |
michael@0 | 693 | switch (err) { |
michael@0 | 694 | case EAGAIN: |
michael@0 | 695 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 696 | break; |
michael@0 | 697 | case EMFILE: |
michael@0 | 698 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 699 | break; |
michael@0 | 700 | case ENODEV: |
michael@0 | 701 | prError = PR_OPERATION_NOT_SUPPORTED_ERROR; |
michael@0 | 702 | break; |
michael@0 | 703 | case ENXIO: |
michael@0 | 704 | prError = PR_INVALID_ARGUMENT_ERROR; |
michael@0 | 705 | break; |
michael@0 | 706 | default: |
michael@0 | 707 | _MD_unix_map_default_error(err); |
michael@0 | 708 | return; |
michael@0 | 709 | } |
michael@0 | 710 | PR_SetError(prError, err); |
michael@0 | 711 | } |
michael@0 | 712 | |
michael@0 | 713 | void _MD_unix_map_gethostname_error(int err) |
michael@0 | 714 | { |
michael@0 | 715 | _MD_unix_map_default_error(err); |
michael@0 | 716 | } |
michael@0 | 717 | |
michael@0 | 718 | void _MD_unix_map_select_error(int err) |
michael@0 | 719 | { |
michael@0 | 720 | _MD_unix_map_default_error(err); |
michael@0 | 721 | } |
michael@0 | 722 | |
michael@0 | 723 | #if defined(_PR_POLL_AVAILABLE) || defined(_PR_NEED_FAKE_POLL) |
michael@0 | 724 | void _MD_unix_map_poll_error(int err) |
michael@0 | 725 | { |
michael@0 | 726 | PRErrorCode prError; |
michael@0 | 727 | |
michael@0 | 728 | switch (err) { |
michael@0 | 729 | case EAGAIN: |
michael@0 | 730 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 731 | break; |
michael@0 | 732 | default: |
michael@0 | 733 | _MD_unix_map_default_error(err); |
michael@0 | 734 | return; |
michael@0 | 735 | } |
michael@0 | 736 | PR_SetError(prError, err); |
michael@0 | 737 | } |
michael@0 | 738 | |
michael@0 | 739 | void _MD_unix_map_poll_revents_error(int err) |
michael@0 | 740 | { |
michael@0 | 741 | if (err & POLLNVAL) |
michael@0 | 742 | PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF); |
michael@0 | 743 | else if (err & POLLHUP) |
michael@0 | 744 | PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE); |
michael@0 | 745 | else if (err & POLLERR) |
michael@0 | 746 | PR_SetError(PR_IO_ERROR, EIO); |
michael@0 | 747 | else |
michael@0 | 748 | PR_SetError(PR_UNKNOWN_ERROR, err); |
michael@0 | 749 | } |
michael@0 | 750 | #endif /* _PR_POLL_AVAILABLE || _PR_NEED_FAKE_POLL */ |
michael@0 | 751 | |
michael@0 | 752 | |
michael@0 | 753 | void _MD_unix_map_flock_error(int err) |
michael@0 | 754 | { |
michael@0 | 755 | PRErrorCode prError; |
michael@0 | 756 | |
michael@0 | 757 | switch (err) { |
michael@0 | 758 | case EINVAL: |
michael@0 | 759 | prError = PR_BAD_DESCRIPTOR_ERROR; |
michael@0 | 760 | break; |
michael@0 | 761 | case EWOULDBLOCK: |
michael@0 | 762 | prError = PR_FILE_IS_LOCKED_ERROR; |
michael@0 | 763 | break; |
michael@0 | 764 | default: |
michael@0 | 765 | _MD_unix_map_default_error(err); |
michael@0 | 766 | return; |
michael@0 | 767 | } |
michael@0 | 768 | PR_SetError(prError, err); |
michael@0 | 769 | } |
michael@0 | 770 | |
michael@0 | 771 | void _MD_unix_map_lockf_error(int err) |
michael@0 | 772 | { |
michael@0 | 773 | PRErrorCode prError; |
michael@0 | 774 | |
michael@0 | 775 | switch (err) { |
michael@0 | 776 | case EACCES: |
michael@0 | 777 | prError = PR_FILE_IS_LOCKED_ERROR; |
michael@0 | 778 | break; |
michael@0 | 779 | case EDEADLK: |
michael@0 | 780 | prError = PR_INSUFFICIENT_RESOURCES_ERROR; |
michael@0 | 781 | break; |
michael@0 | 782 | default: |
michael@0 | 783 | _MD_unix_map_default_error(err); |
michael@0 | 784 | return; |
michael@0 | 785 | } |
michael@0 | 786 | PR_SetError(prError, err); |
michael@0 | 787 | } |
michael@0 | 788 | |
michael@0 | 789 | #ifdef AIX |
michael@0 | 790 | void _MD_aix_map_sendfile_error(int err) |
michael@0 | 791 | { |
michael@0 | 792 | _MD_unix_map_default_error(err); |
michael@0 | 793 | } |
michael@0 | 794 | #endif /* AIX */ |
michael@0 | 795 | |
michael@0 | 796 | #ifdef HPUX11 |
michael@0 | 797 | void _MD_hpux_map_sendfile_error(int err) |
michael@0 | 798 | { |
michael@0 | 799 | _MD_unix_map_default_error(err); |
michael@0 | 800 | } |
michael@0 | 801 | #endif /* HPUX11 */ |
michael@0 | 802 | |
michael@0 | 803 | #ifdef SOLARIS |
michael@0 | 804 | void _MD_solaris_map_sendfile_error(int err) |
michael@0 | 805 | { |
michael@0 | 806 | PRErrorCode prError; |
michael@0 | 807 | |
michael@0 | 808 | switch (err) { |
michael@0 | 809 | /* |
michael@0 | 810 | * Solaris defines a 0 return value for sendfile to mean end-of-file. |
michael@0 | 811 | */ |
michael@0 | 812 | case 0: |
michael@0 | 813 | prError = PR_END_OF_FILE_ERROR; |
michael@0 | 814 | break; |
michael@0 | 815 | |
michael@0 | 816 | default: |
michael@0 | 817 | _MD_unix_map_default_error(err) ; |
michael@0 | 818 | return; |
michael@0 | 819 | } |
michael@0 | 820 | PR_SetError(prError, err); |
michael@0 | 821 | } |
michael@0 | 822 | #endif /* SOLARIS */ |
michael@0 | 823 | |
michael@0 | 824 | #ifdef LINUX |
michael@0 | 825 | void _MD_linux_map_sendfile_error(int err) |
michael@0 | 826 | { |
michael@0 | 827 | _MD_unix_map_default_error(err) ; |
michael@0 | 828 | } |
michael@0 | 829 | #endif /* LINUX */ |