forked from nmap/npcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrsafe.h
126 lines (100 loc) · 5.3 KB
/
strsafe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***********************IMPORTANT NPCAP LICENSE TERMS***********************
* *
* Npcap is a Windows packet sniffing driver and library and is copyright *
* (c) 2013-2016 by Insecure.Com LLC ("The Nmap Project"). All rights *
* reserved. *
* *
* Even though Npcap source code is publicly available for review, it is *
* not open source software and my not be redistributed or incorporated *
* into other software without special permission from the Nmap Project. *
* We fund the Npcap project by selling a commercial license which allows *
* companies to redistribute Npcap with their products and also provides *
* for support, warranty, and indemnification rights. For details on *
* obtaining such a license, please contact: *
* *
* *
* Free and open source software producers are also welcome to contact us *
* for redistribution requests. However, we normally recommend that such *
* authors instead ask your users to download and install Npcap *
* themselves. *
* *
* Since the Npcap source code is available for download and review, *
* users sometimes contribute code patches to fix bugs or add new *
* features. By sending these changes to the Nmap Project (including *
* through direct email or our mailing lists or submitting pull requests *
* through our source code repository), it is understood unless you *
* specify otherwise that you are offering the Nmap Project the *
* unlimited, non-exclusive right to reuse, modify, and relicence your *
* code contribution so that we may (but are not obligated to) *
* incorporate it into Npcap. If you wish to specify special license *
* conditions or restrictions on your contributions, just say so when you *
* send them. *
* *
* This software is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* Other copyright notices and attribution may appear below this license *
* header. We have kept those for attribution purposes, but any license *
* terms granted by those notices apply only to their original work, and *
* not to any changes made by the Nmap Project or to this entire file. *
* *
* This header summarizes a few important aspects of the Npcap license, *
* but is not a substitute for the full Npcap license agreement, which is *
* in the LICENSE file included with Npcap and also available at *
* https://github.com/nmap/npcap/blob/master/LICENSE. *
* *
***************************************************************************/
#ifndef __STRSAFE_GCC__383773443
#define __STRSAFE_GCC__383773443
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#ifdef _MSC_VER
#error Trying to use strsafe.h for GCC within Visual Studio
#endif
static int vsnprintf(char *buffer,size_t count, const char *format, va_list argptr )
{
return vsprintf(buffer, format, argptr);
}
static void StringCchPrintfA(char *pszDest,size_t cbDest, char *pszFormat, ...)
{
va_list marker;
va_start( marker, pszFormat ); /* Initialize variable arguments. */
if (cbDest == 0 || pszDest == NULL || pszFormat == NULL)
return;
pszDest[cbDest - 1] = '\0';
vsnprintf(pszDest, cbDest - 1, pszFormat, marker);
va_end(marker);
}
static void StringCchPrintfW( WCHAR *pszDest,size_t cbDest, WCHAR *pszFormat, ...)
{
va_list marker;
va_start( marker, pszFormat ); /* Initialize variable arguments. */
if (cbDest == 0 || pszDest == NULL || pszFormat == NULL)
return;
pszDest[cbDest - 1] = L'\0';
_vsnwprintf(pszDest, cbDest - 1, pszFormat, marker);
va_end(marker);
}
static void StringCchCopyA(char *pszDest,size_t cbDest, const char* pszSrc)
{
if (cbDest == 0 || pszDest == NULL || pszSrc == NULL)
return;
pszDest[cbDest - 1] = '\0';
strncpy(pszDest, pszSrc, cbDest - 1);
}
static void StringCchCatA(char* pszDest, size_t cbDest,const char* pszSrc)
{
if (cbDest == 0 || pszDest == NULL || pszSrc == NULL)
return;
pszDest[cbDest - 1] = '\0';
strncat(pszDest, pszSrc, cbDest - 1);
}
#ifdef UNICODE
#define StringCchPrintf StringCchPrintfW
#else
#define StringCchPrintf StringCchPrintfA
#endif
#endif