LLVM OpenMP* Runtime Library
src
kmp_safe_c_api.h
1
2
//===----------------------------------------------------------------------===//
3
//
4
// The LLVM Compiler Infrastructure
5
//
6
// This file is dual licensed under the MIT and the University of Illinois Open
7
// Source Licenses. See LICENSE.txt for details.
8
//
9
//===----------------------------------------------------------------------===//
10
11
#ifndef KMP_SAFE_C_API_H
12
#define KMP_SAFE_C_API_H
13
14
// Replacement for banned C API
15
16
// Not every unsafe call listed here is handled now, but keeping everything
17
// in one place should be handy for future maintenance.
18
#if KMP_OS_WINDOWS
19
20
#define RSIZE_MAX_STR (4UL << 10) // 4KB
21
22
// _malloca was suggested, but it is not a drop-in replacement for _alloca
23
#define KMP_ALLOCA _alloca
24
25
#define KMP_MEMCPY_S memcpy_s
26
#define KMP_SNPRINTF sprintf_s
27
#define KMP_SSCANF sscanf_s
28
#define KMP_STRCPY_S strcpy_s
29
#define KMP_STRNCPY_S strncpy_s
30
31
// Use this only when buffer size is unknown
32
#define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
33
34
#define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
35
36
// Use this only when buffer size is unknown
37
#define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
38
39
// _TRUNCATE insures buffer size > max string to print.
40
#define KMP_VSNPRINTF(dst, cnt, fmt, arg) \
41
vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
42
43
#else // KMP_OS_WINDOWS
44
45
// For now, these macros use the existing API.
46
47
#define KMP_ALLOCA alloca
48
#define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
49
#define KMP_SNPRINTF snprintf
50
#define KMP_SSCANF sscanf
51
#define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
52
#define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
53
#define KMP_VSNPRINTF vsnprintf
54
#define KMP_STRNCPY strncpy
55
#define KMP_STRLEN strlen
56
#define KMP_MEMCPY memcpy
57
58
#endif // KMP_OS_WINDOWS
59
60
#endif // KMP_SAFE_C_API_H
Generated by
1.8.13