mbusafecrt.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  4. //
  5. /***
  6. * mbusafecrt.h - public declarations for SafeCRT lib
  7. *
  8. *
  9. * Purpose:
  10. * This file contains the public declarations SafeCRT
  11. * functions ported to MacOS. These are the safe versions of
  12. * functions standard functions banned by SWI
  13. *
  14. ****/
  15. /* shields! */
  16. #ifndef MBUSAFECRT_H
  17. #define MBUSAFECRT_H
  18. //#include <wchar.h>
  19. /* MacOS does not define a specifc type for errnos, but SafeCRT does */
  20. typedef int errno_t;
  21. /* errno value that specific to SafeCRT */
  22. #define STRUNCATE 80
  23. // define the return value for success
  24. #define SAFECRT_SUCCESS 0
  25. /*
  26. * Sizes for buffers used by the _makepath() and _splitpath() functions.
  27. * note that the sizes include space for 0-terminator
  28. */
  29. //#define _MAX_PATH 260 /* max. length of full pathname */
  30. //#define _MAX_DRIVE 3 /* max. length of drive component */
  31. //#define _MAX_DIR 256 /* max. length of path component */
  32. //#define _MAX_FNAME 256 /* max. length of file name component */
  33. //#define _MAX_EXT 256 /* max. length of extension component */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. typedef void ( *tSafeCRT_AssertFuncPtr )( const char* inExpression, const char* inComment, const char* inFile, const unsigned long inLineNum );
  38. void MBUSafeCRTSetAssertFunc( tSafeCRT_AssertFuncPtr inAssertFuncPtr );
  39. extern errno_t strcat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc );
  40. extern errno_t wcscat_s( WCHAR* ioDest, size_t inDestBufferSize, const WCHAR* inSrc );
  41. extern errno_t strncat_s( char* ioDest, size_t inDestBufferSize, const char* inSrc, size_t inCount );
  42. extern errno_t wcsncat_s( WCHAR* ioDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount );
  43. extern errno_t strcpy_s( char* outDest, size_t inDestBufferSize, const char* inSrc );
  44. extern errno_t wcscpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc );
  45. extern errno_t strncpy_s( char* outDest, size_t inDestBufferSize, const char* inSrc, size_t inCount );
  46. extern errno_t wcsncpy_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inSrc, size_t inCount );
  47. extern char* strtok_s( char* inString, const char* inControl, char** ioContext );
  48. extern WCHAR* wcstok_s( WCHAR* inString, const WCHAR* inControl, WCHAR** ioContext );
  49. // strnlen is not required unless the source string is completely untrusted (e.g. anonymous input on a website)
  50. #ifndef SUPPRESS_STRNLEN
  51. extern size_t strnlen( const char* inString, size_t inMaxSize );
  52. extern size_t wcsnlen( const WCHAR* inString, size_t inMaxSize );
  53. #endif
  54. extern errno_t _itoa_s( int inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
  55. extern errno_t _itow_s( int inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );
  56. extern errno_t _ltoa_s( long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
  57. extern errno_t _ltow_s( long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );
  58. extern errno_t _ultoa_s( unsigned long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
  59. extern errno_t _ultow_s( unsigned long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );
  60. extern errno_t _i64toa_s( long long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
  61. extern errno_t _i64tow_s( long long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );
  62. extern errno_t _ui64toa_s( unsigned long long inValue, char* outBuffer, size_t inDestBufferSize, int inRadix );
  63. extern errno_t _ui64tow_s( unsigned long long inValue, WCHAR* outBuffer, size_t inDestBufferSize, int inRadix );
  64. extern errno_t _makepath_s( char* outDest, size_t inDestBufferSize, const char* inDrive, const char* inDirectory, const char* inFilename, const char* inExtension );
  65. extern errno_t _wmakepath_s( WCHAR* outDest, size_t inDestBufferSize, const WCHAR* inDrive, const WCHAR* inDirectory, const WCHAR* inFilename, const WCHAR* inExtension );
  66. extern errno_t _splitpath_s( const char* inPath, char* outDrive, size_t inDriveSize, char* outDirectory, size_t inDirectorySize, char* outFilename, size_t inFilenameSize, char* outExtension, size_t inExtensionSize );
  67. extern errno_t _wsplitpath_s( const WCHAR* inPath, WCHAR* outDrive, size_t inDriveSize, WCHAR* outDirectory, size_t inDirectorySize, WCHAR* outFilename, size_t inFilenameSize, WCHAR* outExtension, size_t inExtensionSize );
  68. extern int sprintf_s( char *string, size_t sizeInBytes, const char *format, ... );
  69. extern int swprintf_s( WCHAR *string, size_t sizeInWords, const WCHAR *format, ... );
  70. extern int _snprintf_s( char *string, size_t sizeInBytes, size_t count, const char *format, ... );
  71. extern int _snwprintf_s( WCHAR *string, size_t sizeInWords, size_t count, const WCHAR *format, ... );
  72. extern int _vsprintf_s( char* string, size_t sizeInBytes, const char* format, va_list arglist );
  73. extern int _vsnprintf_s( char* string, size_t sizeInBytes, size_t count, const char* format, va_list arglist );
  74. extern int _vswprintf_s( WCHAR* string, size_t sizeInWords, const WCHAR* format, va_list arglist );
  75. extern int _vsnwprintf_s( WCHAR* string, size_t sizeInWords, size_t count, const WCHAR* format, va_list arglist );
  76. extern int sscanf_s( const char *string, const char *format, ... );
  77. extern int swscanf_s( const WCHAR *string, const WCHAR *format, ... );
  78. extern int _snscanf_s( const char *string, size_t count, const char *format, ... );
  79. extern int _snwscanf_s( const WCHAR *string, size_t count, const WCHAR *format, ... );
  80. extern errno_t memcpy_s( void * dst, size_t sizeInBytes, const void * src, size_t count );
  81. extern errno_t memmove_s( void * dst, size_t sizeInBytes, const void * src, size_t count );
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* MBUSAFECRT_H */