Author: mturk Date: Fri Aug 28 15:45:31 2009 New Revision: 808924 URL: http://svn.apache.org/viewvc?rev=808924&view=rev Log: Fill in missing error values
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=808924&r1=808923&r2=808924&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Aug 28 15:45:31 2009 @@ -282,108 +282,108 @@ static const char *acr_error_string(int statcode) { switch (statcode) { - case ACR_ENOPOOL: - return "A new pool could not be created."; - case ACR_EBADDATE: - return "An invalid date has been provided"; - case ACR_EINVALSOCK: - return "An invalid socket was returned"; - case ACR_ENOPROC: - return "No process was provided and one was required."; - case ACR_ENOTIME: - return "No time was provided and one was required."; - case ACR_ENODIR: - return "No directory was provided and one was required."; - case ACR_ENOLOCK: - return "No lock was provided and one was required."; - case ACR_ENOPOLL: - return "No poll structure was provided and one was required."; - case ACR_ENOSOCKET: - return "No socket was provided and one was required."; - case ACR_ENOTHREAD: - return "No thread was provided and one was required."; - case ACR_ENOTHDKEY: - return "No thread key structure was provided and one was required."; - case ACR_ENOSHMAVAIL: - return "No shared memory is currently available"; - case ACR_EDSOOPEN: + case ACR_ENOPOOL: + return "A new pool could not be created."; + case ACR_EBADDATE: + return "An invalid date has been provided"; + case ACR_EINVALSOCK: + return "An invalid socket was returned"; + case ACR_ENOPROC: + return "No process was provided and one was required."; + case ACR_ENOTIME: + return "No time was provided and one was required."; + case ACR_ENODIR: + return "No directory was provided and one was required."; + case ACR_ENOLOCK: + return "No lock was provided and one was required."; + case ACR_ENOPOLL: + return "No poll structure was provided and one was required."; + case ACR_ENOSOCKET: + return "No socket was provided and one was required."; + case ACR_ENOTHREAD: + return "No thread was provided and one was required."; + case ACR_ENOTHDKEY: + return "No thread key structure was provided and one was required."; + case ACR_ENOSHMAVAIL: + return "No shared memory is currently available"; + case ACR_EDSOOPEN: #if HAVE_DLFCN_H - return dlerror(); + return dlerror(); #else - return "DSO load failed"; + return "DSO load failed"; #endif /* HAVE_DLFCN_H */ - case ACR_EBADIP: - return "The specified IP address is invalid."; - case ACR_EBADMASK: - return "The specified network mask is invalid."; - - case ACR_INCHILD: - return - "Your code just forked, and you are currently executing in the " - "child process"; - case ACR_INPARENT: - return - "Your code just forked, and you are currently executing in the " - "parent process"; - case ACR_DETACH: - return "The specified thread is detached"; - case ACR_NOTDETACH: - return "The specified thread is not detached"; - case ACR_CHILD_DONE: - return "The specified child process is done executing"; - case ACR_CHILD_NOTDONE: - return "The specified child process is not done executing"; - case ACR_TIMEUP: - return "The timeout specified has expired"; - case ACR_INCOMPLETE: - return "Partial results are valid but processing is incomplete"; - case ACR_BADCH: - return "Bad character specified on command line"; - case ACR_BADARG: - return "Missing parameter for the specified command line option"; - case ACR_EOF: - return "End of file found"; - case ACR_NOTFOUND: - return "Could not find specified socket in poll list."; - case ACR_ANONYMOUS: - return "Shared memory is implemented anonymously"; - case ACR_FILEBASED: - return "Shared memory is implemented using files"; - case ACR_KEYBASED: - return "Shared memory is implemented using a key system"; - case ACR_EINIT: - return - "There is no error, this value signifies an initialized " - "error code"; - case ACR_ENOTIMPL: - return "This function has not been implemented on this platform"; - case ACR_EMISMATCH: - return "passwords do not match"; - case ACR_EABSOLUTE: - return "The given path is absolute"; - case ACR_ERELATIVE: - return "The given path is relative"; - case ACR_EINCOMPLETE: - return "The given path is incomplete"; - case ACR_EABOVEROOT: - return "The given path was above the root path"; - case ACR_EBADPATH: - return "The given path is misformatted or contained invalid characters"; - case ACR_EPATHWILD: - return "The given path contained wildcard characters"; - case ACR_EPROC_UNKNOWN: - return "The process is not recognized."; - case ACR_EGENERAL: - return "Internal error"; - /* ACR specific error codes */ - case ACR_EISNULL: - return "The given argument is null"; - case ACR_EINVALSIZ: - return "The given argument size is invalid"; - case ACR_ECLASSNOTFOUND: - return "The specified Java Class was not found"; - default: - return "Error string not specified yet"; + case ACR_EBADIP: + return "The specified IP address is invalid."; + case ACR_EBADMASK: + return "The specified network mask is invalid."; + + case ACR_INCHILD: + return + "Your code just forked, and you are currently executing in the " + "child process"; + case ACR_INPARENT: + return + "Your code just forked, and you are currently executing in the " + "parent process"; + case ACR_DETACH: + return "The specified thread is detached"; + case ACR_NOTDETACH: + return "The specified thread is not detached"; + case ACR_CHILD_DONE: + return "The specified child process is done executing"; + case ACR_CHILD_NOTDONE: + return "The specified child process is not done executing"; + case ACR_TIMEUP: + return "The timeout specified has expired"; + case ACR_INCOMPLETE: + return "Partial results are valid but processing is incomplete"; + case ACR_BADCH: + return "Bad character specified on command line"; + case ACR_BADARG: + return "Missing parameter for the specified command line option"; + case ACR_EOF: + return "End of file found"; + case ACR_NOTFOUND: + return "Could not find specified socket in poll list."; + case ACR_ANONYMOUS: + return "Shared memory is implemented anonymously"; + case ACR_FILEBASED: + return "Shared memory is implemented using files"; + case ACR_KEYBASED: + return "Shared memory is implemented using a key system"; + case ACR_EINIT: + return + "There is no error, this value signifies an initialized " + "error code"; + case ACR_ENOTIMPL: + return "This function has not been implemented on this platform"; + case ACR_EMISMATCH: + return "Passwords do not match"; + case ACR_EABSOLUTE: + return "The given path is absolute"; + case ACR_ERELATIVE: + return "The given path is relative"; + case ACR_EINCOMPLETE: + return "The given path is incomplete"; + case ACR_EABOVEROOT: + return "The given path was above the root path"; + case ACR_EBADPATH: + return "The given path is misformatted or contained invalid characters"; + case ACR_EPATHWILD: + return "The given path contained wildcard characters"; + case ACR_EPROC_UNKNOWN: + return "The process is not recognized."; + case ACR_EGENERAL: + return "Internal error"; + /* ACR specific error codes */ + case ACR_EISNULL: + return "The given argument is null"; + case ACR_EINVALSIZ: + return "The given argument size is invalid"; + case ACR_ECLASSNOTFOUND: + return "The specified Java Class was not found"; + default: + return "Error string not specified yet"; } } @@ -394,83 +394,157 @@ static const struct { int code; const char *msg; -} gaErrorList[] = { - WSAEINTR, "Interrupted system call", - WSAEBADF, "Bad file number", - WSAEACCES, "Permission denied", - WSAEFAULT, "Bad address", - WSAEINVAL, "Invalid argument", - WSAEMFILE, "Too many open sockets", - WSAEWOULDBLOCK, "Operation would block", - WSAEINPROGRESS, "Operation now in progress", - WSAEALREADY, "Operation already in progress", - WSAENOTSOCK, "Socket operation on non-socket", - WSAEDESTADDRREQ, "Destination address required", - WSAEMSGSIZE, "Message too long", - WSAEPROTOTYPE, "Protocol wrong type for socket", - WSAENOPROTOOPT, "Bad protocol option", - WSAEPROTONOSUPPORT, "Protocol not supported", - WSAESOCKTNOSUPPORT, "Socket type not supported", - WSAEOPNOTSUPP, "Operation not supported on socket", - WSAEPFNOSUPPORT, "Protocol family not supported", - WSAEAFNOSUPPORT, "Address family not supported", - WSAEADDRINUSE, "Address already in use", - WSAEADDRNOTAVAIL, "Can't assign requested address", - WSAENETDOWN, "Network is down", - WSAENETUNREACH, "Network is unreachable", - WSAENETRESET, "Net connection reset", - WSAECONNABORTED, "Software caused connection abort", - WSAECONNRESET, "Connection reset by peer", - WSAENOBUFS, "No buffer space available", - WSAEISCONN, "Socket is already connected", - WSAENOTCONN, "Socket is not connected", - WSAESHUTDOWN, "Can't send after socket shutdown", - WSAETOOMANYREFS, "Too many references, can't splice", - WSAETIMEDOUT, "Connection timed out", - WSAECONNREFUSED, "Connection refused", - WSAELOOP, "Too many levels of symbolic links", - WSAENAMETOOLONG, "File name too long", - WSAEHOSTDOWN, "Host is down", - WSAEHOSTUNREACH, "No route to host", - WSAENOTEMPTY, "Directory not empty", - WSAEPROCLIM, "Too many processes", - WSAEUSERS, "Too many users", - WSAEDQUOT, "Disc quota exceeded", - WSAESTALE, "Stale NFS file handle", - WSAEREMOTE, "Too many levels of remote in path", - WSASYSNOTREADY, "Network system is unavailable", - WSAVERNOTSUPPORTED, "Winsock version out of range", - WSANOTINITIALISED, "WSAStartup not yet called", - WSAEDISCON, "Graceful shutdown in progress", - WSAHOST_NOT_FOUND, "Host not found", - WSANO_DATA, "No host data of that type was found", +} _ws2_errlist[] = { + WSAEINTR, "Interrupted system call", + WSAEBADF, "Bad file number", + WSAEACCES, "Permission denied", + WSAEFAULT, "Bad address", + WSAEINVAL, "Invalid argument", + WSAEMFILE, "Too many open sockets", + WSAEWOULDBLOCK, "Operation would block", + WSAEINPROGRESS, "Operation now in progress", + WSAEALREADY, "Operation already in progress", + WSAENOTSOCK, "Socket operation on non-socket", + WSAEDESTADDRREQ, "Destination address required", + WSAEMSGSIZE, "Message too long", + WSAEPROTOTYPE, "Protocol wrong type for socket", + WSAENOPROTOOPT, "Bad protocol option", + WSAEPROTONOSUPPORT, "Protocol not supported", + WSAESOCKTNOSUPPORT, "Socket type not supported", + WSAEOPNOTSUPP, "Operation not supported on socket", + WSAEPFNOSUPPORT, "Protocol family not supported", + WSAEAFNOSUPPORT, "Address family not supported", + WSAEADDRINUSE, "Address already in use", + WSAEADDRNOTAVAIL, "Can't assign requested address", + WSAENETDOWN, "Network is down", + WSAENETUNREACH, "Network is unreachable", + WSAENETRESET, "Net connection reset", + WSAECONNABORTED, "Software caused connection abort", + WSAECONNRESET, "Connection reset by peer", + WSAENOBUFS, "No buffer space available", + WSAEISCONN, "Socket is already connected", + WSAENOTCONN, "Socket is not connected", + WSAESHUTDOWN, "Can't send after socket shutdown", + WSAETOOMANYREFS, "Too many references, can't splice", + WSAETIMEDOUT, "Connection timed out", + WSAECONNREFUSED, "Connection refused", + WSAELOOP, "Too many levels of symbolic links", + WSAENAMETOOLONG, "File name too long", + WSAEHOSTDOWN, "Host is down", + WSAEHOSTUNREACH, "No route to host", + WSAENOTEMPTY, "Directory not empty", + WSAEPROCLIM, "Too many processes", + WSAEUSERS, "Too many users", + WSAEDQUOT, "Disc quota exceeded", + WSAESTALE, "Stale NFS file handle", + WSAEREMOTE, "Too many levels of remote in path", + WSASYSNOTREADY, "Network system is unavailable", + WSAVERNOTSUPPORTED, "Winsock version out of range", + WSANOTINITIALISED, "WSAStartup not yet called", + WSAEDISCON, "Graceful shutdown in progress", + WSAHOST_NOT_FOUND, "Host not found", + WSANO_DATA, "No host data of that type was found", /* Extra errors */ - WSATRY_AGAIN, "Temporary failure in name resolution", - WSANO_RECOVERY, "Nonrecoverable failure in name resolution", + WSATRY_AGAIN, "Temporary failure in name resolution", + WSANO_RECOVERY, "Nonrecoverable failure in name resolution", WSA_NOT_ENOUGHT_MEMORY, "Memory allocation failed", WSASERVICE_NOT_FOUND, "Service not found.", - WSATYPE_NOT_FOUND, "Class type not found.", - WSASYSCALLFAILURE, "System call failure", - 0, NULL + WSATYPE_NOT_FOUND, "Class type not found.", + WSASYSCALLFAILURE, "System call failure", + 0, NULL }; static const struct { - DWORD get_last_error; /* Error returned from GetLastError() */ + DWORD win32_error; /* Error returned from GetLastError() */ int posix_error; /* POSIX error code */ -} pxErrorList[] = { - { ERROR_INVALID_FUNCTION, ACR_EINVAL }, - { ERROR_FILE_NOT_FOUND, ACR_ENOENT }, - { ERROR_PATH_NOT_FOUND, ACR_ENOENT }, - { ERROR_TOO_MANY_OPEN_FILES, ACR_EMFILE }, - { ERROR_ACCESS_DENIED, ACR_EACCES }, - { ERROR_INVALID_HANDLE, ACR_EBADF }, +} _psx_errlist[] = { + { ERROR_INVALID_FUNCTION, ACR_EINVAL }, + { ERROR_FILE_NOT_FOUND, ACR_ENOENT }, + { ERROR_PATH_NOT_FOUND, ACR_ENOENT }, + { ERROR_TOO_MANY_OPEN_FILES, ACR_EMFILE }, + { ERROR_ACCESS_DENIED, ACR_EACCES }, + { ERROR_INVALID_HANDLE, ACR_EBADF }, + { ERROR_ARENA_TRASHED, ACR_ENOMEM }, + { ERROR_NOT_ENOUGH_MEMORY, ACR_ENOMEM }, + { ERROR_INVALID_BLOCK, ACR_ENOMEM }, + { ERROR_BAD_ENVIRONMENT, ACR_E2BIG }, + { ERROR_BAD_FORMAT, ACR_ENOEXEC }, + { ERROR_INVALID_ACCESS, ACR_EINVAL }, + { ERROR_INVALID_DATA, ACR_EINVAL }, + { ERROR_INVALID_DRIVE, ACR_ENOENT }, + { ERROR_CURRENT_DIRECTORY, ACR_EACCES }, + { ERROR_NOT_SAME_DEVICE, ACR_EXDEV }, + { ERROR_NO_MORE_FILES, ACR_ENOENT }, + { ERROR_LOCK_VIOLATION, ACR_EACCES }, + { ERROR_BAD_NETPATH, ACR_ENOENT }, + { ERROR_NETWORK_ACCESS_DENIED, ACR_EACCES }, + { ERROR_BAD_NET_NAME, ACR_ENOENT }, + { ERROR_FILE_EXISTS, ACR_EEXIST }, + { ERROR_CANNOT_MAKE, ACR_EACCES }, + { ERROR_FAIL_I24, ACR_EACCES }, + { ERROR_INVALID_PARAMETER, ACR_EINVAL }, + { ERROR_NO_PROC_SLOTS, ACR_EAGAIN }, + { ERROR_DRIVE_LOCKED, ACR_EACCES }, + { ERROR_BROKEN_PIPE, ACR_EPIPE }, + { ERROR_DISK_FULL, ACR_ENOSPC }, + { ERROR_INVALID_TARGET_HANDLE, ACR_EBADF }, + { ERROR_INVALID_HANDLE, ACR_EINVAL }, + { ERROR_WAIT_NO_CHILDREN, ACR_ECHILD }, + { ERROR_CHILD_NOT_COMPLETE, ACR_ECHILD }, + { ERROR_DIRECT_ACCESS_HANDLE, ACR_EBADF }, + { ERROR_NEGATIVE_SEEK, ACR_EINVAL }, + { ERROR_SEEK_ON_DEVICE, ACR_EACCES }, + { ERROR_DIR_NOT_EMPTY, ACR_ENOTEMPTY }, + { ERROR_NOT_LOCKED, ACR_EACCES }, + { ERROR_BAD_PATHNAME, ACR_ENOENT }, + { ERROR_MAX_THRDS_REACHED, ACR_EAGAIN }, + { ERROR_LOCK_FAILED, ACR_EACCES }, + { ERROR_ALREADY_EXISTS, ACR_EEXIST }, + { ERROR_FILENAME_EXCED_RANGE, ACR_ENOENT }, + { ERROR_NESTING_NOT_ALLOWED, ACR_EAGAIN }, + { ERROR_NOT_ENOUGH_QUOTA, ACR_ENOMEM }, - { 0, -1 } + { 0, 0 } }; +void acr_set_os_error(int oserror) +{ + int i; + if (!oserror) { + SetLastError(0); + errno = 0; + return; + } + for (i = 0; i < (sizeof(_psx_errlist) / sizeof(_psx_errlist[0])); i++) { + if (oserror == (int)_psx_errlist[i].win32_error) { + errno = _psx_errlist[i].posix_error; + break; + } + } + + SetLastError(oserror - ACR_OS_START_SYSERR); +} + +int acr_get_os_error() +{ + int i, crt; + DWORD os; + if ((os = GetLastError())) + return os + ACR_OS_START_SYSERR; + crt = errno; + for (i = 0; crt, i < (sizeof(_psx_errlist) / sizeof(_psx_errlist[0])); i++) { + if (crt == _psx_errlist[i].posix_error) + return _psx_errlist[i].win32_error; + } + + return crt == 0 ? 0 : crt + ACR_OS_START_SYSERR; +} + + static char *acr_os_strerror(char *buf, acr_size_t bufsize, int errcode) { - acr_size_t len = 0, i; + DWORD len = 0; + int i; len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, @@ -481,11 +555,10 @@ (DWORD)bufsize, NULL); if (!len) { - for (i = 0; gaErrorList[i].msg; i++) { - if (gaErrorList[i].code == errcode) { - ACR_CopyStrn(buf, gaErrorList[i].msg, bufsize); - len = strlen(buf); - break; + for (i = 0; _ws2_errlist[i].msg; i++) { + if (_ws2_errlist[i].code == errcode) { + strlcpy(buf, _ws2_errlist[i].msg, bufsize); + return buf; } } } @@ -497,11 +570,9 @@ * as visually perfect as moving all the remaining message over, * but more efficient. */ - i = len; - while (i) { - i--; - if ((buf[i] == '\r') || (buf[i] == '\n')) - buf[i] = ' '; + while (len--) { + if ((buf[len] == '\r') || (buf[len] == '\n')) + buf[len] = ' '; } } else {