libuv-svace-build
173 строки · 8.3 Кб
1/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2*
3* Permission is hereby granted, free of charge, to any person obtaining a copy
4* of this software and associated documentation files (the "Software"), to
5* deal in the Software without restriction, including without limitation the
6* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7* sell copies of the Software, and to permit persons to whom the Software is
8* furnished to do so, subject to the following conditions:
9*
10* The above copyright notice and this permission notice shall be included in
11* all copies or substantial portions of the Software.
12*
13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19* IN THE SOFTWARE.
20*/
21
22#include <assert.h>23#include <errno.h>24#include <stdio.h>25#include <string.h>26#include <stdlib.h>27
28#include "uv.h"29#include "internal.h"30
31
32/*
33* Display an error message and abort the event loop.
34*/
35void uv_fatal_error(const int errorno, const char* syscall) {36char* buf = NULL;37const char* errmsg;38
39FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |40FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,41MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buf, 0, NULL);42
43if (buf) {44errmsg = buf;45} else {46errmsg = "Unknown error";47}48
49/* FormatMessage messages include a newline character already, so don't add50* another. */
51if (syscall) {52fprintf(stderr, "%s: (%d) %s", syscall, errorno, errmsg);53} else {54fprintf(stderr, "(%d) %s", errorno, errmsg);55}56
57if (buf) {58LocalFree(buf);59}60
61DebugBreak();62abort();63}
64
65
66int uv_translate_sys_error(int sys_errno) {67if (sys_errno <= 0) {68return sys_errno; /* If < 0 then it's already a libuv error. */69}70
71switch (sys_errno) {72case ERROR_NOACCESS: return UV_EACCES;73case WSAEACCES: return UV_EACCES;74case ERROR_ELEVATION_REQUIRED: return UV_EACCES;75case ERROR_CANT_ACCESS_FILE: return UV_EACCES;76case ERROR_ADDRESS_ALREADY_ASSOCIATED: return UV_EADDRINUSE;77case WSAEADDRINUSE: return UV_EADDRINUSE;78case WSAEADDRNOTAVAIL: return UV_EADDRNOTAVAIL;79case WSAEAFNOSUPPORT: return UV_EAFNOSUPPORT;80case WSAEWOULDBLOCK: return UV_EAGAIN;81case WSAEALREADY: return UV_EALREADY;82case ERROR_INVALID_FLAGS: return UV_EBADF;83case ERROR_INVALID_HANDLE: return UV_EBADF;84case ERROR_LOCK_VIOLATION: return UV_EBUSY;85case ERROR_PIPE_BUSY: return UV_EBUSY;86case ERROR_SHARING_VIOLATION: return UV_EBUSY;87case ERROR_OPERATION_ABORTED: return UV_ECANCELED;88case WSAEINTR: return UV_ECANCELED;89case ERROR_NO_UNICODE_TRANSLATION: return UV_ECHARSET;90case ERROR_CONNECTION_ABORTED: return UV_ECONNABORTED;91case WSAECONNABORTED: return UV_ECONNABORTED;92case ERROR_CONNECTION_REFUSED: return UV_ECONNREFUSED;93case WSAECONNREFUSED: return UV_ECONNREFUSED;94case ERROR_NETNAME_DELETED: return UV_ECONNRESET;95case WSAECONNRESET: return UV_ECONNRESET;96case ERROR_ALREADY_EXISTS: return UV_EEXIST;97case ERROR_FILE_EXISTS: return UV_EEXIST;98case ERROR_BUFFER_OVERFLOW: return UV_EFAULT;99case WSAEFAULT: return UV_EFAULT;100case ERROR_HOST_UNREACHABLE: return UV_EHOSTUNREACH;101case WSAEHOSTUNREACH: return UV_EHOSTUNREACH;102case ERROR_INSUFFICIENT_BUFFER: return UV_EINVAL;103case ERROR_INVALID_DATA: return UV_EINVAL;104case ERROR_INVALID_PARAMETER: return UV_EINVAL;105case ERROR_SYMLINK_NOT_SUPPORTED: return UV_EINVAL;106case WSAEINVAL: return UV_EINVAL;107case WSAEPFNOSUPPORT: return UV_EINVAL;108case ERROR_BEGINNING_OF_MEDIA: return UV_EIO;109case ERROR_BUS_RESET: return UV_EIO;110case ERROR_CRC: return UV_EIO;111case ERROR_DEVICE_DOOR_OPEN: return UV_EIO;112case ERROR_DEVICE_REQUIRES_CLEANING: return UV_EIO;113case ERROR_DISK_CORRUPT: return UV_EIO;114case ERROR_EOM_OVERFLOW: return UV_EIO;115case ERROR_FILEMARK_DETECTED: return UV_EIO;116case ERROR_GEN_FAILURE: return UV_EIO;117case ERROR_INVALID_BLOCK_LENGTH: return UV_EIO;118case ERROR_IO_DEVICE: return UV_EIO;119case ERROR_NO_DATA_DETECTED: return UV_EIO;120case ERROR_NO_SIGNAL_SENT: return UV_EIO;121case ERROR_OPEN_FAILED: return UV_EIO;122case ERROR_SETMARK_DETECTED: return UV_EIO;123case ERROR_SIGNAL_REFUSED: return UV_EIO;124case WSAEISCONN: return UV_EISCONN;125case ERROR_CANT_RESOLVE_FILENAME: return UV_ELOOP;126case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE;127case WSAEMFILE: return UV_EMFILE;128case WSAEMSGSIZE: return UV_EMSGSIZE;129case ERROR_FILENAME_EXCED_RANGE: return UV_ENAMETOOLONG;130case ERROR_NETWORK_UNREACHABLE: return UV_ENETUNREACH;131case WSAENETUNREACH: return UV_ENETUNREACH;132case WSAENOBUFS: return UV_ENOBUFS;133case ERROR_BAD_PATHNAME: return UV_ENOENT;134case ERROR_DIRECTORY: return UV_ENOENT;135case ERROR_ENVVAR_NOT_FOUND: return UV_ENOENT;136case ERROR_FILE_NOT_FOUND: return UV_ENOENT;137case ERROR_INVALID_NAME: return UV_ENOENT;138case ERROR_INVALID_DRIVE: return UV_ENOENT;139case ERROR_INVALID_REPARSE_DATA: return UV_ENOENT;140case ERROR_MOD_NOT_FOUND: return UV_ENOENT;141case ERROR_PATH_NOT_FOUND: return UV_ENOENT;142case WSAHOST_NOT_FOUND: return UV_ENOENT;143case WSANO_DATA: return UV_ENOENT;144case ERROR_NOT_ENOUGH_MEMORY: return UV_ENOMEM;145case ERROR_OUTOFMEMORY: return UV_ENOMEM;146case ERROR_CANNOT_MAKE: return UV_ENOSPC;147case ERROR_DISK_FULL: return UV_ENOSPC;148case ERROR_EA_TABLE_FULL: return UV_ENOSPC;149case ERROR_END_OF_MEDIA: return UV_ENOSPC;150case ERROR_HANDLE_DISK_FULL: return UV_ENOSPC;151case ERROR_NOT_CONNECTED: return UV_ENOTCONN;152case WSAENOTCONN: return UV_ENOTCONN;153case ERROR_DIR_NOT_EMPTY: return UV_ENOTEMPTY;154case WSAENOTSOCK: return UV_ENOTSOCK;155case ERROR_NOT_SUPPORTED: return UV_ENOTSUP;156case ERROR_BROKEN_PIPE: return UV_EOF;157case ERROR_ACCESS_DENIED: return UV_EPERM;158case ERROR_PRIVILEGE_NOT_HELD: return UV_EPERM;159case ERROR_BAD_PIPE: return UV_EPIPE;160case ERROR_NO_DATA: return UV_EPIPE;161case ERROR_PIPE_NOT_CONNECTED: return UV_EPIPE;162case WSAESHUTDOWN: return UV_EPIPE;163case WSAEPROTONOSUPPORT: return UV_EPROTONOSUPPORT;164case ERROR_WRITE_PROTECT: return UV_EROFS;165case ERROR_SEM_TIMEOUT: return UV_ETIMEDOUT;166case WSAETIMEDOUT: return UV_ETIMEDOUT;167case ERROR_NOT_SAME_DEVICE: return UV_EXDEV;168case ERROR_INVALID_FUNCTION: return UV_EISDIR;169case ERROR_META_EXPANSION_TOO_LONG: return UV_E2BIG;170case WSAESOCKTNOSUPPORT: return UV_ESOCKTNOSUPPORT;171default: return UV_UNKNOWN;172}173}
174