Manages string table of system errors.
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2013 Jörg Seebohn
Header file ErrorContext.
Implementation file ErrorContext impl.
typedef struct errorcontext_t errorcontext_t
Export errorcontext_t into global namespace.
extern uint16_t g_errorcontext_stroffset[]
Used in <processcontext_INIT_STATIC> to initialize static processcontext_t.
extern uint8_t g_errorcontext_strdata[]
Used in <processcontext_INIT_STATIC> to initialize static processcontext_t.
test | |
unittest_context_errorcontext | Test errorcontext_t functionality. |
int unittest_context_errorcontext( void )
Test errorcontext_t functionality.
struct errorcontext_t
Stores description of system errors in a string table. Used as replacement for strerror.
stroffset | Table with offset values relative to strdata. |
strdata | String table with system error descriptions in english. |
initonce | |
initonce_errorcontext | Called from maincontext_t.init_maincontext. |
freeonce_errorcontext | Called from maincontext_t.free_maincontext. |
lifetime | |
errorcontext_FREE | Static initializer. |
errorcontext_INIT_STATIC | Static initializer used in <processcontext_INIT_STATIC>. |
init_errorcontext | Initializes errcontext with static system error string table. |
free_errorcontext | Sets members of errcontext to 0. |
query | |
maxsyserrnum_errorcontext | Returns the number of system error entries. |
str_errorcontext | Returns the error description of errnum as a null terminated C string. |
generic | |
genericcast_errorcontext | Casts a pointer to generic object into pointer to errorcontext_t. |
uint16_t * stroffset
Table with offset values relative to strdata. The tables length is equal to 256 but all entries with index > maxsyserrnum_errorcontext share the same offset to string “Unknown error”.
int initonce_errorcontext( /*out*/errorcontext_t * error )
Called from maincontext_t.init_maincontext. The parameter errcontext supports any generic object type which has the same structure as errorcontext_t.
int freeonce_errorcontext( errorcontext_t * error )
Called from maincontext_t.free_maincontext. The parameter errcontext supports any generic object type which has the same structure as errorcontext_t. This operation is a no op. This ensures that errorcontext_t works in an uninitialized (static) context.
const uint8_t * str_errorcontext( const errorcontext_t errcontext, int errnum )
Returns the error description of errnum as a null terminated C string. The value of errnum should be set to the value returned in errno. If errnum is < 0 or errnum > maxsyserrnum_errorcontext then string “Unknown error” is returned.
errorcontext_t * genericcast_errorcontext( void * object )
Casts a pointer to generic object into pointer to errorcontext_t. The object must have members with the same name and type as errorcontext_t and in the same order.
#define initonce_errorcontext( error ) (init_errorcontext(genericcast_errorcontext(error)))
Implements errorcontext_t.initonce_errorcontext.
#define freeonce_errorcontext( error ) (0)
Implements errorcontext_t.freeonce_errorcontext.
#define genericcast_errorcontext( object ) ( __extension__ ({ typeof(object) _obj = (object) ; errorcontext_t * _errcon = 0 ; static_assert( sizeof(_errcon->stroffset) == sizeof(_obj->stroffset) && sizeof((_errcon->stroffset)[0]) == sizeof((_obj->stroffset)[0]) && offsetof(errorcontext_t, stroffset) == offsetof(typeof(*_obj), stroffset) && sizeof(_errcon->strdata) == sizeof(_obj->strdata) && sizeof(_errcon->strdata[0]) == sizeof(_obj->strdata[0]) && offsetof(errorcontext_t, strdata) == offsetof(typeof(*_obj), strdata), "members are compatible") ; if (0) { volatile uint16_t _off ; volatile uint8_t _str ; _off = _obj->stroffset[0] ; _str = _obj->strdata[_off] ; (void) _str ; } (void) _errcon ; (errorcontext_t *)(_obj) ; }))
Implements errorcontext_t.genericcast_errorcontext.
#define maxsyserrnum_errorcontext( ) (132)
Implements errorcontext_t.maxsyserrnum_errorcontext.
#define str_errorcontext( errcontext, errnum ) ( __extension__ ({ unsigned _errnum = (unsigned) (errnum) ; (errcontext).strdata + (errcontext).stroffset[ (_errnum > 511 ? 511 : _errnum)] ; }))
Implements errorcontext_t.str_errorcontext.
Export errorcontext_t into global namespace.
typedef struct errorcontext_t errorcontext_t
Stores description of system errors in a string table.
struct errorcontext_t
Used in processcontext_INIT_STATIC to initialize static processcontext_t.
extern uint16_t g_errorcontext_stroffset[]
Defines computing environment / context which is shared between all threads of computation.
struct processcontext_t
Used in processcontext_INIT_STATIC to initialize static processcontext_t.
extern uint8_t g_errorcontext_strdata[]
Test errorcontext_t functionality.
int unittest_context_errorcontext( void )
Table with offset values relative to strdata.
uint16_t * stroffset
String table with system error descriptions in english.
uint8_t * strdata
Called from maincontext_t.init_maincontext.
int initonce_errorcontext( /*out*/errorcontext_t * error )
Initializes global program context.
int init_maincontext( const maincontext_e context_type, int argc, const char ** argv )
Called from maincontext_t.free_maincontext.
int freeonce_errorcontext( errorcontext_t * error )
Frees global context.
int free_maincontext( void )
Static initializer.
#define errorcontext_FREE { 0, 0 }
Static initializer used in processcontext_INIT_STATIC.
#define errorcontext_INIT_STATIC { g_errorcontext_stroffset, g_errorcontext_strdata }
Initializes errcontext with static system error string table.
int init_errorcontext( /*out*/errorcontext_t * errcontext )
Sets members of errcontext to 0.
int free_errorcontext( errorcontext_t * errcontext )
Returns the number of system error entries.
uint16_t maxsyserrnum_errorcontext( void )
Returns the error description of errnum as a null terminated C string.
const uint8_t * str_errorcontext( const errorcontext_t errcontext, int errnum )
Casts a pointer to generic object into pointer to errorcontext_t.
errorcontext_t * genericcast_errorcontext( void * object )
Implements errorcontext_t.initonce_errorcontext.
#define initonce_errorcontext( error ) (init_errorcontext(genericcast_errorcontext(error)))
Implements errorcontext_t.freeonce_errorcontext.
#define freeonce_errorcontext( error ) (0)
Implements errorcontext_t.genericcast_errorcontext.
#define genericcast_errorcontext( object ) ( __extension__ ({ typeof(object) _obj = (object) ; errorcontext_t * _errcon = 0 ; static_assert( sizeof(_errcon->stroffset) == sizeof(_obj->stroffset) && sizeof((_errcon->stroffset)[0]) == sizeof((_obj->stroffset)[0]) && offsetof(errorcontext_t, stroffset) == offsetof(typeof(*_obj), stroffset) && sizeof(_errcon->strdata) == sizeof(_obj->strdata) && sizeof(_errcon->strdata[0]) == sizeof(_obj->strdata[0]) && offsetof(errorcontext_t, strdata) == offsetof(typeof(*_obj), strdata), "members are compatible") ; if (0) { volatile uint16_t _off ; volatile uint8_t _str ; _off = _obj->stroffset[0] ; _str = _obj->strdata[_off] ; (void) _str ; } (void) _errcon ; (errorcontext_t *)(_obj) ; }))
Implements errorcontext_t.maxsyserrnum_errorcontext.
#define maxsyserrnum_errorcontext( ) (132)
Implements errorcontext_t.str_errorcontext.
#define str_errorcontext( errcontext, errnum ) ( __extension__ ({ unsigned _errnum = (unsigned) (errnum) ; (errcontext).strdata + (errcontext).stroffset[ (_errnum > 511 ? 511 : _errnum)] ; }))