diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/dk4error.h |
Initial commit
Diffstat (limited to 'support/dktools/dk4error.h')
-rw-r--r-- | support/dktools/dk4error.h | 547 |
1 files changed, 547 insertions, 0 deletions
diff --git a/support/dktools/dk4error.h b/support/dktools/dk4error.h new file mode 100644 index 0000000000..cb64f2ab04 --- /dev/null +++ b/support/dktools/dk4error.h @@ -0,0 +1,547 @@ +/* + WARNING: This file was generated by dkct. + Changes you make here will be lost if dkct is run again! + You should modify the original source and run dkct on it. + Original source: dk4error.ctr +*/ + +/* +Copyright (C) 2015-2017, Dirk Krause + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above opyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +* Neither the name of the author nor the names of contributors may be used + to endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef DK4ERROR_H_INCLUDED +/** Avoid multiple inclusions. */ +#define DK4ERROR_H_INCLUDED 1 + + +#line 9 "dk4error.ctr" + +/** @file + Return error information from + called function to caller, more detailed than just an + error code. + + In addition to the error code we can save details, i.e. + the errno or GetLastError() value or the element size + and number of elements for a failed memory allocation... + This allows the caller to produce detailed error messages + if necessary. + + Before processing a code section where errors can occur, + use dk4error_init() to initialize an error structure. + A value indicating ``no error occured'' is set in the structure. + + Depending on the errors occuring, the code section might use + one from the dk4error_set_...() functions. + + At the end of the code section, check the error code in the + dk4_er_t structure. + + + The address of one dk4_er_t can be passed to several function + calls. Only the first error occured is noted in the structure, + it is not overwritten by later errors. +*/ + +#ifndef DK4CONF_H_INCLUDED +#include "dk4conf.h" +#endif + +#ifndef DK4TYPES_H_INCLUDED +#include "dk4types.h" +#endif + + + +/** Error report. +*/ +typedef struct { + /** Details. + */ + union { + /** Position within a file or data stream. + */ + struct { + dk4_um_t byteno; /**< Byte number. */ + dk4_um_t lineno; /**< Line number. */ + dk4_um_t charno; /**< Character number. */ + dk4_um_t charinline; /**< Character number within the line. */ + } fpos; + /** Failed memory allocation. + */ + struct { + size_t elsize; /**< Element size. */ + size_t nelem; /**< Number of elements. */ + } mem; + int iDetails1; /**< Integer details. */ + long lDetails1; /**< Long details. */ + } dt; + int ec; /**< Error code. */ +} dk4_er_t; + + + +#ifdef __cplusplus +extern "C" { +#endif + +/** Initialize error report. + + CRT on Windows: Optional. + @param erp Error report to initialize. +*/ +void +dk4error_init(dk4_er_t *erp); + +/** Set simple error code. + + CRT on Windows: Not used. + @param erp Error report to modify, may be NULL. + @param ec New error code. +*/ +void +dk4error_set_simple_error_code(dk4_er_t *erp, int ec); + +/** Set error code for dealing with a number of elements + (memory allocation). + + CRT on Windows: Not used. + @param erp Error report to modify, may be NULL. + @param ec New error code to set. + @param sz Element size. + @param ne Number of elements. +*/ +void +dk4error_set_elsize_nelem(dk4_er_t *erp, int ec, size_t sz, size_t ne); + +/** Set error code for error from a system function, save + errno value in details. + + CRT on Windows: Not used. + @param erp Error report to modify, may be NULL. + @param ec New error code to set. + @param errnval Value of errno, stored in iDetails1. +*/ +void +dk4error_set_idetails(dk4_er_t *erp, int ec, int errnval); + +/** Set long error code for error from a Windows system function, + save GetLastError() value in details. + + CRT on Windows: Not used. + @param erp Error report to modify, may be NULL. + @param ec New error code to set. + @param errnval Value obtained from GetLastError(). +*/ +void +dk4error_set_ldetails(dk4_er_t *erp, int ec, long errnval); + +/** Set error code and keep file or data stream position. + + CRT on Windows: Not used. + @param erp Error report to modify, may be NULL. + @param ec New error code to set. + @param byteno Byte position in file. + @param lineno Current line number. + @param charno Character number in file. + @param charinline Character position in line. +*/ +void +dk4error_set_with_position( + dk4_er_t *erp, + int ec, + dk4_um_t byteno, + dk4_um_t lineno, + dk4_um_t charno, + dk4_um_t charinline +); + +/** Copy error report if there was an error in the source report + and no error yet in the destination report. + + CRT on Windows: Optional. + @param dptr Destination report. + @param sptr Source report. +*/ +void +dk4error_copy(dk4_er_t *dptr, const dk4_er_t *sptr); + +#ifdef __cplusplus +} +#endif + + + +/** Error codes. +*/ +enum { + + /** No error occured. + */ + DK4_E_NONE = 0, + + /** System error, the errno value is saved to + det,syserr. + */ + DK4_E_SYSTEM , + + /** Something failed although it should not. + */ + DK4_E_BUG , + + /** Invalid arguments (in example NULL pointers, + 0 sizes) were passed to a function. + No details are reported. + */ + DK4_E_INVALID_ARGUMENTS , + + /** A buffer was too small to take a text + completely. + */ + DK4_E_BUFFER_TOO_SMALL , + + /** The requested information was not found. + */ + DK4_E_NOT_FOUND , + + /** Memory allocation failed. Element size and + number of elements are stored in + dt,mem,elsize and dt,mem,nelem. + */ + DK4_E_MEMORY_ALLOCATION_FAILED , + + /** Numeric overflow. For floating point numbers + the absolute value exceeded DBL_MAX. + For integer numbers the result is outside + the range MIN...MAX. + No details are reported. + */ + DK4_E_MATH_OVERFLOW , + + /** Numeric underflow. + The underflow is reported if the absolute + value of a floating point operation is too + small. + For integer numbers only overflow is reported + even if the result is smaller than MIN. + No details are reported. + */ + DK4_E_MATH_UNDERFLOW , + + /** Division by zero. No details are reported. + */ + DK4_E_MATH_DIVZERO , + + /** An invalid argument was passed to a + mathematical function. + */ + DK4_E_MATH_INVALID , + + /** Mathematical result is inexact, cutting bits. + */ + DK4_E_MATH_INEXACT , + + /** Syntax error when processing text, illegal + character when decoding or encoding. + */ + DK4_E_SYNTAX , + + /** Functionality not supported on this system. + */ + DK4_E_NOT_SUPPORTED , + + /** A write operation failed. + */ + DK4_E_WRITE_FAILED , + + /** A data flush operation failed. + */ + DK4_E_FLUSH_FAILED , + + /** Failed to read data. + */ + DK4_E_READ_FAILED , + /** A file or other stream close operation failed. + */ + DK4_E_CLOSE_FAILED , + + /** Additional security checks before opening a + file failed. + */ + DK4_E_SEC_CHECK , + + /** Attempt to open a file failed. + */ + DK4_E_OPEN_FAILED , + + /** Failed to open file for reading. + */ + DK4_E_OPEN_READ_FAILED , + + /** Failed to open file for writing. + */ + DK4_E_OPEN_WRITE_FAILED , + + /** Failed to encode 32 bit character to + output encoding. + */ + DK4_E_ENCODING_FAILED , + + /** Failed to decode 32 bit character from + input encoding. + */ + DK4_E_DECODING_FAILED , + + /** Failed to create a directory. + */ + DK4_E_MKDIR_FAILED , + + /** Failed to change file or directory ownership. + */ + DK4_E_CHOWN_FAILED , + + /** Failed to change file or directory permissions. + */ + DK4_E_CHMOD_FAILED , + + /** Non-directory component in path name. + */ + DK4_E_NON_DIR , + + /** File exists, but is not a socket. + */ + DK4_E_NON_SOCKET , + + /** An unlink operation failed. + */ + DK4_E_UNLINK_FAILED , + + /** The DeleteFile() function on Windows failed. + */ + DK4_E_DELETE_FILE_FAILED , + + /** An rmdir operation failed. + */ + DK4_E_RMDIR_FAILED , + + /** The RemoveDirectory() function failed + on Windows. + */ + DK4_E_REMOVE_DIRECTORY_FAILED , + + /** Opendir failed. + */ + DK4_E_OPENDIR_FAILED , + + /** The CreateFile() function failed on Windows. + The result of GetLastError() is stored + in dt.lDetails1. + */ + DK4_E_CREATE_FILE_FAILED , + + /** The CreateDirectory() function failed on + Windows. The result of GetLastError() is + stored in dt.lDetails1. + */ + DK4_E_CREATE_DIR_FAILED , + + /** The GetFileInformationByHandle() function + failed on Windows. The result of + GetLastError() is stored in dt.lDetails1. + */ + DK4_E_FILE_INFORMATION_FAILED , + + /** The FindFirstFile() function on Windows failed. + The GetLastError() value is stored in lDetails1. + */ + DK4_E_FINDFIRSTFILE_FAILED , + + /** Timeout occured in socket operation, + no details in iDetails1. + */ + DK4_E_SOCKET_TIMEOUT , + + /** The getaddrinfo() function failed to + find the remote address. + The function result is stored in iDetails1. + */ + DK4_E_SOCKET_GETADDRINFO , + + /** The getaddrinfo() function failed to + find the local address. + The function result is stored in iDetails1. + */ + DK4_E_SOCKET_GETADDRLOC , + + /** Failed to start up Windows sockets. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_UP , + + /** Failed to shut down Windows sockets. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_DOWN , + + /** The socket() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_SOCKET , + + /** The close() or closesocket() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_CLOSE , + + /** The bind() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_BIND , + + /** The connect() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_CONNECT , + + /** The listen() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_LISTEN , + + /** The accept() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_ACCEPT , + + /** The select() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_SELECT , + + /** The setsockopt() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_SETSOCKOPT , + + /** The getsockopt() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_GETSOCKOPT , + + /** The shutdown() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_SHUTDOWN , + + /** The send()/sendto() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_SEND , + + /** The recv()/recvfrom() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_RECV , + + /** The ioctlsocket() function failed. + The error code from WSAGetLastError() on + Windows is stored in iDetails1. + On Windows only. + */ + DK4_E_SOCKET_IOCTLSOCKET , + + /** The fcntl() function failed. + The error code from + errno on non-Windows is stored + in iDetails1. + Not on Windows systems (ioctlsocket + is used to switch between blocking + and non-blocking). + */ + DK4_E_SOCKET_FCNTL , + + /** The getservbyname() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_GETSERVBYNAME , + + /** The gethostbyname() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_GETHOSTBYNAME , + + /** The inet_ntop() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_INET_NTOP , + + /** The inet_pton() function failed. + The error code from WSAGetLastError() on + Windows / errno on non-Windows is stored + in iDetails1. + */ + DK4_E_SOCKET_INET_PTON , +}; + + + + +#endif |