Intel® OpenMP* Runtime Library
Main Page
Modules
Classes
src
kmp_safe_c_api.h
1
/* <copyright>
2
Copyright (c) 1997-2015 Intel Corporation. All Rights Reserved.
3
4
Redistribution and use in source and binary forms, with or without
5
modification, are permitted provided that the following conditions
6
are met:
7
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in the
12
documentation and/or other materials provided with the distribution.
13
* Neither the name of Intel Corporation nor the names of its
14
contributors may be used to endorse or promote products derived
15
from this software without specific prior written permission.
16
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
</copyright> */
30
31
#ifndef KMP_SAFE_C_API_H
32
#define KMP_SAFE_C_API_H
33
34
//
35
// Replacement for banned C API
36
//
37
38
// Not every unsafe call listed here is handled now, but keeping everything
39
// in one place should be handy for future maintenance.
40
#if KMP_OS_WINDOWS
41
42
# define RSIZE_MAX_STR ( 4UL << 10 ) // 4KB
43
44
// _malloca was suggested, but it is not a drop-in replacement for _alloca
45
# define KMP_ALLOCA _alloca
46
47
# define KMP_MEMCPY_S memcpy_s
48
# define KMP_SNPRINTF sprintf_s
49
# define KMP_SSCANF sscanf_s
50
# define KMP_STRCPY_S strcpy_s
51
# define KMP_STRNCPY_S strncpy_s
52
53
// Use this only when buffer size is unknown
54
# define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
55
56
# define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
57
58
// Use this only when buffer size is unknown
59
# define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
60
61
// _TRUNCATE insures buffer size > max string to print.
62
# define KMP_VSNPRINTF(dst, cnt, fmt, arg) vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
63
64
#else // KMP_OS_WINDOWS
65
66
// For now, these macros use the existing API.
67
68
# define KMP_ALLOCA alloca
69
# define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
70
# define KMP_SNPRINTF snprintf
71
# define KMP_SSCANF sscanf
72
# define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
73
# define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
74
# define KMP_VSNPRINTF vsnprintf
75
# define KMP_STRNCPY strncpy
76
# define KMP_STRLEN strlen
77
# define KMP_MEMCPY memcpy
78
79
#endif // KMP_OS_WINDOWS
80
81
#endif // KMP_SAFE_C_API_H
Generated by
1.8.9.1