yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
48ac6f25f
master
1#ifndef _WIN32 2#ifndef SLANG_CORE_SECURE_CRT_H 3#define SLANG_CORE_SECURE_CRT_H 4#include <assert.h> 5#include <stdarg.h> 6#include <stdio.h> 7#include <stdlib.h> 8#include <string.h> 9#include <strings.h> 10#include <wchar.h> 11 12inline void memcpy_s (void * dest , [[maybe_unused ]]size_t destSize ,const void * src ,size_t count ) 13{ 14assert (destSize >=count ); 15memcpy (dest ,src ,count ); 16} 17 18#define _TRUNCATE ((size_t)-1) 19#define _stricmp strcasecmp 20 21inline void fopen_s (FILE ** f ,const char * fileName ,const char * mode ) 22{ 23* f = fopen (fileName ,mode ); 24} 25 26inline size_t fread_s ( 27void * buffer , 28 [[maybe_unused ]]size_t bufferSize , 29size_t elementSize , 30size_t count , 31FILE * stream ) 32{ 33assert (bufferSize >=elementSize * count ); 34return fread (buffer ,elementSize ,count ,stream ); 35} 36 37inline size_t wcsnlen_s (const wchar_t * str ,size_t /*numberofElements*/ ) 38{ 39return wcslen (str ); 40} 41 42inline size_t strnlen_s (const char * str ,size_t numberOfElements ) 43{ 44#if defined(__CYGWIN__ ) 45const char * cur = str ; 46if (str ) 47 { 48const char * const end = str + numberOfElements ; 49while (* cur && cur < end ) 50cur ++ ; 51 } 52return size_t (cur - str ); 53#else 54return strnlen (str ,numberOfElements ); 55#endif 56} 57 58__attribute__((format (printf ,3 ,4 )))inline int sprintf_s ( 59char * buffer , 60size_t sizeOfBuffer , 61const char * format , 62 ...) 63{ 64va_list argptr ; 65va_start (argptr ,format ); 66int rs = vsnprintf (buffer ,sizeOfBuffer ,format ,argptr ); 67va_end (argptr ); 68return rs ; 69} 70 71// A patch was submitted to GCC wchar_t support in 2001, so I'm sure we can 72// enable this any day now... 73// __attribute__((format(wprintf, 3, 4))) 74inline int swprintf_s (wchar_t * buffer ,size_t sizeOfBuffer ,const wchar_t * format , ...) 75{ 76va_list argptr ; 77va_start (argptr ,format ); 78int rs = vswprintf (buffer ,sizeOfBuffer ,format ,argptr ); 79va_end (argptr ); 80return rs ; 81} 82 83inline void wcscpy_s (wchar_t * strDestination ,size_t /*numberOfElements*/ ,const wchar_t * strSource ) 84{ 85wcscpy (strDestination ,strSource ); 86} 87inline void strcpy_s (char * strDestination ,size_t /*numberOfElements*/ ,const char * strSource ) 88{ 89strcpy (strDestination ,strSource ); 90} 91 92inline void wcsncpy_s ( 93wchar_t * strDestination , 94size_t /*numberOfElements*/ , 95const wchar_t * strSource , 96size_t count ) 97{ 98wcsncpy (strDestination ,strSource ,count ); 99} 100inline void strncpy_s ( 101char * strDestination , 102size_t /*numberOfElements*/ , 103const char * strSource , 104size_t count ) 105{ 106strncpy (strDestination ,strSource ,count ); 107} 108#endif 109#endif