LLVM OpenMP* Runtime Library
Main Page
Modules
Classes
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
12
#ifndef KMP_SAFE_C_API_H
13
#define KMP_SAFE_C_API_H
14
15
//
16
// Replacement for banned C API
17
//
18
19
// Not every unsafe call listed here is handled now, but keeping everything
20
// in one place should be handy for future maintenance.
21
#if KMP_OS_WINDOWS
22
23
# define RSIZE_MAX_STR ( 4UL << 10 ) // 4KB
24
25
// _malloca was suggested, but it is not a drop-in replacement for _alloca
26
# define KMP_ALLOCA _alloca
27
28
# define KMP_MEMCPY_S memcpy_s
29
# define KMP_SNPRINTF sprintf_s
30
# define KMP_SSCANF sscanf_s
31
# define KMP_STRCPY_S strcpy_s
32
# define KMP_STRNCPY_S strncpy_s
33
34
// Use this only when buffer size is unknown
35
# define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
36
37
# define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
38
39
// Use this only when buffer size is unknown
40
# define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
41
42
// _TRUNCATE insures buffer size > max string to print.
43
# define KMP_VSNPRINTF(dst, cnt, fmt, arg) vsnprintf_s(dst, cnt, _TRUNCATE, fmt, arg)
44
45
#else // KMP_OS_WINDOWS
46
47
// For now, these macros use the existing API.
48
49
# define KMP_ALLOCA alloca
50
# define KMP_MEMCPY_S(dst, bsz, src, cnt) memcpy(dst, src, cnt)
51
# define KMP_SNPRINTF snprintf
52
# define KMP_SSCANF sscanf
53
# define KMP_STRCPY_S(dst, bsz, src) strcpy(dst, src)
54
# define KMP_STRNCPY_S(dst, bsz, src, cnt) strncpy(dst, src, cnt)
55
# define KMP_VSNPRINTF vsnprintf
56
# define KMP_STRNCPY strncpy
57
# define KMP_STRLEN strlen
58
# define KMP_MEMCPY memcpy
59
60
#endif // KMP_OS_WINDOWS
61
62
#endif // KMP_SAFE_C_API_H
Generated by
1.8.9.1