#ifndef __SECURE_CODING_UTIL_H__
#define __SECURE_CODING_UTIL_H__

#ifdef __cplusplus
#ifndef BEGIN_DECLS
#define BEGIN_DECLS extern "C" {
#endif
#ifndef END_DECLS
#define END_DECLS }
#endif
#else
#ifndef BEGIN_DECLS
#define BEGIN_DECLS
#endif
#ifndef END_DECLS
#define END_DECLS
#endif
#endif


BEGIN_DECLS

#if defined(_WIN32) && defined(UNICODE)
#include <wchar.h>
#endif

#include <stdio.h>
#include <string.h>

#include "StringUtil.h"

#define SEC_ERR_SUCCESS                         0
#define SEC_ERR_NO_MEM                          -1
#define SEC_ERR_RANGE_OVERLAPPED                -2
#define SEC_ERR_DESTINATION_SIZE_OVERFLOW       -3
#define SEC_ERR_NULL_PARAMETER                  -4
#define SEC_ERR_DESTINATION_LEN_ZERO            -5
#define SEC_ERR_SIZE_TOO_BIG                    -6
#define SEC_ERR_NOT_FOUND                       -7

#ifndef __SECURE_CODING
#define memset_s(dest, dmax, value, n)          memset(dest, value, n)
#define memcpy_s(dest, dmax, src, slen)         memcpy(dest, src, slen)
#define memmove_s(dest, dmax, src, slen)        memmove(dest, src, slen)
#define strnlen_s(str, smax)                    strnlen(str, smax)
//#define strncpy_s(dest, dmax, src, slen)        strncpy(dest, src, slen)
#define printf_s                                printf
#define strtok_s(str, strmax, delim, ptr)       strtok(str, delim)
#else
#include <libsafec/safe_lib.h>
#include <libsafec/safe_str_lib.h>
#include <libsafec/safe_mem_lib.h>
#include <libsafec/safe_lib_errno.h>
#endif

int SafeMemCopy(void *pDestination, int nDestinationSize, const void *pSource, int nSourceSize);
int SafeMemSet(void *pDestination, int nDestinationSize, const char cValue, int nSetSize);
int SafeStrCmp(const char *pDestination, int nDestinationSize, const char *pSource, int *pnCmpResult);
int SafeStrCat(char *pDestination, int nDestinationSize, const char *pSource, int nSourceSize);
int SafeStrNCopy(char *pDestination, int nDestinationSize, const char *pSource, int nSourceSize);
int SafeStrCopy(char *pDestination, int nDestinationSize, const char *pSource);
int SafeMemCmp(const void *pDestination, int nDestinationSize, const void *pSource, int pSourceSize, int *pnCmpResult);
int SafeStrChr(const char *pSource, int nSourceSize, char cSearchChar, char **pCharPointer);
int SafeStrrChr(const char *pSource, int nSourceSize, char cSearchChar, char **pCharPointer);

END_DECLS

#endif
