Last active
September 23, 2024 11:57
-
-
Save RGBA-CRT/c1d008df8da2e31e88cb04d61500603c to your computer and use it in GitHub Desktop.
MSVC safe func replace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef _MSC_VER | |
| #define fopen_s(fd, name, mode) ((*fd = fopen(name, mode)) ? errno : errno) | |
| #define _wfopen_s(fd, name, mode) ((*fd = _wfopen(name, mode)) ? errno : errno) | |
| #define _snprintf_s(buf, bsize, count, format, ...) (snprintf(buf, (bsize<count) ? bsize : count, format, __VA_ARGS__)) | |
| #define sscanf_s sscanf // 注意:文字列系は文字列バッファサイズを外す必要あり | |
| // not tested. todo: return value | |
| #define strcpy_s(str1, str1len, str2) do{strncpy(str1,str2,str1len); ((char*)str1)[str1len-1]='\0';}while(0) | |
| #define strncpy_s(str1, str1len, str2, str2len) strcpy_s(str1,((str1len<(str2len+1))?str1len:(str2len+1)), str2) | |
| #define wcsncpy_s(str1, str1len, str2, str2len) wcsncpy(str1,((str1len<(str2len+1))?str1len:(str2len+1)), str2) | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment