2000-02-18 03:38:33 +08:00
|
|
|
/* errno.cc: errno-related functions
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
#define _sys_nerr FOO_sys_nerr
|
|
|
|
#define sys_nerr FOOsys_nerr
|
2003-05-11 08:10:11 +08:00
|
|
|
#define _sys_errlist FOO_sys_errlist
|
2011-02-11 04:25:54 +08:00
|
|
|
#define strerror_r FOO_strerror_r
|
2011-05-18 09:25:41 +08:00
|
|
|
#define __INSIDE_CYGWIN__
|
|
|
|
#include <errno.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2003-12-24 00:26:31 +08:00
|
|
|
#include "cygtls.h"
|
2010-04-16 23:42:29 +08:00
|
|
|
#include "ntdll.h"
|
2001-10-14 01:23:35 +08:00
|
|
|
#undef _sys_nerr
|
|
|
|
#undef sys_nerr
|
2003-05-11 08:10:11 +08:00
|
|
|
#undef _sys_errlist
|
2011-02-11 04:25:54 +08:00
|
|
|
#undef strerror_r
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Table to map Windows error codes to Errno values. */
|
|
|
|
/* FIXME: Doing things this way is a little slow. It's trivial to change
|
|
|
|
this into a big case statement if necessary. Left as is for now. */
|
|
|
|
|
|
|
|
#define X(w, e) {ERROR_##w, #w, e}
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
static const struct
|
2003-05-11 08:10:11 +08:00
|
|
|
{
|
|
|
|
DWORD w; /* windows version of error */
|
|
|
|
const char *s; /* text of windows version */
|
|
|
|
int e; /* errno version of error */
|
|
|
|
} errmap[] =
|
2003-05-10 01:58:20 +08:00
|
|
|
{
|
|
|
|
/* FIXME: Some of these choices are arbitrary! */
|
|
|
|
X (ACCESS_DENIED, EACCES),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (ACTIVE_CONNECTIONS, EAGAIN),
|
|
|
|
X (ALREADY_EXISTS, EEXIST),
|
|
|
|
X (BAD_DEVICE, ENODEV),
|
2011-01-19 17:15:17 +08:00
|
|
|
X (BAD_EXE_FORMAT, ENOEXEC),
|
2009-01-12 00:13:11 +08:00
|
|
|
X (BAD_NETPATH, ENOENT),
|
|
|
|
X (BAD_NET_NAME, ENOENT),
|
2010-09-24 20:41:33 +08:00
|
|
|
X (BAD_NET_RESP, ENOSYS),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (BAD_PATHNAME, ENOENT),
|
|
|
|
X (BAD_PIPE, EINVAL),
|
|
|
|
X (BAD_UNIT, ENODEV),
|
|
|
|
X (BAD_USERNAME, EINVAL),
|
|
|
|
X (BEGINNING_OF_MEDIA, EIO),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (BROKEN_PIPE, EPIPE),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (BUSY, EBUSY),
|
|
|
|
X (BUS_RESET, EIO),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (CALL_NOT_IMPLEMENTED, ENOSYS),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (CANCELLED, EINTR),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (CANNOT_MAKE, EPERM),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (CHILD_NOT_COMPLETE, EBUSY),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (COMMITMENT_LIMIT, EAGAIN),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (CONNECTION_REFUSED, ECONNREFUSED),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (CRC, EIO),
|
|
|
|
X (DEVICE_DOOR_OPEN, EIO),
|
|
|
|
X (DEVICE_IN_USE, EAGAIN),
|
|
|
|
X (DEVICE_REQUIRES_CLEANING, EIO),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (DEV_NOT_EXIST, ENOENT),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (DIRECTORY, ENOTDIR),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (DIR_NOT_EMPTY, ENOTEMPTY),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (DISK_CORRUPT, EIO),
|
|
|
|
X (DISK_FULL, ENOSPC),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (DS_GENERIC_ERROR, EIO),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (DUP_NAME, ENOTUNIQ),
|
* Makefile.in (DLL_OFILES): Add ntea.o.
* cygwin.din (getxattr, listxattr, removexattr, setxattr, lgetxattr,
llistxattr, lremovexattr, lsetxattr, fgetxattr, flistxattr,
fremovexattr, fsetxattr): Export Linux extended attribute functions.
Sort.
* errno.cc (errmap): Add mappings for ERROR_EAS_DIDNT_FIT,
ERROR_EAS_NOT_SUPPORTED, ERROR_EA_LIST_INCONSISTENT,
ERROR_EA_TABLE_FULL, ERROR_FILE_CORRUPT, ERROR_INVALID_EA_NAME.
* fhandler.h (class fhandler_base): Declare new fgetxattr and
fsetxattr methods.
(class fhandler_disk_file): Ditto.
* fhandler.cc (fhandler_base::fgetxattr): New method.
(fhandler_base::fsetxattr): New method.
* fhandler_disk_file.cc (fhandler_disk_file::fgetxattr): New method.
(fhandler_disk_file::fsetxattr): New method.
* ntdll.h (STATUS_EA_TOO_LARGE): Define.
(STATUS_NONEXISTENT_EA_ENTRY): Define.
(STATUS_NO_EAS_ON_FILE): Define.
* ntea.cc (read_ea): Rewrite for long pathnames and for using with
Linux extended attribute functions.
(write_ea): Ditto.
(getxattr_worker): New static function.
(getxattr): New function.
(lgetxattr): New function.
(fgetxattr): New function.
(listxattr): New function.
(llistxattr): New function.
(flistxattr): New function.
(setxattr_worker): New static function.
(setxattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
(removexattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
* security.h (read_ea): Change declaration according to above changes.
(write_ea): Ditto.
* include/cygwin/version.h: Bump API minor version.
2008-02-10 23:43:04 +08:00
|
|
|
X (EAS_DIDNT_FIT, ENOSPC),
|
|
|
|
X (EAS_NOT_SUPPORTED, ENOTSUP),
|
|
|
|
X (EA_LIST_INCONSISTENT, EINVAL),
|
|
|
|
X (EA_TABLE_FULL, ENOSPC),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (END_OF_MEDIA, ENOSPC),
|
|
|
|
X (EOM_OVERFLOW, EIO),
|
2011-04-30 02:54:23 +08:00
|
|
|
X (EXE_MACHINE_TYPE_MISMATCH, ENOEXEC),
|
2011-01-19 17:15:17 +08:00
|
|
|
X (EXE_MARKED_INVALID, ENOEXEC),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (FILEMARK_DETECTED, EIO),
|
2005-03-29 02:06:49 +08:00
|
|
|
X (FILENAME_EXCED_RANGE, ENAMETOOLONG),
|
* Makefile.in (DLL_OFILES): Add ntea.o.
* cygwin.din (getxattr, listxattr, removexattr, setxattr, lgetxattr,
llistxattr, lremovexattr, lsetxattr, fgetxattr, flistxattr,
fremovexattr, fsetxattr): Export Linux extended attribute functions.
Sort.
* errno.cc (errmap): Add mappings for ERROR_EAS_DIDNT_FIT,
ERROR_EAS_NOT_SUPPORTED, ERROR_EA_LIST_INCONSISTENT,
ERROR_EA_TABLE_FULL, ERROR_FILE_CORRUPT, ERROR_INVALID_EA_NAME.
* fhandler.h (class fhandler_base): Declare new fgetxattr and
fsetxattr methods.
(class fhandler_disk_file): Ditto.
* fhandler.cc (fhandler_base::fgetxattr): New method.
(fhandler_base::fsetxattr): New method.
* fhandler_disk_file.cc (fhandler_disk_file::fgetxattr): New method.
(fhandler_disk_file::fsetxattr): New method.
* ntdll.h (STATUS_EA_TOO_LARGE): Define.
(STATUS_NONEXISTENT_EA_ENTRY): Define.
(STATUS_NO_EAS_ON_FILE): Define.
* ntea.cc (read_ea): Rewrite for long pathnames and for using with
Linux extended attribute functions.
(write_ea): Ditto.
(getxattr_worker): New static function.
(getxattr): New function.
(lgetxattr): New function.
(fgetxattr): New function.
(listxattr): New function.
(llistxattr): New function.
(flistxattr): New function.
(setxattr_worker): New static function.
(setxattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
(removexattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
* security.h (read_ea): Change declaration according to above changes.
(write_ea): Ditto.
* include/cygwin/version.h: Bump API minor version.
2008-02-10 23:43:04 +08:00
|
|
|
X (FILE_CORRUPT, EEXIST),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (FILE_EXISTS, EEXIST),
|
|
|
|
X (FILE_INVALID, ENXIO),
|
|
|
|
X (FILE_NOT_FOUND, ENOENT),
|
|
|
|
X (HANDLE_DISK_FULL, ENOSPC),
|
|
|
|
X (HANDLE_EOF, ENODATA),
|
|
|
|
X (INVALID_ADDRESS, EINVAL),
|
|
|
|
X (INVALID_AT_INTERRUPT_TIME, EINTR),
|
|
|
|
X (INVALID_BLOCK_LENGTH, EIO),
|
|
|
|
X (INVALID_DATA, EINVAL),
|
|
|
|
X (INVALID_DRIVE, ENODEV),
|
* Makefile.in (DLL_OFILES): Add ntea.o.
* cygwin.din (getxattr, listxattr, removexattr, setxattr, lgetxattr,
llistxattr, lremovexattr, lsetxattr, fgetxattr, flistxattr,
fremovexattr, fsetxattr): Export Linux extended attribute functions.
Sort.
* errno.cc (errmap): Add mappings for ERROR_EAS_DIDNT_FIT,
ERROR_EAS_NOT_SUPPORTED, ERROR_EA_LIST_INCONSISTENT,
ERROR_EA_TABLE_FULL, ERROR_FILE_CORRUPT, ERROR_INVALID_EA_NAME.
* fhandler.h (class fhandler_base): Declare new fgetxattr and
fsetxattr methods.
(class fhandler_disk_file): Ditto.
* fhandler.cc (fhandler_base::fgetxattr): New method.
(fhandler_base::fsetxattr): New method.
* fhandler_disk_file.cc (fhandler_disk_file::fgetxattr): New method.
(fhandler_disk_file::fsetxattr): New method.
* ntdll.h (STATUS_EA_TOO_LARGE): Define.
(STATUS_NONEXISTENT_EA_ENTRY): Define.
(STATUS_NO_EAS_ON_FILE): Define.
* ntea.cc (read_ea): Rewrite for long pathnames and for using with
Linux extended attribute functions.
(write_ea): Ditto.
(getxattr_worker): New static function.
(getxattr): New function.
(lgetxattr): New function.
(fgetxattr): New function.
(listxattr): New function.
(llistxattr): New function.
(flistxattr): New function.
(setxattr_worker): New static function.
(setxattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
(removexattr): New function.
(lsetxattr): New function.
(fsetxattr): New function.
* security.h (read_ea): Change declaration according to above changes.
(write_ea): Ditto.
* include/cygwin/version.h: Bump API minor version.
2008-02-10 23:43:04 +08:00
|
|
|
X (INVALID_EA_NAME, EINVAL),
|
2011-01-19 17:15:17 +08:00
|
|
|
X (INVALID_EXE_SIGNATURE, ENOEXEC),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (INVALID_FUNCTION, EBADRQC),
|
|
|
|
X (INVALID_HANDLE, EBADF),
|
|
|
|
X (INVALID_NAME, ENOENT),
|
|
|
|
X (INVALID_PARAMETER, EINVAL),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (INVALID_SIGNAL_NUMBER, EINVAL),
|
2011-01-19 17:15:17 +08:00
|
|
|
X (IOPL_NOT_ENABLED, ENOEXEC),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (IO_DEVICE, EIO),
|
2011-04-30 02:54:23 +08:00
|
|
|
X (IO_INCOMPLETE, EAGAIN),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (IO_PENDING, EAGAIN),
|
2013-01-19 00:09:51 +08:00
|
|
|
X (LOCK_VIOLATION, EBUSY),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (MAX_THRDS_REACHED, EAGAIN),
|
|
|
|
X (META_EXPANSION_TOO_LONG, EINVAL),
|
2005-05-22 11:54:29 +08:00
|
|
|
X (MOD_NOT_FOUND, ENOENT),
|
2006-09-08 04:42:53 +08:00
|
|
|
X (MORE_DATA, EMSGSIZE),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NEGATIVE_SEEK, EINVAL),
|
2009-01-12 00:13:11 +08:00
|
|
|
X (NETNAME_DELETED, ENOENT),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NOACCESS, EFAULT),
|
2008-07-11 18:00:36 +08:00
|
|
|
X (NONE_MAPPED, EINVAL),
|
2011-04-30 02:54:23 +08:00
|
|
|
X (NONPAGED_SYSTEM_RESOURCES, EAGAIN),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (NOT_CONNECTED, ENOLINK),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NOT_ENOUGH_MEMORY, ENOMEM),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (NOT_ENOUGH_QUOTA, EIO),
|
2003-05-10 01:58:20 +08:00
|
|
|
X (NOT_OWNER, EPERM),
|
|
|
|
X (NOT_READY, ENOMEDIUM),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NOT_SAME_DEVICE, EXDEV),
|
|
|
|
X (NOT_SUPPORTED, ENOSYS),
|
|
|
|
X (NO_DATA, EPIPE),
|
|
|
|
X (NO_DATA_DETECTED, EIO),
|
2004-03-27 05:43:49 +08:00
|
|
|
X (NO_MEDIA_IN_DRIVE, ENOMEDIUM),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NO_MORE_FILES, ENMFILE),
|
2005-08-25 23:27:10 +08:00
|
|
|
X (NO_MORE_ITEMS, ENMFILE),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NO_MORE_SEARCH_HANDLES, ENFILE),
|
|
|
|
X (NO_PROC_SLOTS, EAGAIN),
|
|
|
|
X (NO_SIGNAL_SENT, EIO),
|
2011-03-10 00:47:44 +08:00
|
|
|
X (NO_SYSTEM_RESOURCES, EFBIG),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (NO_TOKEN, EINVAL),
|
|
|
|
X (OPEN_FAILED, EIO),
|
|
|
|
X (OPEN_FILES, EAGAIN),
|
|
|
|
X (OUTOFMEMORY, ENOMEM),
|
2005-03-31 06:07:20 +08:00
|
|
|
X (PAGED_SYSTEM_RESOURCES, EAGAIN),
|
|
|
|
X (PAGEFILE_QUOTA, EAGAIN),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (PATH_NOT_FOUND, ENOENT),
|
|
|
|
X (PIPE_BUSY, EBUSY),
|
|
|
|
X (PIPE_CONNECTED, EBUSY),
|
|
|
|
X (PIPE_LISTENING, ECOMM),
|
|
|
|
X (PIPE_NOT_CONNECTED, ECOMM),
|
|
|
|
X (POSSIBLE_DEADLOCK, EDEADLOCK),
|
2012-08-15 02:38:22 +08:00
|
|
|
X (PRIVILEGE_NOT_HELD, EPERM),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (PROCESS_ABORTED, EFAULT),
|
|
|
|
X (PROC_NOT_FOUND, ESRCH),
|
|
|
|
X (REM_NOT_LIST, ENONET),
|
2011-04-30 02:54:23 +08:00
|
|
|
X (SECTOR_NOT_FOUND, EINVAL),
|
|
|
|
X (SEEK, EINVAL),
|
2014-06-25 18:01:58 +08:00
|
|
|
X (SERVICE_REQUEST_TIMEOUT, EBUSY),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (SETMARK_DETECTED, EIO),
|
|
|
|
X (SHARING_BUFFER_EXCEEDED, ENOLCK),
|
|
|
|
X (SHARING_VIOLATION, EBUSY),
|
|
|
|
X (SIGNAL_PENDING, EBUSY),
|
|
|
|
X (SIGNAL_REFUSED, EIO),
|
2012-08-14 22:56:19 +08:00
|
|
|
X (SXS_CANT_GEN_ACTCTX, ELIBBAD),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (THREAD_1_INACTIVE, EINVAL),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (TIMEOUT, EBUSY),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (TOO_MANY_LINKS, EMLINK),
|
|
|
|
X (TOO_MANY_OPEN_FILES, EMFILE),
|
2014-06-25 17:59:38 +08:00
|
|
|
X (UNEXP_NET_ERR, EIO),
|
2005-04-30 12:10:39 +08:00
|
|
|
X (WAIT_NO_CHILDREN, ECHILD),
|
|
|
|
X (WORKING_SET_QUOTA, EAGAIN),
|
|
|
|
X (WRITE_PROTECT, EROFS),
|
2003-05-10 01:58:20 +08:00
|
|
|
{ 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
extern "C" {
|
2013-04-23 17:44:36 +08:00
|
|
|
const char *_sys_errlist[] =
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-08-20 02:26:58 +08:00
|
|
|
/* NOERROR 0 */ "No error",
|
|
|
|
/* EPERM 1 */ "Operation not permitted",
|
|
|
|
/* ENOENT 2 */ "No such file or directory",
|
|
|
|
/* ESRCH 3 */ "No such process",
|
|
|
|
/* EINTR 4 */ "Interrupted system call",
|
2011-06-16 01:36:10 +08:00
|
|
|
/* EIO 5 */ "Input/output error",
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ENXIO 6 */ "No such device or address",
|
|
|
|
/* E2BIG 7 */ "Argument list too long",
|
|
|
|
/* ENOEXEC 8 */ "Exec format error",
|
|
|
|
/* EBADF 9 */ "Bad file descriptor",
|
|
|
|
/* ECHILD 10 */ "No child processes",
|
|
|
|
/* EAGAIN 11 */ "Resource temporarily unavailable",
|
|
|
|
/* ENOMEM 12 */ "Cannot allocate memory",
|
|
|
|
/* EACCES 13 */ "Permission denied",
|
|
|
|
/* EFAULT 14 */ "Bad address",
|
|
|
|
/* ENOTBLK 15 */ "Block device required",
|
|
|
|
/* EBUSY 16 */ "Device or resource busy",
|
|
|
|
/* EEXIST 17 */ "File exists",
|
|
|
|
/* EXDEV 18 */ "Invalid cross-device link",
|
|
|
|
/* ENODEV 19 */ "No such device",
|
|
|
|
/* ENOTDIR 20 */ "Not a directory",
|
|
|
|
/* EISDIR 21 */ "Is a directory",
|
|
|
|
/* EINVAL 22 */ "Invalid argument",
|
|
|
|
/* ENFILE 23 */ "Too many open files in system",
|
|
|
|
/* EMFILE 24 */ "Too many open files",
|
|
|
|
/* ENOTTY 25 */ "Inappropriate ioctl for device",
|
|
|
|
/* ETXTBSY 26 */ "Text file busy",
|
|
|
|
/* EFBIG 27 */ "File too large",
|
|
|
|
/* ENOSPC 28 */ "No space left on device",
|
|
|
|
/* ESPIPE 29 */ "Illegal seek",
|
|
|
|
/* EROFS 30 */ "Read-only file system",
|
|
|
|
/* EMLINK 31 */ "Too many links",
|
|
|
|
/* EPIPE 32 */ "Broken pipe",
|
|
|
|
/* EDOM 33 */ "Numerical argument out of domain",
|
|
|
|
/* ERANGE 34 */ "Numerical result out of range",
|
|
|
|
/* ENOMSG 35 */ "No message of desired type",
|
|
|
|
/* EIDRM 36 */ "Identifier removed",
|
|
|
|
/* ECHRNG 37 */ "Channel number out of range",
|
|
|
|
/* EL2NSYNC 38 */ "Level 2 not synchronized",
|
|
|
|
/* EL3HLT 39 */ "Level 3 halted",
|
|
|
|
/* EL3RST 40 */ "Level 3 reset",
|
|
|
|
/* ELNRNG 41 */ "Link number out of range",
|
|
|
|
/* EUNATCH 42 */ "Protocol driver not attached",
|
|
|
|
/* ENOCSI 43 */ "No CSI structure available",
|
|
|
|
/* EL2HLT 44 */ "Level 2 halted",
|
|
|
|
/* EDEADLK 45 */ "Resource deadlock avoided",
|
|
|
|
/* ENOLCK 46 */ "No locks available",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* EBADE 50 */ "Invalid exchange",
|
|
|
|
/* EBADR 51 */ "Invalid request descriptor",
|
|
|
|
/* EXFULL 52 */ "Exchange full",
|
|
|
|
/* ENOANO 53 */ "No anode",
|
|
|
|
/* EBADRQC 54 */ "Invalid request code",
|
|
|
|
/* EBADSLT 55 */ "Invalid slot",
|
|
|
|
/* EDEADLOCK 56 */ "File locking deadlock error",
|
|
|
|
/* EBFONT 57 */ "Bad font file format",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ENOSTR 60 */ "Device not a stream",
|
|
|
|
/* ENODATA 61 */ "No data available",
|
|
|
|
/* ETIME 62 */ "Timer expired",
|
|
|
|
/* ENOSR 63 */ "Out of streams resources",
|
|
|
|
/* ENONET 64 */ "Machine is not on the network",
|
|
|
|
/* ENOPKG 65 */ "Package not installed",
|
|
|
|
/* EREMOTE 66 */ "Object is remote",
|
|
|
|
/* ENOLINK 67 */ "Link has been severed",
|
|
|
|
/* EADV 68 */ "Advertise error",
|
|
|
|
/* ESRMNT 69 */ "Srmount error",
|
|
|
|
/* ECOMM 70 */ "Communication error on send",
|
|
|
|
/* EPROTO 71 */ "Protocol error",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* EMULTIHOP 74 */ "Multihop attempted",
|
|
|
|
/* ELBIN 75 */ "Inode is remote (not really error)",
|
|
|
|
/* EDOTDOT 76 */ "RFS specific error",
|
|
|
|
/* EBADMSG 77 */ "Bad message",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* EFTYPE 79 */ "Inappropriate file type or format",
|
|
|
|
/* ENOTUNIQ 80 */ "Name not unique on network",
|
|
|
|
/* EBADFD 81 */ "File descriptor in bad state",
|
|
|
|
/* EREMCHG 82 */ "Remote address changed",
|
|
|
|
/* ELIBACC 83 */ "Can not access a needed shared library",
|
|
|
|
/* ELIBBAD 84 */ "Accessing a corrupted shared library",
|
|
|
|
/* ELIBSCN 85 */ ".lib section in a.out corrupted",
|
|
|
|
/* ELIBMAX 86 */ "Attempting to link in too many shared libraries",
|
|
|
|
/* ELIBEXEC 87 */ "Cannot exec a shared library directly",
|
|
|
|
/* ENOSYS 88 */ "Function not implemented",
|
|
|
|
/* ENMFILE 89 */ "No more files",
|
|
|
|
/* ENOTEMPTY 90 */ "Directory not empty",
|
|
|
|
/* ENAMETOOLONG 91 */ "File name too long",
|
|
|
|
/* ELOOP 92 */ "Too many levels of symbolic links",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* EOPNOTSUPP 95 */ "Operation not supported",
|
|
|
|
/* EPFNOSUPPORT 96 */ "Protocol family not supported",
|
2011-02-11 01:36:51 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ECONNRESET 104 */ "Connection reset by peer",
|
|
|
|
/* ENOBUFS 105 */ "No buffer space available",
|
|
|
|
/* EAFNOSUPPORT 106 */ "Address family not supported by protocol",
|
|
|
|
/* EPROTOTYPE 107 */ "Protocol wrong type for socket",
|
2008-09-20 07:29:24 +08:00
|
|
|
/* ENOTSOCK 108 */ "Socket operation on non-socket",
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ENOPROTOOPT 109 */ "Protocol not available",
|
|
|
|
/* ESHUTDOWN 110 */ "Cannot send after transport endpoint shutdown",
|
|
|
|
/* ECONNREFUSED 111 */ "Connection refused",
|
|
|
|
/* EADDRINUSE 112 */ "Address already in use",
|
|
|
|
/* ECONNABORTED 113 */ "Software caused connection abort",
|
|
|
|
/* ENETUNREACH 114 */ "Network is unreachable",
|
|
|
|
/* ENETDOWN 115 */ "Network is down",
|
|
|
|
/* ETIMEDOUT 116 */ "Connection timed out",
|
|
|
|
/* EHOSTDOWN 117 */ "Host is down",
|
|
|
|
/* EHOSTUNREACH 118 */ "No route to host",
|
|
|
|
/* EINPROGRESS 119 */ "Operation now in progress",
|
|
|
|
/* EALREADY 120 */ "Operation already in progress",
|
|
|
|
/* EDESTADDRREQ 121 */ "Destination address required",
|
|
|
|
/* EMSGSIZE 122 */ "Message too long",
|
2000-02-18 03:38:33 +08:00
|
|
|
/* EPROTONOSUPPORT 123 */ "Protocol not supported",
|
|
|
|
/* ESOCKTNOSUPPORT 124 */ "Socket type not supported",
|
2004-08-20 02:26:58 +08:00
|
|
|
/* EADDRNOTAVAIL 125 */ "Cannot assign requested address",
|
|
|
|
/* ENETRESET 126 */ "Network dropped connection on reset",
|
|
|
|
/* EISCONN 127 */ "Transport endpoint is already connected",
|
|
|
|
/* ENOTCONN 128 */ "Transport endpoint is not connected",
|
|
|
|
/* ETOOMANYREFS 129 */ "Too many references: cannot splice",
|
|
|
|
/* EPROCLIM 130 */ "Too many processes",
|
|
|
|
/* EUSERS 131 */ "Too many users",
|
|
|
|
/* EDQUOT 132 */ "Disk quota exceeded",
|
|
|
|
/* ESTALE 133 */ "Stale NFS file handle",
|
2008-09-20 07:29:24 +08:00
|
|
|
/* ENOTSUP 134 */ "Not supported",
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ENOMEDIUM 135 */ "No medium found",
|
2008-09-20 07:29:24 +08:00
|
|
|
/* ENOSHARE 136 */ "No such host or network path",
|
2004-08-20 02:26:58 +08:00
|
|
|
/* ECASECLASH 137 */ "Filename exists with different case",
|
|
|
|
/* EILSEQ 138 */ "Invalid or incomplete multibyte or wide character",
|
2008-09-20 07:29:24 +08:00
|
|
|
/* EOVERFLOW 139 */ "Value too large for defined data type",
|
|
|
|
/* ECANCELED 140 */ "Operation canceled",
|
|
|
|
/* ENOTRECOVERABLE 141 */ "State not recoverable",
|
2009-03-15 21:46:56 +08:00
|
|
|
/* EOWNERDEAD 142 */ "Previous owner died",
|
|
|
|
/* ESTRPIPE 143 */ "Streams pipe error"
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
2003-05-11 08:10:11 +08:00
|
|
|
int NO_COPY_INIT _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
|
2001-10-14 01:23:35 +08:00
|
|
|
};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2003-05-11 08:10:11 +08:00
|
|
|
geterrno_from_win_error (DWORD code, int deferrno)
|
|
|
|
{
|
|
|
|
for (int i = 0; errmap[i].w != 0; ++i)
|
|
|
|
if (code == errmap[i].w)
|
|
|
|
{
|
|
|
|
syscall_printf ("windows error %u == errno %d", code, errmap[i].e);
|
|
|
|
return errmap[i].e;
|
|
|
|
}
|
|
|
|
|
|
|
|
syscall_printf ("unknown windows error %u, setting errno to %d", code,
|
|
|
|
deferrno);
|
|
|
|
return deferrno; /* FIXME: what's so special about EACCESS? */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* seterrno_from_win_error: Given a Windows error code, set errno
|
|
|
|
as appropriate. */
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg3
|
2003-05-11 08:10:11 +08:00
|
|
|
seterrno_from_win_error (const char *file, int line, DWORD code)
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%s:%d windows error %u", file, line, code);
|
2017-07-19 16:28:39 +08:00
|
|
|
errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES);
|
2010-04-16 23:42:29 +08:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2011-04-28 20:13:41 +08:00
|
|
|
geterrno_from_nt_status (NTSTATUS status, int deferrno)
|
|
|
|
{
|
|
|
|
return geterrno_from_win_error (RtlNtStatusToDosError (status));
|
|
|
|
}
|
|
|
|
|
2010-04-16 23:42:29 +08:00
|
|
|
/* seterrno_from_nt_status: Given a NT status code, set errno
|
|
|
|
as appropriate. */
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg3
|
2010-04-16 23:42:29 +08:00
|
|
|
seterrno_from_nt_status (const char *file, int line, NTSTATUS status)
|
|
|
|
{
|
|
|
|
DWORD code = RtlNtStatusToDosError (status);
|
|
|
|
SetLastError (code);
|
2013-04-23 17:44:36 +08:00
|
|
|
syscall_printf ("%s:%d status %y -> windows error %u",
|
2010-04-16 23:42:29 +08:00
|
|
|
file, line, status, code);
|
2017-07-19 16:28:39 +08:00
|
|
|
errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES);
|
2003-05-11 08:10:11 +08:00
|
|
|
}
|
|
|
|
|
2005-08-29 01:30:34 +08:00
|
|
|
static char *
|
|
|
|
strerror_worker (int errnum)
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
if (errnum >= 0 && errnum < _sys_nerr)
|
|
|
|
res = (char *) _sys_errlist [errnum];
|
|
|
|
else
|
|
|
|
res = NULL;
|
|
|
|
return res;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-26 02:47:32 +08:00
|
|
|
/* Newlib requires this override for perror and friends to avoid
|
|
|
|
clobbering strerror() buffer, without having to differentiate
|
|
|
|
between strerror_r signatures. This function is intentionally not
|
|
|
|
exported, so that only newlib can use it. */
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" char *
|
2011-05-26 02:47:32 +08:00
|
|
|
_strerror_r (struct _reent *, int errnum, int internal, int *errptr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-08-29 01:30:34 +08:00
|
|
|
char *errstr = strerror_worker (errnum);
|
|
|
|
if (!errstr)
|
2011-02-11 01:36:51 +08:00
|
|
|
{
|
2011-05-26 02:47:32 +08:00
|
|
|
errstr = internal ? _my_tls.locals.strerror_r_buf
|
2011-06-06 13:02:13 +08:00
|
|
|
: _my_tls.locals.strerror_buf;
|
2011-05-26 02:47:32 +08:00
|
|
|
__small_sprintf (errstr, "Unknown error %d", errnum);
|
|
|
|
if (errptr)
|
2011-06-06 13:02:13 +08:00
|
|
|
*errptr = EINVAL;
|
2011-02-11 01:36:51 +08:00
|
|
|
}
|
2005-08-29 01:30:34 +08:00
|
|
|
return errstr;
|
|
|
|
}
|
|
|
|
|
2011-05-26 02:47:32 +08:00
|
|
|
/* strerror: convert from errno values to error strings. Newlib's
|
|
|
|
strerror_r returns "" for unknown values, so we override it to
|
|
|
|
provide a nicer thread-safe result string and set errno. */
|
|
|
|
extern "C" char *
|
|
|
|
strerror (int errnum)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
char *result = _strerror_r (NULL, errnum, 0, &error);
|
|
|
|
if (error)
|
|
|
|
set_errno (error);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:49:24 +08:00
|
|
|
extern "C" char *
|
|
|
|
strerror_l (int errnum, locale_t locale)
|
|
|
|
{
|
|
|
|
/* We don't provide localized system error messages (yet?). */
|
|
|
|
return strerror (errnum);
|
|
|
|
}
|
|
|
|
|
2011-02-11 01:36:51 +08:00
|
|
|
/* Newlib's <string.h> provides declarations for two strerror_r
|
|
|
|
variants, according to preprocessor feature macros. However, it
|
|
|
|
returns "" instead of "Unknown error ...", so we override both
|
|
|
|
versions. */
|
|
|
|
extern "C" char *
|
2005-08-29 01:30:34 +08:00
|
|
|
strerror_r (int errnum, char *buf, size_t n)
|
|
|
|
{
|
2011-05-26 02:47:32 +08:00
|
|
|
int error = 0;
|
|
|
|
char *errstr = _strerror_r (NULL, errnum, 1, &error);
|
|
|
|
if (error)
|
|
|
|
set_errno (error);
|
|
|
|
if (strlen (errstr) >= n)
|
|
|
|
return errstr;
|
|
|
|
return strcpy (buf, errstr);
|
2011-02-11 01:36:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int
|
|
|
|
__xpg_strerror_r (int errnum, char *buf, size_t n)
|
|
|
|
{
|
|
|
|
if (!n)
|
2005-08-29 01:30:34 +08:00
|
|
|
return ERANGE;
|
2011-02-11 01:36:51 +08:00
|
|
|
int result = 0;
|
|
|
|
char *error = strerror_worker (errnum);
|
2011-05-24 04:43:06 +08:00
|
|
|
char tmp[sizeof "Unknown error -2147483648"];
|
2011-03-03 17:50:13 +08:00
|
|
|
if (!error)
|
2011-02-11 01:36:51 +08:00
|
|
|
{
|
2011-05-24 04:43:06 +08:00
|
|
|
__small_sprintf (error = tmp, "Unknown error %d", errnum);
|
2011-02-11 01:36:51 +08:00
|
|
|
result = EINVAL;
|
|
|
|
}
|
|
|
|
if (strlen (error) >= n)
|
|
|
|
{
|
|
|
|
memcpy (buf, error, n - 1);
|
|
|
|
buf[n - 1] = '\0';
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
strcpy (buf, error);
|
|
|
|
return result;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2011-05-18 09:25:41 +08:00
|
|
|
|
|
|
|
unsigned int error_message_count = 0;
|
|
|
|
int error_one_per_line = 0;
|
|
|
|
void (*error_print_progname) (void) = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_verror (int status, int errnum, const char *filename, unsigned int lineno, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
error_message_count++;
|
|
|
|
|
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
if (error_print_progname)
|
|
|
|
(*error_print_progname) ();
|
|
|
|
else
|
|
|
|
fprintf (stderr, "%s:%s", program_invocation_name, filename ? "" : " ");
|
|
|
|
|
|
|
|
if (filename)
|
|
|
|
fprintf (stderr, "%s:%d: ", filename, lineno);
|
|
|
|
|
|
|
|
vfprintf (stderr, fmt, ap);
|
|
|
|
|
|
|
|
if (errnum != 0)
|
|
|
|
fprintf (stderr, ": %s", strerror (errnum));
|
|
|
|
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
error (int status, int errnum, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
_verror (status, errnum, NULL, 0, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
error_at_line (int status, int errnum, const char *filename, unsigned int lineno, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (error_one_per_line != 0)
|
|
|
|
{
|
|
|
|
static const char *last_filename;
|
|
|
|
static unsigned int last_lineno;
|
|
|
|
|
|
|
|
/* strcmp(3) will SEGV if filename or last_filename are NULL */
|
|
|
|
if (lineno == last_lineno
|
2011-06-06 13:02:13 +08:00
|
|
|
&& ((!filename && !last_filename)
|
|
|
|
|| (filename && last_filename && strcmp (filename, last_filename) == 0)))
|
|
|
|
return;
|
2011-05-18 09:25:41 +08:00
|
|
|
|
|
|
|
last_filename = filename;
|
|
|
|
last_lineno = lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start (ap, fmt);
|
|
|
|
_verror (status, errnum, filename, lineno, fmt, ap);
|
|
|
|
va_end (ap);
|
|
|
|
}
|