#pragma once
#ifndef LIBC_FUNCTIONS_H
#define LIBC_FUNCTIONS_H

#include "stddef.h"
#include "stdarg.h"

/*  QSEE includes */
#ifdef QSEE
#include "comdef.h"
#include "qsee_services.h"
#include "qsee_heap.h"
#include "qsee_log.h"
//#include "log.h"
#include "ctype.h"
#endif

int libc_init(void);

#if 0
//#include <stdio.h>
//#include <stdarg.h>
//#include <sys/types.h>
//#include <string.h>
//#include <linux/kernel.h>

//#define FILE int
//extern FILE * stderr;
//extern int errno;
//#define assert(STR)
//typedef long unsigned int size_t;
#endif

#ifdef QSEE_DEF_REALLOC
#ifdef malloc
    #undef malloc
#endif
#define malloc qsee_malloc

void* qsee_realloc( void* ptr, size_t size );
#ifdef realloc
    #undef realloc
#endif
#define realloc qsee_realloc


#ifdef free
    #undef free
#endif
#define free qsee_free
#endif

#if 0
//--------------------------------------------------------------------------------------------------
// Memory allocation routines
//--------------------------------------------------------------------------------------------------
void* tz_malloc( size_t size );
#ifdef malloc
	#undef malloc
#endif
#define malloc tz_malloc

void* tz_realloc( void* ptr, size_t size );
#ifdef realloc
	#undef realloc
#endif
#define realloc tz_realloc

void tz_free( void* ptr );
#ifdef free
	#undef free
#endif
#define free tz_free

//--------------------------------------------------------------------------------------------------
//Memory operation routines
//--------------------------------------------------------------------------------------------------

void* tz_memcpy( void* dest, const void* src, size_t n );
#ifdef memcpy
	#undef memcpy
#endif
#define memcpy tz_memcpy

void* tz_memset ( void* ptr, int value, size_t num );
#ifdef memset
	#undef memset
#endif
#define memset tz_memset

void* tz_memchr( const void* s, int c, size_t n );
#ifdef memchr
	#undef memchr
#endif
#define memchr tz_memchr

int tz_memcmp( const void* s1, const void* s2, size_t n );
#ifdef memcmp
	#undef memcmp
#endif
#define memcmp tz_memcmp

//--------------------------------------------------------------------------------------------------
// String operation routines
//--------------------------------------------------------------------------------------------------
char* tz_strcpy( char* dest, const char* src );
#ifdef strcpy
	#undef strcpy
#endif
#define strcpy tz_strcpy

size_t tz_strlen( const char* s );
#ifdef strlen
	#undef strlen
#endif
#define strlen tz_strlen


#endif

#if 0
//--------------------------------------------------------------------------------------------------
//Memory operation routines
//--------------------------------------------------------------------------------------------------
void* tz_memcpy( void* dest, const void* src, size_t n );
#ifdef memcpy
	#undef memcpy
#endif
#define memcpy tz_memcpy

void* tz_memset ( void* ptr, int value, size_t num );
#ifdef memset
	#undef memset
#endif
#define memset tz_memset

void* tz_memchr( const void* s, int c, size_t n );
#ifdef memchr
	#undef memchr
#endif
#define memchr tz_memchr

int tz_memcmp( const void* s1, const void* s2, size_t n );
#ifdef memcmp
	#undef memcmp
#endif
#define memcmp tz_memcmp

void* tz_memmove( void* dest, const void* src, size_t n );
#ifdef memmove
	#undef memmove
#endif
#define memmove tz_memmove

//--------------------------------------------------------------------------------------------------
// String operation routines
//--------------------------------------------------------------------------------------------------
char* tz_strcpy( char* dest, const char* src );
#ifdef strcpy
	#undef strcpy
#endif
#define strcpy tz_strcpy

size_t tz_strlen( const char* s );
#ifdef strlen
	#undef strlen
#endif
#define strlen tz_strlen

int tz_strcmp( const char* s1, const char* s2 );
#ifdef strcmp
	#undef strcmp
#endif
#define strcmp tz_strcmp

char* tz_strchr( const char* s, int c );
#ifdef strchr
	#undef strchr
#endif
#define strchr tz_strchr

char* tz_strerror( int errnum );
#ifdef strerror
	#undef strerror
#endif
#define strerror tz_strerror

char* tz_strncpy( char* dest, const char* src, size_t n );
#ifdef strncpy
	#undef strncpy
#endif
#define strncpy tz_strncpy

