newlib/winsup/cygwin/errno.cc

510 lines
16 KiB
C++
Raw Normal View History

2000-02-17 20:38:33 +01: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. */
#define _sys_nerr FOO_sys_nerr
#define sys_nerr FOOsys_nerr
#define _sys_errlist FOO_sys_errlist
#define strerror_r FOO_strerror_r
#define __INSIDE_CYGWIN__
#include <errno.h>
#include <error.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "winsup.h"
* exceptions.cc (set_signal_mask): Redefine to not pass by address. Report calculated mask in debugging output. * sigproc.h (set_signal_mask): Reflect above change in declaration. * path.cc (mount_item::build_win32): Take path apart before feeding it to fnmunge. Throughout, change use of _reent_winsup()-> to _my_tls.locals. instead. Throughout, remove obsolete MT_SAFE/_CYG_THREAD_FAILSAFE considerations. Througout, add cygtls.h include. * Makefile.in (DLL_OFILES): Add cygtls.o. Add some more objects to the -fomit-frame-pointer list. * acconfig.h: Remove obsolete settings. * config.h.in: Ditto. * bsdlib.cc: Add cygtls.h include. * configure.in: Remove --enable-extra-threadsafe-checking. * configure: Regenerate. * cygtls.h (_local_storage): New struct renamed from _winsup_t (sic). (_threadinfo:local_clib): Add new field. (_threadinfo::locals): Ditto. (_threadinfo::init_thread): Accept second _reent * argument. (_threadinfo::call): Define as regparm. (CYGTLS_PADSIZE): Remove unnecessary slop. (_getreent): Define as a macro. * thread.h: Remove _CYG_THREAD_FAILSAFE and MT_SAFE stuff. (_winsup_t): Move to cygtls.h. (ResourceLocks::ResourceLocks): Eliminate empty constructor. (MTinterface::reents): Eliminate. (MTinterface::thread_self_key): Eliminate. (MTinterface::MTinterface): Eliminate. * dcrt0.cc: Include stdio.h for _impure_ptr initialization. (do_global_ctors): Remove run_ctors_p (sic) considerations. Don't call atexit here. (__main): Initialize destructors for user here. (dll_crt0_1): Accept a dummy argument. Don't call init_thread here. Don't set _impure_ptr here. Call do_global_ctors after more things have been initialized. (_dll_crt0): Define zeros buffer as max of needed size of CYGTLS_PADSIZE so that it can be used for two purposes while minimizing stack usage. Initialize _impure_ptr specifically, for speed. Call dll_crt0_1 with buffer argument. (cygwin_dll_init): Call dll_crt0_1 with dummy argument. * dtable.cc (dtable::find_unused_handle): Remove call to AssertResourceOwner. * exceptions.cc: Move _threadinfo stuff to new file. * cygtls.cc: New file. * gentls_offsets: Accommodate increasing complexity of cygtls.h. * hires.h (hires_base::~hires_base): Remove. * init.cc (dll_entry): Remove setting of reents. * thread.cc: Remove syslog.h include. (__getreent): Simplify to use _my_tls. (_reent_winsup): Delete. (AssertResourceOwner): Delete. (MTinterface::Init): Remove setting of _clib and _winsup, with all that entails. (MTinterface::fixup_after_fork): Ditto. (pthread::thread_init_wrapper): Ditto. Also remove call to set_tls_self_pointer. (pthread::set_tls_self_pointer): Eliminate. (pthread::get_tls_self_pointer): Just return _my_tls.tid; (__reent_t::init_clib): Eliminate. * tlsoffsets.h: Regenerate.
2003-12-23 17:26:31 +01:00
#include "cygtls.h"
#include "ntdll.h"
#undef _sys_nerr
#undef sys_nerr
#undef _sys_errlist
#undef strerror_r
2000-02-17 20:38:33 +01: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}
static const errmap_t errmap[] =
2003-05-09 19:58:20 +02:00
{
/* FIXME: Some of these choices are arbitrary! */
X (ACCESS_DENIED, EACCES),
2005-04-30 06:10:39 +02:00
X (ACTIVE_CONNECTIONS, EAGAIN),
X (ALREADY_EXISTS, EEXIST),
X (BAD_DEVICE, ENODEV),
X (BAD_EXE_FORMAT, ENOEXEC),
X (BAD_NETPATH, ENOENT),
X (BAD_NET_NAME, ENOENT),
X (BAD_NET_RESP, ENOSYS),
2005-04-30 06:10:39 +02:00
X (BAD_PATHNAME, ENOENT),
X (BAD_PIPE, EINVAL),
X (BAD_UNIT, ENODEV),
X (BAD_USERNAME, EINVAL),
X (BEGINNING_OF_MEDIA, EIO),
2003-05-09 19:58:20 +02:00
X (BROKEN_PIPE, EPIPE),
2005-04-30 06:10:39 +02:00
X (BUSY, EBUSY),
X (BUS_RESET, EIO),
2003-05-09 19:58:20 +02:00
X (CALL_NOT_IMPLEMENTED, ENOSYS),
X (CANCELLED, EINTR),
2005-04-30 06:10:39 +02:00
X (CANNOT_MAKE, EPERM),
2003-05-09 19:58:20 +02:00
X (CHILD_NOT_COMPLETE, EBUSY),
2005-04-30 06:10:39 +02:00
X (COMMITMENT_LIMIT, EAGAIN),
X (CONNECTION_REFUSED, ECONNREFUSED),
2005-04-30 06:10:39 +02:00
X (CRC, EIO),
X (DEVICE_DOOR_OPEN, EIO),
X (DEVICE_IN_USE, EAGAIN),
X (DEVICE_REQUIRES_CLEANING, EIO),
X (DEV_NOT_EXIST, ENOENT),
2005-04-30 06:10:39 +02:00
X (DIRECTORY, ENOTDIR),
2003-05-09 19:58:20 +02:00
X (DIR_NOT_EMPTY, ENOTEMPTY),
2005-04-30 06:10:39 +02:00
X (DISK_CORRUPT, EIO),
X (DISK_FULL, ENOSPC),
X (DS_GENERIC_ERROR, EIO),
2005-04-30 06:10:39 +02: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 16:43:04 +01:00
X (EAS_DIDNT_FIT, ENOSPC),
X (EAS_NOT_SUPPORTED, ENOTSUP),
X (EA_LIST_INCONSISTENT, EINVAL),
X (EA_TABLE_FULL, ENOSPC),
2005-04-30 06:10:39 +02:00
X (END_OF_MEDIA, ENOSPC),
X (EOM_OVERFLOW, EIO),
X (EXE_MACHINE_TYPE_MISMATCH, ENOEXEC),
X (EXE_MARKED_INVALID, ENOEXEC),
2005-04-30 06:10:39 +02:00
X (FILEMARK_DETECTED, EIO),
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 16:43:04 +01:00
X (FILE_CORRUPT, EEXIST),
2005-04-30 06:10:39 +02: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 16:43:04 +01:00
X (INVALID_EA_NAME, EINVAL),
X (INVALID_EXE_SIGNATURE, ENOEXEC),
2005-04-30 06:10:39 +02:00
X (INVALID_FUNCTION, EBADRQC),
X (INVALID_HANDLE, EBADF),
X (INVALID_NAME, ENOENT),
X (INVALID_PARAMETER, EINVAL),
2003-05-09 19:58:20 +02:00
X (INVALID_SIGNAL_NUMBER, EINVAL),
X (IOPL_NOT_ENABLED, ENOEXEC),
2005-04-30 06:10:39 +02:00
X (IO_DEVICE, EIO),
X (IO_INCOMPLETE, EAGAIN),
2005-04-30 06:10:39 +02:00
X (IO_PENDING, EAGAIN),
X (LOCK_VIOLATION, EBUSY),
2005-04-30 06:10:39 +02:00
X (MAX_THRDS_REACHED, EAGAIN),
X (META_EXPANSION_TOO_LONG, EINVAL),
X (MOD_NOT_FOUND, ENOENT),
X (MORE_DATA, EMSGSIZE),
2005-04-30 06:10:39 +02:00
X (NEGATIVE_SEEK, EINVAL),
X (NETNAME_DELETED, ENOENT),
2005-04-30 06:10:39 +02:00
X (NOACCESS, EFAULT),
X (NONE_MAPPED, EINVAL),
X (NONPAGED_SYSTEM_RESOURCES, EAGAIN),
2003-05-09 19:58:20 +02:00
X (NOT_CONNECTED, ENOLINK),
2005-04-30 06:10:39 +02:00
X (NOT_ENOUGH_MEMORY, ENOMEM),
X (NOT_ENOUGH_QUOTA, EIO),
2003-05-09 19:58:20 +02:00
X (NOT_OWNER, EPERM),
X (NOT_READY, ENOMEDIUM),
2005-04-30 06:10:39 +02:00
X (NOT_SAME_DEVICE, EXDEV),
X (NOT_SUPPORTED, ENOSYS),
X (NO_DATA, EPIPE),
X (NO_DATA_DETECTED, EIO),
* errno.cc (errmap): Map ERROR_SHARING_VIOLATION to EBUSY, ERROR_EOM_OVERFLOW and ERROR_NO_DATA_DETECTED to EIO. Add mappings for ERROR_NO_MEDIA_IN_DRIVE, ERROR_DEVICE_REQUIRES_CLEANING and ERROR_DEVICE_DOOR_OPEN. * fhandler.h (class fhandler_dev_raw): Drop varblkop member. (fhandler_dev_raw::is_eom): De-virtualize. (fhandler_dev_raw::is_eof): Ditto. (class fhandler_dev_tape): Drop lasterr and dp member. Add mt_mtx member. Drop all private methods formerly used by ioctl. (fhandler_dev_tape::is_rewind_device): Use get_minor for clarity. (fhandler_dev_tape::driveno): New method. (fhandler_dev_tape::drive_init): New method. (fhandler_dev_tape::clear): Remove method. (fhandler_dev_tape::is_eom): Ditto. (fhandler_dev_tape::is_eof): Ditto. (fhandler_dev_tape::write_file): Ditto. (fhandler_dev_tape::read_file): Ditto. (fhandler_dev_tape::_lock): New method. (fhandler_dev_tape::unlock): New method. (fhandler_dev_tape::raw_read): New method. (fhandler_dev_tape::raw_write): New method. * fhandler_raw.cc (fhandler_dev_raw::is_eom): New method. (fhandler_dev_raw::is_eof): New method. (fhandler_dev_raw::open): Allow setting write through option by using the O_TEXT flag as ... flag. (fhandler_dev_raw::writebuf): Remove usage of varblkop and other tape specific code. (fhandler_dev_raw::raw_read): Ditto. (fhandler_dev_raw::dup): Ditto. * fhandler_tape.cc: Rewrite tape operations entirely. Implement new tape driver classes mtinfo, mtinfo_drive and mtinfo_part. Reduce fhandler_dev_tape methods to mostly just calling appropriate mtinfo_drive methods. (mtinfo_init): New function adding the mtinfo shared memory area. * mtinfo.h: New file, containing the definition of the new tape driver classes. * shared.cc: Include mtinfo.h. (offsets): Add entry for mtinfo shared memory area. (memory_init): Call mtinfo_init. * shared_info.h (shared_locations): Add SH_MTINFO shared location. * include/cygwin/mtio.h: Change and add various comments. Add GMT_xxx macros for new generic flags. Add MT_ST_xxx bitfield definitions for MTSETDRVBUFFER ioctl. * include/cygwin/version.h: Bump API minor version number.
2004-03-26 22:43:49 +01:00
X (NO_MEDIA_IN_DRIVE, ENOMEDIUM),
2005-04-30 06:10:39 +02:00
X (NO_MORE_FILES, ENMFILE),
X (NO_MORE_ITEMS, ENMFILE),
2005-04-30 06:10:39 +02:00
X (NO_MORE_SEARCH_HANDLES, ENFILE),
X (NO_PROC_SLOTS, EAGAIN),
X (NO_SIGNAL_SENT, EIO),
* errno.cc (errmap): Change mapping of NO_SYSTEM_RESOURCES to EFBIG. * fhandler.cc (MAX_OVERLAPPED_WRITE_LEN): New constant. (MIN_OVERLAPPED_WRITE_LEN): Ditto. (fhandler_base_overlapped::close): Accommodate change in arguments to wait_overlapped. (fhandler_base_overlapped::setup_overlapped): Add __stdcall and regparm modifiers. (fhandler_base_overlapped::destroy_overlapped): Ditto. (fhandler_base_overlapped::has_ongoing_io): Ditto. (fhandler_base_overlapped::wait_overlapped): Modify to return an enum returning various states. Accept nonblocking parameter. (fhandler_base_overlapped::read_overlapped): Add __stdcall and regparm modifiers. Rework to attempt to be smarter about reacting to states returned by wait_overlapped. (fhandler_base_overlapped::write_overlapped): Ditto. Add fallback option for when wait_overlapped detects that smaller chunks must be written. (fhandler_base_overlapped::write_overlapped_fallback): Ditto. * fhandler.h (DEFAULT_PIPEBUFSIZE): Move definition here from pipe.cc. (fhandler_base::has_ongoing_io): Define with __stdcall and regparm modifiers. (fhandler_base_overlapped::wait_return): New enum. (fhandler_base_overlapped::max_atomic_write): New variable. (fhandler_base_overlapped:: wait_overlapped): Accommodate changes mentioned above to arguments and modifiers. (fhandler_base_overlapped::setup_overlapped): Ditto for modifiers. (fhandler_base_overlapped::read_overlapped): Ditto. (fhandler_base_overlapped::write_overlapped): Ditto. (fhandler_base_overlapped::destroy_overlapped): Ditto. (fhandler_base_overlapped::has_ongoing_io): Ditto. (fhandler_base_overlapped::fhandler_base_overlapped): Zero max_atomic_write. * fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Set max_atomic_write to the size of the DEFAULT_PIPEBUFSIZE. (fhandler_fifo::wait): Accommodate change in arguments to wait_overlapped. * pipe.cc (fhandler_pipe::fhandler_pipe): Set max_atomic_write to the size of the DEFAULT_PIPEBUFSIZE. (fhandler_pipe::create_selectable): Allow minimum size of DEFAULT_PIPEBUFSIZE. (DEFAULT_PIPEBUFSIZE): Delete here, move to fhandler.h.
2011-03-09 17:47:44 +01:00
X (NO_SYSTEM_RESOURCES, EFBIG),
2005-04-30 06:10:39 +02:00
X (NO_TOKEN, EINVAL),
X (OPEN_FAILED, EIO),
X (OPEN_FILES, EAGAIN),
X (OUTOFMEMORY, ENOMEM),
X (PAGED_SYSTEM_RESOURCES, EAGAIN),
X (PAGEFILE_QUOTA, EAGAIN),
2005-04-30 06:10:39 +02: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-14 20:38:22 +02:00
X (PRIVILEGE_NOT_HELD, EPERM),
2005-04-30 06:10:39 +02:00
X (PROCESS_ABORTED, EFAULT),
X (PROC_NOT_FOUND, ESRCH),
X (REM_NOT_LIST, ENONET),
X (SECTOR_NOT_FOUND, EINVAL),
X (SEEK, EINVAL),
X (SERVICE_REQUEST_TIMEOUT, EBUSY),
2005-04-30 06:10:39 +02: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 16:56:19 +02:00
X (SXS_CANT_GEN_ACTCTX, ELIBBAD),
2005-04-30 06:10:39 +02:00
X (THREAD_1_INACTIVE, EINVAL),
X (TIMEOUT, EBUSY),
2005-04-30 06:10:39 +02:00
X (TOO_MANY_LINKS, EMLINK),
X (TOO_MANY_OPEN_FILES, EMFILE),
X (UNEXP_NET_ERR, EIO),
2005-04-30 06:10:39 +02:00
X (WAIT_NO_CHILDREN, ECHILD),
X (WORKING_SET_QUOTA, EAGAIN),
X (WRITE_PROTECT, EROFS),
2003-05-09 19:58:20 +02:00
{ 0, NULL, 0}
};
extern "C" {
2013-04-23 11:44:36 +02:00
const char *_sys_errlist[] =
2000-02-17 20:38:33 +01: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",
/* EIO 5 */ "Input/output error",
/* 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",
NULL,
NULL,
NULL,
/* 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",
NULL,
NULL,
/* 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",
NULL,
NULL,
/* EMULTIHOP 74 */ "Multihop attempted",
/* ELBIN 75 */ "Inode is remote (not really error)",
/* EDOTDOT 76 */ "RFS specific error",
/* EBADMSG 77 */ "Bad message",
NULL,
/* 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",
NULL,
NULL,
/* EOPNOTSUPP 95 */ "Operation not supported",
/* EPFNOSUPPORT 96 */ "Protocol family not supported",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
/* 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",
/* ENOTSOCK 108 */ "Socket operation on non-socket",
/* 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-17 20:38:33 +01:00
/* EPROTONOSUPPORT 123 */ "Protocol not supported",
/* ESOCKTNOSUPPORT 124 */ "Socket type not supported",
/* 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",
/* ENOTSUP 134 */ "Not supported",
/* ENOMEDIUM 135 */ "No medium found",
/* ENOSHARE 136 */ "No such host or network path",
/* ECASECLASH 137 */ "Filename exists with different case",
/* EILSEQ 138 */ "Invalid or incomplete multibyte or wide character",
/* EOVERFLOW 139 */ "Value too large for defined data type",
/* ECANCELED 140 */ "Operation canceled",
/* ENOTRECOVERABLE 141 */ "State not recoverable",
/* EOWNERDEAD 142 */ "Previous owner died",
/* ESTRPIPE 143 */ "Streams pipe error"
2000-02-17 20:38:33 +01:00
};
int NO_COPY_INIT _sys_nerr = sizeof (_sys_errlist) / sizeof (_sys_errlist[0]);
};
2000-02-17 20:38:33 +01:00
int __reg2
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. */
void __reg3
seterrno_from_win_error (const char *file, int line, DWORD code)
{
2013-04-23 11:44:36 +02:00
syscall_printf ("%s:%d windows error %u", file, line, code);
errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES);
}
int __reg2
geterrno_from_nt_status (NTSTATUS status, int deferrno)
{
return geterrno_from_win_error (RtlNtStatusToDosError (status));
}
/* seterrno_from_nt_status: Given a NT status code, set errno
as appropriate. */
void __reg3
seterrno_from_nt_status (const char *file, int line, NTSTATUS status)
{
DWORD code = RtlNtStatusToDosError (status);
SetLastError (code);
2013-04-23 11:44:36 +02:00
syscall_printf ("%s:%d status %y -> windows error %u",
file, line, status, code);
errno = _impure_ptr->_errno = geterrno_from_win_error (code, EACCES);
}
2005-08-28 19:30:34 +02: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-17 20:38:33 +01: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-17 20:38:33 +01:00
extern "C" char *
_strerror_r (struct _reent *, int errnum, int internal, int *errptr)
2000-02-17 20:38:33 +01:00
{
2005-08-28 19:30:34 +02:00
char *errstr = strerror_worker (errnum);
if (!errstr)
{
errstr = internal ? _my_tls.locals.strerror_r_buf
2011-06-06 07:02:13 +02:00
: _my_tls.locals.strerror_buf;
__small_sprintf (errstr, "Unknown error %d", errnum);
if (errptr)
2011-06-06 07:02:13 +02:00
*errptr = EINVAL;
}
2005-08-28 19:30:34 +02:00
return errstr;
}
/* 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;
}
extern "C" char *
strerror_l (int errnum, locale_t locale)
{
/* We don't provide localized system error messages (yet?). */
return strerror (errnum);
}
/* 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-28 19:30:34 +02:00
strerror_r (int errnum, char *buf, size_t n)
{
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);
}
extern "C" int
__xpg_strerror_r (int errnum, char *buf, size_t n)
{
if (!n)
2005-08-28 19:30:34 +02:00
return ERANGE;
int result = 0;
char *error = strerror_worker (errnum);
char tmp[sizeof "Unknown error -2147483648"];
if (!error)
{
__small_sprintf (error = tmp, "Unknown error %d", errnum);
result = EINVAL;
}
if (strlen (error) >= n)
{
memcpy (buf, error, n - 1);
buf[n - 1] = '\0';
return ERANGE;
}
strcpy (buf, error);
return result;
2000-02-17 20:38:33 +01: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 07:02:13 +02:00
&& ((!filename && !last_filename)
|| (filename && last_filename && strcmp (filename, last_filename) == 0)))
return;
last_filename = filename;
last_lineno = lineno;
}
va_start (ap, fmt);
_verror (status, errnum, filename, lineno, fmt, ap);
va_end (ap);
}