/* The X64 libraries from Microsoft are missing all the 'secure' system
   calls. Below are some glue functions to translate the _s calls into
   flat calls. */

#include "x64glue.h"

errno_t fopen_s(FILE** pFile, const char *filename, const char *mode) {
  *pFile = fopen(filename,mode);
  return(0);
  }

errno_t _wfopen_s(FILE** pFile, const WCHAR *filename, const WCHAR *mode) {
  *pFile = _wfopen(filename,mode);
  return(0);
  }

errno_t localtime_s(struct tm *TimeTm, const time_t *Time) {
  struct tm *TempTm;
  TempTm = localtime(Time);
  memcpy(TimeTm,TempTm,sizeof(struct tm));
  return(0);
  }

errno_t _ftime64_s(struct __timeb64 *TimeB) {
  _ftime64(TimeB);
  return(0);
  }

errno_t strcpy_s(char *StrDestination, size_t SizeInBytes, const char *StrSource) {
  strcpy(StrDestination,StrSource);
  return(0);
  }

errno_t strncpy_s(char *StrDestination, size_t SizeInBytes, const char *StrSource, size_t Count) {
  strncpy(StrDestination,StrSource,Count);
  return(0);
  }

errno_t wcscpy_s(wchar_t *StrDestination, size_t SizeInBytes, const wchar_t *StrSource) {
  wcscpy(StrDestination,StrSource);
  return(0);
  }

errno_t wcsncpy_s(wchar_t *StrDestination, size_t SizeInBytes, const wchar_t *StrSource, size_t Count) {
  wcsncpy(StrDestination,StrSource,Count);
  return(0);
  }

errno_t strcat_s(char *StrDestination, size_t SizeInBytes, const char *StrSource) {
  strcat(StrDestination,StrSource);
  return(0);
  }

errno_t wcscat_s(wchar_t *StrDestination, size_t SizeInBytes, const wchar_t *StrSource) {
  wcscat(StrDestination,StrSource);
  return(0);
  }

int sprintf_s(char *Buffer, size_t SizeOfBuffer, const char *Format, ... ) {
  va_list Args;

  va_start(Args,Format);
  vsprintf(Buffer,Format,Args);
  va_end(Args);

  return(0);
  }

int swprintf_s(wchar_t *Buffer, size_t SizeOfBuffer, const wchar_t *Format, ... ) {
  va_list Args;

  va_start(Args,Format);
  vswprintf(Buffer,Format,Args);
  va_end(Args);

  return(0);
  }

int vsprintf_s(char *Buffer, size_t SizeOfBuffer, const char *Format, va_list Args) {
  vsprintf(Buffer,Format,Args);
  return(0);
  }

int vswprintf_s(WCHAR *Buffer, size_t SizeOfBuffer, const WCHAR *Format, va_list Args) {
  vswprintf(Buffer,Format,Args);
  return(0);
  }

int vfprintf_s(FILE *Stream, const char *Format, va_list Args) {
  vfprintf(Stream,Format,Args);
  return(0);
  }

int vfwprintf_s(FILE *Stream, const WCHAR *Format, va_list Args) {
  vfwprintf(Stream,Format,Args);
  return(0);
  }

errno_t _strerror_s(char *Buffer, size_t SizeInBytes, const char *strErrMsg) {
  strcpy(Buffer,_strerror(strErrMsg));
  return(0);
  }
