1 /******************************************************************
2 *                                                                                                            *
3 *  strsafe.h -- This module defines safer C library string             *
4 *                         routine replacements. These are meant to make C     *
5 *                         a bit more safe in reference to security and          *
6 *                         robustness                                                                  *
7 *                                                                                                            *
8 *  Copyright (c) Microsoft Corp.  All rights reserved.                    *
9 *                                                                                                            *
10 ******************************************************************/
11 #ifndef _STRSAFE_H_INCLUDED_
12 #define _STRSAFE_H_INCLUDED_
13 #if (_MSC_VER > 1000)
14 #pragma once
15 #endif
16
17 #include <stdio.h>                // for _vsnprintf, _vsnwprintf, getc, getwc
18 #include <string.h>               // for memset
19 #include <stdarg.h>               // for va_start, etc.
20 #include <specstrings.h>      // for __in, etc.
21
22 #if !defined(_W64)
23 #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && (_MSC_VER >= 1300)
24 #define _W64 __w64
25 #else
26 #define _W64
27 #endif
28 #endif
29
30 #if defined(_M_MRX000) || defined(_M_ALPHA) || defined(_M_PPC) || defined(_M_IA64) || defined(_M_AMD64)
31 #define ALIGNMENT_MACHINE
32 #define UNALIGNED __unaligned
33 #if defined(_WIN64)
34 #define UNALIGNED64 __unaligned
35 #else
36 #define UNALIGNED64
37 #endif
38 #else
39 #undef ALIGNMENT_MACHINE
40 #define UNALIGNED
41 #define UNALIGNED64
42 #endif
43
44 // typedefs
45 #ifdef  _WIN64
46 typedef unsigned __int64      size_t;
47 #else
48 typedef _W64 unsigned int     size_t;
49 #endif
50
51 #ifndef _HRESULT_DEFINED
52 #define _HRESULT_DEFINED
53 typedef __success(return >= 0) long HRESULT;
54 #endif
55
56 typedef unsigned long DWORD;
57
58
59 // macros
60 #define SUCCEEDED(hr)     (((HRESULT)(hr)) >= 0)
61 #define FAILED(hr)          (((HRESULT)(hr)) < 0)
62
63 #define S_OK                    ((HRESULT)0L)
64
65 #ifndef SORTPP_PASS
66 // compiletime asserts (failure results in error C2118: negative subscript)
67 #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
68 #else
69 #define C_ASSERT(e)
70 #endif
71
72 #ifdef __cplusplus
73 #define EXTERN_C      extern "C"
74 #else
75 #define EXTERN_C      extern
76 #endif
77
78 // use the new secure crt functions if available
79 #ifndef STRSAFE_USE_SECURE_CRT
80 #if defined(__GOT_SECURE_LIB__) && (__GOT_SECURE_LIB__ >= 200402L)
81 #define STRSAFE_USE_SECURE_CRT 0
82 #else
83 #define STRSAFE_USE_SECURE_CRT 0
84 #endif
85 #endif  // !STRSAFE_USE_SECURE_CRT
86
87 #ifdef _M_CEE_PURE
88 #define STRSAFEAPI          __inline HRESULT __clrcall
89 #else
90 #define STRSAFEAPI          __inline HRESULT __stdcall
91 #endif
92
93 #if defined(STRSAFE_LIB_IMPL) || defined(STRSAFE_LIB)
94 #define STRSAFEWORKERAPI      EXTERN_C HRESULT __stdcall 
95 #else
96 #define STRSAFEWORKERAPI      static STRSAFEAPI
97 #endif
98
99 #ifdef STRSAFE_LOCALE_FUNCTIONS
100 #if defined(STRSAFE_LOCALE_LIB_IMPL) || defined(STRSAFE_LIB)
101 #define STRSAFELOCALEWORKERAPI  EXTERN_C HRESULT __stdcall 
102 #else
103 #define STRSAFELOCALEWORKERAPI  static STRSAFEAPI
104 #endif
105 #endif // STRSAFE_LOCALE_FUNCTIONS
106
107 #if defined(STRSAFE_LIB)
108 #pragma comment(lib, "strsafe.lib")
109 #endif
110
111 // The user can request no "Cb" or no "Cch" fuctions, but not both
112 #if defined(STRSAFE_NO_CB_FUNCTIONS) && defined(STRSAFE_NO_CCH_FUNCTIONS)
113 #error cannot specify both STRSAFE_NO_CB_FUNCTIONS and STRSAFE_NO_CCH_FUNCTIONS !!
Lines 114 ... 9521 are skipped.
9522 #pragma deprecated(_getws)
9523
9524 // Then all the windows.h names
9525 #undef lstrcpy
9526 #undef lstrcat
9527 #undef wsprintf
9528 #undef wvsprintf
9529 #pragma deprecated(lstrcpy)
9530 #pragma deprecated(lstrcat)
9531 #pragma deprecated(wsprintf)
9532 #pragma deprecated(wvsprintf)
9533 #ifdef UNICODE
9534 #define lstrcpy      lstrcpyW
9535 #define lstrcat      lstrcatW
9536 #define wsprintf     wsprintfW
9537 #define wvsprintf  wvsprintfW
9538 #else
9539 #define lstrcpy      lstrcpyA
9540 #define lstrcat      lstrcatA
9541 #define wsprintf     wsprintfA
9542 #define wvsprintf  wvsprintfA
9543 #endif
9544
9545 // Then the shlwapi names
9546 #undef StrCpyA
9547 #undef StrCpy
9548 #undef StrCatA
9549 #undef StrCat
9550 #undef StrNCat
9551 #undef StrCatN
9552 #pragma deprecated(StrCpyA)
9553 #pragma deprecated(StrCatA)
9554 #pragma deprecated(StrCatN)
9555 #pragma deprecated(StrCpy)
9556 #pragma deprecated(StrCat)
9557 #pragma deprecated(StrNCat)
9558 #define StrCpyA lstrcpyA
9559 #define StrCatA lstrcatA
9560 #define StrCatN StrNCat
9561 #ifdef UNICODE
9562 #define StrCpy  StrCpyW
9563 #define StrCat  StrCatW
9564 #define StrNCat StrNCatW
9565 #else
9566 #define StrCpy  lstrcpyA
9567 #define StrCat  lstrcatA
9568 #define StrNCat StrNCatA
9569 #endif
9570
9571 #undef _tcscpy
9572 #undef _ftcscpy
9573 #undef _tcscat
9574 #undef _ftcscat
9575 #undef _stprintf
9576 #undef _sntprintf
9577 #undef _vstprintf
9578 #undef _vsntprintf
9579 #undef _getts
9580 #pragma deprecated(_tcscpy)
9581 #pragma deprecated(_ftcscpy)
9582 #pragma deprecated(_tcscat)
9583 #pragma deprecated(_ftcscat)
9584 #pragma deprecated(_stprintf)
9585 #pragma deprecated(_sntprintf)
9586 #pragma deprecated(_vstprintf)
9587 #pragma deprecated(_vsntprintf)
9588 #pragma deprecated(_getts)
9589 #ifdef _UNICODE
9590 #define _tcscpy        wcscpy
9591 #define _ftcscpy      wcscpy
9592 #define _tcscat        wcscat
9593 #define _ftcscat      wcscat
9594 #define _stprintf     swprintf
9595 #define _sntprintf  _snwprintf
9596 #define _vstprintf  vswprintf
9597 #define _vsntprintf _vsnwprintf
9598 #define _getts          _getws
9599 #else
9600 #define _tcscpy        strcpy
9601 #define _ftcscpy      strcpy
9602 #define _tcscat        strcat
9603 #define _ftcscat      strcat
9604 #define _stprintf     sprintf
9605 #define _sntprintf  _snprintf
9606 #define _vstprintf  vsprintf
9607 #define _vsntprintf _vsnprintf
9608 #define _getts          gets
9609 #endif
9610
9611 #else // DEPRECATE_SUPPORTED
9612
9613 #undef strcpy
9614 #define strcpy          strcpy_instead_use_StringCchCopyA_or_StringCbCopyA;
9615
9616 #undef wcscpy
9617 #define wcscpy          wcscpy_instead_use_StringCchCopyW_or_StringCbCopyW;
9618
9619 #undef strcat
9620 #define strcat          strcat_instead_use_StringCchCatA_or_StringCbCatA;
9621
9622 #undef wcscat
9623 #define wcscat          wcscat_instead_use_StringCchCatW_or_StringCbCatW;
9624
9625 #undef sprintf
9626 #define sprintf        sprintf_instead_use_StringCchPrintfA_or_StringCbPrintfA;
9627
9628 #undef swprintf
9629 #define swprintf      swprintf_instead_use_StringCchPrintfW_or_StringCbPrintfW;
9630
9631 #undef vsprintf
9632 #define vsprintf      vsprintf_instead_use_StringCchVPrintfA_or_StringCbVPrintfA;
9633
9634 #undef vswprintf
9635 #define vswprintf     vswprintf_instead_use_StringCchVPrintfW_or_StringCbVPrintfW;
9636
9637 #undef _snprintf
9638 #define _snprintf     _snprintf_instead_use_StringCchPrintfA_or_StringCbPrintfA;
9639
9640 #undef _snwprintf
9641 #define _snwprintf  _snwprintf_instead_use_StringCchPrintfW_or_StringCbPrintfW;
9642
9643 #undef _vsnprintf
9644 #define _vsnprintf  _vsnprintf_instead_use_StringCchVPrintfA_or_StringCbVPrintfA;
9645
9646 #undef _vsnwprintf
9647 #define _vsnwprintf _vsnwprintf_instead_use_StringCchVPrintfW_or_StringCbVPrintfW;
9648
9649 #undef strcpyA
9650 #define strcpyA        strcpyA_instead_use_StringCchCopyA_or_StringCbCopyA;
9651
9652 #undef strcpyW
9653 #define strcpyW        strcpyW_instead_use_StringCchCopyW_or_StringCbCopyW;
9654
9655 #undef lstrcpy
9656 #define lstrcpy        lstrcpy_instead_use_StringCchCopy_or_StringCbCopy;
9657
9658 #undef lstrcpyA
9659 #define lstrcpyA      lstrcpyA_instead_use_StringCchCopyA_or_StringCbCopyA;
9660
9661 #undef lstrcpyW
9662 #define lstrcpyW      lstrcpyW_instead_use_StringCchCopyW_or_StringCbCopyW;
9663
9664 #undef StrCpy
9665 #define StrCpy          StrCpy_instead_use_StringCchCopy_or_StringCbCopy;
9666
9667 #undef StrCpyA
9668 #define StrCpyA        StrCpyA_instead_use_StringCchCopyA_or_StringCbCopyA;
9669
9670 #undef StrCpyW
9671 #define StrCpyW        StrCpyW_instead_use_StringCchCopyW_or_StringCbCopyW;
9672
9673 #undef _tcscpy
9674 #define _tcscpy        _tcscpy_instead_use_StringCchCopy_or_StringCbCopy;
9675
9676 #undef _ftcscpy
9677 #define _ftcscpy      _ftcscpy_instead_use_StringCchCopy_or_StringCbCopy;
9678
9679 #undef lstrcat
9680 #define lstrcat        lstrcat_instead_use_StringCchCat_or_StringCbCat;
9681
9682 #undef lstrcatA
9683 #define lstrcatA      lstrcatA_instead_use_StringCchCatA_or_StringCbCatA;
9684
9685 #undef lstrcatW
9686 #define lstrcatW      lstrcatW_instead_use_StringCchCatW_or_StringCbCatW;
9687
9688 #undef StrCat
9689 #define StrCat          StrCat_instead_use_StringCchCat_or_StringCbCat;
9690
9691 #undef StrCatA
9692 #define StrCatA        StrCatA_instead_use_StringCchCatA_or_StringCbCatA;
9693
9694 #undef StrCatW
9695 #define StrCatW        StrCatW_instead_use_StringCchCatW_or_StringCbCatW;
9696
9697 #undef StrNCat
9698 #define StrNCat        StrNCat_instead_use_StringCchCatN_or_StringCbCatN;
9699
9700 #undef StrNCatA
9701 #define StrNCatA      StrNCatA_instead_use_StringCchCatNA_or_StringCbCatNA;
9702
9703 #undef StrNCatW
9704 #define StrNCatW      StrNCatW_instead_use_StringCchCatNW_or_StringCbCatNW;
9705
9706 #undef StrCatN
9707 #define StrCatN        StrCatN_instead_use_StringCchCatN_or_StringCbCatN;
9708
9709 #undef StrCatNA
9710 #define StrCatNA      StrCatNA_instead_use_StringCchCatNA_or_StringCbCatNA;
9711
9712 #undef StrCatNW
9713 #define StrCatNW      StrCatNW_instead_use_StringCchCatNW_or_StringCbCatNW;
9714
9715 #undef _tcscat
9716 #define _tcscat        _tcscat_instead_use_StringCchCat_or_StringCbCat;
9717
9718 #undef _ftcscat
9719 #define _ftcscat      _ftcscat_instead_use_StringCchCat_or_StringCbCat;
9720
9721 #undef wsprintf
9722 #define wsprintf      wsprintf_instead_use_StringCchPrintf_or_StringCbPrintf;
9723
9724 #undef wsprintfA
9725 #define wsprintfA     wsprintfA_instead_use_StringCchPrintfA_or_StringCbPrintfA;
9726
9727 #undef wsprintfW
9728 #define wsprintfW     wsprintfW_instead_use_StringCchPrintfW_or_StringCbPrintfW;
9729
9730 #undef wvsprintf
9731 #define wvsprintf     wvsprintf_instead_use_StringCchVPrintf_or_StringCbVPrintf;
9732
9733 #undef wvsprintfA
9734 #define wvsprintfA  wvsprintfA_instead_use_StringCchVPrintfA_or_StringCbVPrintfA;
9735
9736 #undef wvsprintfW
9737 #define wvsprintfW  wvsprintfW_instead_use_StringCchVPrintfW_or_StringCbVPrintfW;
9738
9739 #undef _vstprintf
9740 #define _vstprintf  _vstprintf_instead_use_StringCchVPrintf_or_StringCbVPrintf;
9741
9742 #undef _vsntprintf
9743 #define _vsntprintf _vsntprintf_instead_use_StringCchVPrintf_or_StringCbVPrintf;
9744
9745 #undef _stprintf
9746 #define _stprintf     _stprintf_instead_use_StringCchPrintf_or_StringCbPrintf;
9747
9748 #undef _sntprintf
9749 #define _sntprintf  _sntprintf_instead_use_StringCchPrintf_or_StringCbPrintf;
9750
9751 #undef _getts
9752 #define _getts          _getts_instead_use_StringCchGets_or_StringCbGets;
9753
9754 #undef gets
9755 #define gets             _gets_instead_use_StringCchGetsA_or_StringCbGetsA;
9756
9757 #undef _getws
9758 #define _getws          _getws_instead_use_StringCchGetsW_or_StringCbGetsW;
9759
9760 #endif  // DEPRECATE_SUPPORTED
9761 #endif  // !STRSAFE_NO_DEPRECATE
9762
9763 #pragma warning(pop)
9764
9765 #endif  // _STRSAFE_H_INCLUDED_
9766
9767