err_codes.c File Reference

Common error codes and conversion into error strings. More...

#include "ErrStringTable.h"
+ Include dependency graph for err_codes.c:

Functions

const char * ErrorToString (TErrCode ErrNum)
 This function converts error code into error string. More...
 

Detailed Description

Common error codes and conversion into error strings.

Author
Uwe Kindler (UK)
Date
2007/30/27

Function Documentation

const char* ErrorToString ( TErrCode  ErrCode)

This function converts error code into error string.

Parameters
[in]ErrCodeNumeric error code to convert into error message string
Returns
Error string

Referenced by CsiErrorToString().

24 {
25  //
26  // We do a binary search here to be fast
27  //
28  int32_t left = 0;
29  int32_t right = (sizeof(ErrMsgTbl) / sizeof(TErrTblEntry)) - 1;
30 
31  while (left <= right)
32  {
33  int middle = (left + right) / 2;
34  if (ErrMsgTbl[middle].ErrId < ErrNum)
35  {
36  left = middle + 1;
37  }
38  else if (ErrMsgTbl[middle].ErrId > ErrNum)
39  {
40  right = middle - 1;
41  }
42  else
43  {
44  return ErrMsgTbl[middle].ErrMsg;
45  }
46  }
47 
48  return "Unknown error or invalid error code";
49 }
static const TErrTblEntry ErrMsgTbl[]
Static table of error code and string.
Definition: ErrStringTable.h:274
One table entry contains error code and error string.
Definition: ErrStringTable.h:23