ErrorContext

Manages string table of system errors.

Summary
ErrorContextManages string table of system errors.
CopyrightThis program is free software.
Files
C-kern/api/context/errorcontext.hHeader file ErrorContext.
C-kern/context/errorcontext.cImplementation file ErrorContext impl.
Types
struct errorcontext_tExport errorcontext_t into global namespace.
Variables
g_errorcontext_stroffsetUsed in <processcontext_INIT_STATIC> to initialize static processcontext_t.
g_errorcontext_strdataUsed in <processcontext_INIT_STATIC> to initialize static processcontext_t.
Functions
test
unittest_context_errorcontextTest errorcontext_t functionality.
errorcontext_tStores description of system errors in a string table.
stroffsetTable with offset values relative to strdata.
strdataString table with system error descriptions in english.
initonce
initonce_errorcontextCalled from maincontext_t.init_maincontext.
freeonce_errorcontextCalled from maincontext_t.free_maincontext.
lifetime
errorcontext_FREEStatic initializer.
errorcontext_INIT_STATICStatic initializer used in <processcontext_INIT_STATIC>.
init_errorcontextInitializes errcontext with static system error string table.
free_errorcontextSets members of errcontext to 0.
query
maxsyserrnum_errorcontextReturns the number of system error entries.
str_errorcontextReturns the error description of errnum as a null terminated C string.
generic
genericcast_errorcontextCasts a pointer to generic object into pointer to errorcontext_t.
inline implementation
Macros
initonce_errorcontextImplements errorcontext_t.initonce_errorcontext.
freeonce_errorcontextImplements errorcontext_t.freeonce_errorcontext.
genericcast_errorcontextImplements errorcontext_t.genericcast_errorcontext.
maxsyserrnum_errorcontextImplements errorcontext_t.maxsyserrnum_errorcontext.
str_errorcontextImplements errorcontext_t.str_errorcontext.

Copyright

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.

Author

© 2013 Jörg Seebohn

Files

C-kern/api/context/errorcontext.h

Header file ErrorContext.

C-kern/context/errorcontext.c

Implementation file ErrorContext impl.

Types

struct errorcontext_t

typedef struct errorcontext_t errorcontext_t

Export errorcontext_t into global namespace.

Variables

g_errorcontext_stroffset

extern uint16_t g_errorcontext_stroffset[]

Used in <processcontext_INIT_STATIC> to initialize static processcontext_t.

g_errorcontext_strdata

extern uint8_t g_errorcontext_strdata[]

Used in <processcontext_INIT_STATIC> to initialize static processcontext_t.

Functions

test

unittest_context_errorcontext

int unittest_context_errorcontext(void)

Test errorcontext_t functionality.

errorcontext_t

struct errorcontext_t

Stores description of system errors in a string table.  Used as replacement for strerror.

Summary
stroffsetTable with offset values relative to strdata.
strdataString table with system error descriptions in english.
initonce
initonce_errorcontextCalled from maincontext_t.init_maincontext.
freeonce_errorcontextCalled from maincontext_t.free_maincontext.
lifetime
errorcontext_FREEStatic initializer.
errorcontext_INIT_STATICStatic initializer used in <processcontext_INIT_STATIC>.
init_errorcontextInitializes errcontext with static system error string table.
free_errorcontextSets members of errcontext to 0.
query
maxsyserrnum_errorcontextReturns the number of system error entries.
str_errorcontextReturns the error description of errnum as a null terminated C string.
generic
genericcast_errorcontextCasts a pointer to generic object into pointer to errorcontext_t.

stroffset

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”.

strdata

uint8_t * strdata

String table with system error descriptions in english.  Last byte of string is a ‘\0’ byte (C string).

initonce

initonce_errorcontext

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.

freeonce_errorcontext

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.

lifetime

errorcontext_FREE

#define errorcontext_FREE { 0, 0 }

Static initializer.

errorcontext_INIT_STATIC

#define errorcontext_INIT_STATIC { g_errorcontext_stroffset, g_errorcontext_strdata }

Static initializer used in <processcontext_INIT_STATIC>.

init_errorcontext

int init_errorcontext(/*out*/errorcontext_t *errcontext)

Initializes errcontext with static system error string table.

free_errorcontext

int free_errorcontext(errorcontext_t *errcontext)

Sets members of errcontext to 0.

query

maxsyserrnum_errorcontext

uint16_t maxsyserrnum_errorcontext(void)

Returns the number of system error entries.

str_errorcontext

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.

generic

genericcast_errorcontext

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.

Macros

initonce_errorcontext

#define initonce_errorcontext(
   error
) (init_errorcontext(genericcast_errorcontext(error)))

Implements errorcontext_t.initonce_errorcontext.

freeonce_errorcontext

#define freeonce_errorcontext(error) (0)

Implements errorcontext_t.freeonce_errorcontext.

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.genericcast_errorcontext.

maxsyserrnum_errorcontext

#define maxsyserrnum_errorcontext() (132)

Implements errorcontext_t.maxsyserrnum_errorcontext.

str_errorcontext

#define str_errorcontext(
   errcontext,
   errnum
) ( __extension__ ({ unsigned _errnum = (unsigned) (errnum) ; (errcontext).strdata + (errcontext).stroffset[ (_errnum > 511 ? 511 : _errnum)] ; }))

Implements errorcontext_t.str_errorcontext.

Manages string table of system errors.
Implements ErrorContext.
typedef struct errorcontext_t errorcontext_t
Export errorcontext_t into global namespace.
struct errorcontext_t
Stores description of system errors in a string table.
extern uint16_t g_errorcontext_stroffset[]
Used in processcontext_INIT_STATIC to initialize static processcontext_t.
struct processcontext_t
Defines computing environment / context which is shared between all threads of computation.
extern uint8_t g_errorcontext_strdata[]
Used in processcontext_INIT_STATIC to initialize static processcontext_t.
int unittest_context_errorcontext(void)
Test errorcontext_t functionality.
uint16_t * stroffset
Table with offset values relative to strdata.
uint8_t * strdata
String table with system error descriptions in english.
int initonce_errorcontext(/*out*/errorcontext_t *error)
Called from maincontext_t.init_maincontext.
int init_maincontext(const maincontext_e context_type,
int argc,
const char **argv)
Initializes global program context.
int freeonce_errorcontext(errorcontext_t *error)
Called from maincontext_t.free_maincontext.
int free_maincontext(void)
Frees global context.
#define errorcontext_FREE { 0, 0 }
Static initializer.
#define errorcontext_INIT_STATIC { g_errorcontext_stroffset, g_errorcontext_strdata }
Static initializer used in processcontext_INIT_STATIC.
int init_errorcontext(/*out*/errorcontext_t *errcontext)
Initializes errcontext with static system error string table.
int free_errorcontext(errorcontext_t *errcontext)
Sets members of errcontext to 0.
uint16_t maxsyserrnum_errorcontext(void)
Returns the number of system error entries.
const uint8_t * str_errorcontext(const errorcontext_t errcontext,
int errnum)
Returns the error description of errnum as a null terminated C string.
errorcontext_t * genericcast_errorcontext(void *object)
Casts a pointer to generic object into pointer to errorcontext_t.
#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.
Close