XCore CBase

Files CCore/inc/libc/CBase.h CCore/src/libc/CBase.cpp

XCore provides implementation of the C standard library functions. Such implementation requires some system service. This implementation includes memory allocation functions, timer functions, assert functions and stdio functions. Target must provide some basic definitions in the CBase.h header file to adapt this implementation. These definitions are enclosed in the namespace LibC_Internal.


/* CBase.h */

#ifndef CCore_inc_libc_CBase_h
#define CCore_inc_libc_CBase_h

namespace LibC_Internal {

/* types */

using PtrValue = unsigned ;

      // to represent void *


using Size = unsigned ;

      // size_t : unsigned , unsigned long


using Format_sj_t =          long long ;
using Format_uj_t = unsigned long long ;

      // intmax_t


using Format_sz_t =      int ;
using Format_uz_t = unsigned ;

      // size_t


using Format_st_t =      int ;
using Format_ut_t = unsigned ;

      // ptrdiff_t


PtrValue is an unsigned integral type to be used to represent a pointer value.

Size is an unsigned integral type to be used to represent a size value (internal size_t).

The following types are used to pass some specific arguments using ... function argument specifications.

Format_sj_t is a largest signed integral type.

Format_uj_t is a largest unsigned integral type.

Format_sz_t is a "size_t" signed integral type.

Format_uz_t is a "size_t" unsigned integral type.

Format_st_t is a "ptrdiff_t" signed integral type.

Format_ut_t is a "ptrdiff_t" unsigned integral type.


/* consts */

const Size NumberBufSize = 64 ;

const Size PtrValueHexSize = 8 ;

/* types */

using FilePos = unsigned long long ;

/* consts */

const Size FileBufSize = 4*(1<<10) ;

NumberBufSize is the number of octal digits required to represent the unsigned long long type plus one.

PtrValueHexSize is the number of hex digits required to represent the PtrValue.

FilePos is used to represent the file position, it is an unsigned integral type.

FileBufSize is the file IO buffer size.


/* functions */

void Abort(const char *zstr);

/* char prop functions */

inline bool IsSpace(char ch) // 0 is not a space
 {
  return ch==' ' || ch=='\n' || ch=='\r' || ch=='\t' || ch=='\v' || ch=='\f' ;
 }

/* signed int functions */

template <class SInt,class UInt>
void SetPosInt(SInt *out,UInt value) { *out=(SInt)value; }

template <class SInt,class UInt>
void SetNegInt(SInt *out,UInt value) { *out=(SInt)(UInt)-value; }

} // namespace LibC_Internal

#endif

Abort() is the abort functions.

IsSpace() is the space character detection function.

SetPosInt() is used to create a positive signed value from the unsigned magnitude.

SetNegInt() is used to create a negative signed value from the unsigned magnitude.

The STD implementation of the Abort() is :


/* CBase.cpp */

#include <CCore/inc/libc/CBase.h>

#include <__std_init.h>

namespace LibC_Internal {

/* functions */

void Abort(const char *zstr) { __std_abort(zstr); }

} // namespace LibC_Internal