long tz_strtol( const char* nptr, char** endptr, int base );
#ifdef strtol
	#undef strtol
#endif
#define strtol tz_strtol

int tz_strncmp( const char* s1, const char* s2, size_t n );
#ifdef strncmp
	#undef strncmp
#endif
#define strncmp tz_strncmp

int tz_strncasecmp( const char* s1, const char* s2, size_t n );
#ifdef strncasecmp
	#undef strncasecmp
#endif
#define strncasecmp tz_strncasecmp

unsigned long tz_strtoul( const char* nptr, char** endptr, int base );
#ifdef strtoul
	#undef strtoul
#endif
#define strtoul tz_strtoul

int tz_strcasecmp( const char* s1, const char* s2 );
#ifdef strcasecmp
	#undef strcasecmp
#endif
#define strcasecmp tz_strcasecmp

char* tz_strcat( char* dest, const char* src );
#ifdef strcat
	#undef strcat
#endif
#define strcat tz_strcat

char* tz_strrchr( const char* s, int n );
#ifdef strrchr
	#undef strrchr
#endif
#define strrchr tz_strrchr

int tz_sscanf( const char* str, const char* format, ...);
#ifdef sscanf
	#undef sscanf
#endif
#define sscanf tz_sscanf

#ifdef strtol
	#undef strtol
#endif
#define strtol simple_strtol

#ifdef strtoul
	#undef strtoul
#endif
#define strtoul simple_strtoul

//--------------------------------------------------------------------------------------------------
// File operation routines
//--------------------------------------------------------------------------------------------------
size_t tz_fwrite( const void* ptr, size_t size, size_t n, FILE* s );
#ifdef fwrite
	#undef fwrite
#endif
#define fwrite tz_fwrite

int tz_fclose( FILE* stream );
#ifdef fclose
	#undef fclose
#endif
#define fclose tz_fclose

int tz_feof( FILE* stream );
#ifdef feof
	#undef feof
#endif
#define feof tz_feof

int tz_ferror( FILE* stream );
#ifdef ferror
	#undef ferror
#endif
#define ferror tz_ferror

int tz_fflush( FILE* stream );
#ifdef fflush
	#undef fflush
#endif
#define fflush tz_fflush

char* tz_fgets( char* s, int n, FILE* stream );
#ifdef fgets
	#undef fgets
#endif
#define fgets tz_fgets

size_t tz_fread( void* ptr, size_t size, size_t n, FILE* stream );
#ifdef fread
	#undef fread
#endif
#define fread tz_fread

int tz_fseek( FILE* stream, long off, int whence );
#ifdef fseek
	#undef fseek
#endif
#define fseek tz_fseek

long tz_ftell( FILE* stream );
#ifdef ftell
	#undef ftell
#endif
#define ftell tz_ftell

int tz_vfprintf( FILE* stream, const char* format, va_list arg );
#ifdef vfprintf
	#undef vfprintf
#endif
#define vfprintf tz_vfprintf

int tz_fprintf( FILE* stream, const char* format, ... );
#ifdef fprintf
	#undef fprintf
#endif
#define fprintf tz_fprintf

FILE* tz_fopen( const char* filename, const char* mode );
#ifdef fopen
	#undef fopen
#endif
#define fopen tz_fopen

//--------------------------------------------------------------------------------------------------
// System routines
//--------------------------------------------------------------------------------------------------
char* tz_getenv( const char* name );
#ifdef getenv
	#undef getenv
#endif
#define getenv tz_getenv

time_t tz_time( time_t* timer );
#ifdef time
	#undef time
#endif
#define time tz_time

void tz_abort( void );
#ifdef abort
	#undef abort
#endif
#define abort tz_abort

pid_t tz_getpid( void );
#ifdef getpid
	#undef getpid
#endif
#define getpid tz_getpid

void tz_qsort ( void* base, size_t num, size_t size, int (* comparator ) ( const void*, const void* ) );
#ifdef qsort
	#undef qsort
#endif
#define qsort tz_qsort

int tz_atoi( const char* str );
#ifdef atoi
	#undef atoi
#endif
#define atoi tz_atoi

struct tm* tz_gmtime_r( const time_t* timep, struct tm* result );
#ifdef gmtime_r
	#undef gmtime_r
#endif
#define gmtime_r tz_gmtime_r

struct tm* tz_localtime( const time_t* timep );
#ifdef localtime
	#undef localtime
#endif
#define localtime tz_localtime

#endif
#endif
