You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

securec.h 29 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
  17. #define __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27
  18. #include "securectype.h"
  19. #include <stdarg.h>
  20. #ifndef SECUREC_HAVE_ERRNO_H
  21. #if SECUREC_IN_KERNEL
  22. #define SECUREC_HAVE_ERRNO_H 0
  23. #else
  24. #define SECUREC_HAVE_ERRNO_H 1
  25. #endif
  26. #endif
  27. /* EINVAL ERANGE may defined in errno.h */
  28. #if SECUREC_HAVE_ERRNO_H
  29. #include <errno.h>
  30. #endif
  31. /* define error code */
  32. #if defined(SECUREC_NEED_ERRNO_TYPE) || !defined(__STDC_WANT_LIB_EXT1__) || \
  33. (defined(__STDC_WANT_LIB_EXT1__) && (__STDC_WANT_LIB_EXT1__ == 0))
  34. #ifndef SECUREC_DEFINED_ERRNO_TYPE
  35. #define SECUREC_DEFINED_ERRNO_TYPE
  36. /* just check whether macrodefinition exists. */
  37. #ifndef errno_t
  38. typedef int errno_t;
  39. #endif
  40. #endif
  41. #endif
  42. /* success */
  43. #ifndef EOK
  44. #define EOK 0
  45. #endif
  46. #ifndef EINVAL
  47. /* The src buffer is not correct and destination buffer cant not be reset */
  48. #define EINVAL 22
  49. #endif
  50. #ifndef EINVAL_AND_RESET
  51. /* Once the error is detected, the dest buffer must be reseted! */
  52. #define EINVAL_AND_RESET (22 | 128)
  53. #endif
  54. #ifndef ERANGE
  55. /* The destination buffer is not long enough and destination buffer can not be reset */
  56. #define ERANGE 34
  57. #endif
  58. #ifndef ERANGE_AND_RESET
  59. /* Once the error is detected, the dest buffer must be reseted! */
  60. #define ERANGE_AND_RESET (34 | 128)
  61. #endif
  62. #ifndef EOVERLAP_AND_RESET
  63. /* Once the buffer overlap is detected, the dest buffer must be reseted! */
  64. #define EOVERLAP_AND_RESET (54 | 128)
  65. #endif
  66. /* if you need export the function of this library in Win32 dll, use __declspec(dllexport) */
  67. #ifndef SECUREC_API
  68. #if defined(SECUREC_DLL_EXPORT)
  69. #define SECUREC_API __declspec(dllexport)
  70. #elif defined(SECUREC_DLL_IMPORT)
  71. #define SECUREC_API __declspec(dllimport)
  72. #else
  73. /* Standardized function declaration . If a security function is declared in the your code,
  74. * it may cause a compilation alarm,Please delete the security function you declared
  75. * Adding extern under windows will cause the system to have inline functions to expand,
  76. * so do not add the extern in default
  77. */
  78. #if defined(_MSC_VER)
  79. #define SECUREC_API
  80. #else
  81. #define SECUREC_API extern
  82. #endif
  83. #endif
  84. #endif
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. /*
  89. * Description: The GetHwSecureCVersion function get SecureC Version string and version number.
  90. * Parameter: verNumber - to store version number
  91. * Return: version string
  92. */
  93. SECUREC_API const char *GetHwSecureCVersion(unsigned short *verNumber);
  94. #if SECUREC_ENABLE_MEMSET
  95. /*
  96. * Description: The memset_s function copies the value of c (converted to an unsigned char) into each of
  97. * the first count characters of the object pointed to by dest.
  98. * Parameter: dest - destination address
  99. * Parameter: destMax -The maximum length of destination buffer
  100. * Parameter: c - the value to be copied
  101. * Parameter: count -copies fisrt count characters of dest
  102. * Return: EOK if there was no runtime-constraint violation
  103. */
  104. SECUREC_API errno_t memset_s(void *dest, size_t destMax, int c, size_t count);
  105. #endif
  106. #ifndef SECUREC_ONLY_DECLARE_MEMSET
  107. #define SECUREC_ONLY_DECLARE_MEMSET 0
  108. #endif
  109. #if SECUREC_ONLY_DECLARE_MEMSET == 0
  110. #if SECUREC_ENABLE_MEMMOVE
  111. /*
  112. * Description: The memmove_s function copies n characters from the object pointed to by src
  113. * into the object pointed to by dest.
  114. * Parameter: dest - destination address
  115. * Parameter: destMax -The maximum length of destination buffer
  116. * Parameter: src -source address
  117. * Parameter: count -copies count wide characters from the src
  118. * Return: EOK if there was no runtime-constraint violation
  119. */
  120. SECUREC_API errno_t memmove_s(void *dest, size_t destMax, const void *src, size_t count);
  121. #endif
  122. #if SECUREC_ENABLE_MEMCPY
  123. /*
  124. * Description: The memcpy_s function copies n characters from the object pointed to
  125. * by src into the object pointed to by dest.
  126. * Parameter: dest - destination address
  127. * Parameter: destMax -The maximum length of destination buffer
  128. * Parameter: src -source address
  129. * Parameter: count -copies count characters from the src
  130. * Return: EOK if there was no runtime-constraint violation
  131. */
  132. SECUREC_API errno_t memcpy_s(void *dest, size_t destMax, const void *src, size_t count);
  133. #endif
  134. #if SECUREC_ENABLE_STRCPY
  135. /*
  136. * Description: The strcpy_s function copies the string pointed to by strSrc (including
  137. * the terminating null character) into the array pointed to by strDest
  138. * Parameter: strDest - destination address
  139. * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
  140. * Parameter: strSrc -source address
  141. * Return: EOK if there was no runtime-constraint violation
  142. */
  143. SECUREC_API errno_t strcpy_s(char *strDest, size_t destMax, const char *strSrc);
  144. #endif
  145. #if SECUREC_ENABLE_STRNCPY
  146. /*
  147. * Description: The strncpy_s function copies not more than n successive characters (not including
  148. * the terminating null character)
  149. * from the array pointed to by strSrc to the array pointed to by strDest
  150. * Parameter: strDest - destination address
  151. * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
  152. * Parameter: strSrc -source address
  153. * Parameter: count -copies count characters from the src
  154. * Return: EOK if there was no runtime-constraint violation
  155. */
  156. SECUREC_API errno_t strncpy_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
  157. #endif
  158. #if SECUREC_ENABLE_STRCAT
  159. /*
  160. * Description: The strcat_s function appends a copy of the string pointed to by strSrc (including
  161. * the terminating null character)
  162. * to the end of the string pointed to by strDest
  163. * Parameter: strDest - destination address
  164. * Parameter: destMax -The maximum length of destination buffer(including the terminating null wide character)
  165. * Parameter: strSrc -source address
  166. * Return: EOK if there was no runtime-constraint violation
  167. */
  168. SECUREC_API errno_t strcat_s(char *strDest, size_t destMax, const char *strSrc);
  169. #endif
  170. #if SECUREC_ENABLE_STRNCAT
  171. /*
  172. * Description: The strncat_s function appends not more than n successive characters (not including
  173. * the terminating null character)
  174. * from the array pointed to by strSrc to the end of the string pointed to by strDest.
  175. * Parameter: strDest - destination address
  176. * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
  177. * Parameter: strSrc -source address
  178. * Parameter: count -copies count characters from the src
  179. * Return: EOK if there was no runtime-constraint violation
  180. */
  181. SECUREC_API errno_t strncat_s(char *strDest, size_t destMax, const char *strSrc, size_t count);
  182. #endif
  183. #if SECUREC_ENABLE_VSPRINTF
  184. /*
  185. * Description: The vsprintf_s function is equivalent to the vsprintf function except for the Parameter: destMax
  186. * and the explicit runtime-constraints violation
  187. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  188. * Parameter: destMax - The maximum length of destination buffer(including the terminating null wide characte)
  189. * Parameter: format - fromat string
  190. * Parameter: argList - instead of a variable number of arguments
  191. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  192. * If an error occurred Return: -1.
  193. */
  194. SECUREC_API int vsprintf_s(char *strDest, size_t destMax, const char *format,
  195. va_list argList) SECUREC_ATTRIBUTE(3, 0);
  196. #endif
  197. #if SECUREC_ENABLE_SPRINTF
  198. /*
  199. * Description: The sprintf_s function is equivalent to the sprintf function except for the Parameter: destMax
  200. * and the explicit runtime-constraints violation
  201. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  202. * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
  203. * Parameter: format - fromat string
  204. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  205. * If an error occurred Return: -1.
  206. */
  207. SECUREC_API int sprintf_s(char *strDest, size_t destMax, const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
  208. #endif
  209. #if SECUREC_ENABLE_VSNPRINTF
  210. /*
  211. * Description: The vsnprintf_s function is equivalent to the vsnprintf function except for the Parameter:
  212. * destMax/count and the explicit runtime-constraints violation
  213. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  214. * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
  215. * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte ('\0'))
  216. * Parameter: format - fromat string
  217. * Parameter: argList - instead of a variable number of arguments
  218. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  219. * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
  220. */
  221. SECUREC_API int vsnprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
  222. va_list argList) SECUREC_ATTRIBUTE(4, 0);
  223. #endif
  224. #if SECUREC_ENABLE_SNPRINTF
  225. /*
  226. * Description: The snprintf_s function is equivalent to the snprintf function except for the Parameter:
  227. * destMax/count and the explicit runtime-constraints violation
  228. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  229. * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
  230. * Parameter: count - do not write more than count bytes to strDest(not including the terminating null byte ('\0'))
  231. * Parameter: format - fromat string
  232. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  233. * If an error occurred Return: -1.Pay special attention to returning -1 when truncation occurs
  234. */
  235. SECUREC_API int snprintf_s(char *strDest, size_t destMax, size_t count, const char *format,
  236. ...) SECUREC_ATTRIBUTE(4, 5);
  237. #endif
  238. #if SECUREC_SNPRINTF_TRUNCATED
  239. /*
  240. * Description: The vsnprintf_truncated_s function is equivalent to the vsnprintf_s function except
  241. * no count Parameter: and Return: value
  242. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  243. * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
  244. * Parameter: format - fromat string
  245. * Parameter: argList - instead of a variable number of arguments
  246. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  247. * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
  248. */
  249. SECUREC_API int vsnprintf_truncated_s(char *strDest, size_t destMax, const char *format,
  250. va_list argList) SECUREC_ATTRIBUTE(3, 0);
  251. /*
  252. * Description: The snprintf_truncated_s function is equivalent to the snprintf_2 function except
  253. * no count Parameter: and Return: value
  254. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  255. * Parameter: destMax - The maximum length of destination buffer(including the terminating null byte ('\0'))
  256. * Parameter: format - fromat string
  257. * Return: the number of characters printed(not including the terminating null byte ('\0')),
  258. * If an error occurred Return: -1.Pay special attention to returning destMax - 1 when truncation occurs
  259. */
  260. SECUREC_API int snprintf_truncated_s(char *strDest, size_t destMax,
  261. const char *format, ...) SECUREC_ATTRIBUTE(3, 4);
  262. #endif
  263. #if SECUREC_ENABLE_SCANF
  264. /*
  265. * Description: The scanf_s function is equivalent to fscanf_s with the argument stdin
  266. * interposed before the arguments to scanf_s
  267. * Parameter: format - fromat string
  268. * Return: the number of input items assigned, If an error occurred Return: -1.
  269. */
  270. SECUREC_API int scanf_s(const char *format, ...);
  271. #endif
  272. #if SECUREC_ENABLE_VSCANF
  273. /*
  274. * Description: The vscanf_s function is equivalent to scanf_s, with the variable argument list replaced by argList
  275. * Parameter: format - fromat string
  276. * Parameter: argList - instead of a variable number of arguments
  277. * Return: the number of input items assigned, If an error occurred Return: -1.
  278. */
  279. SECUREC_API int vscanf_s(const char *format, va_list argList);
  280. #endif
  281. #if SECUREC_ENABLE_SSCANF
  282. /*
  283. * Description: The sscanf_s function is equivalent to fscanf_s, except that input is obtained from a
  284. * string (specified by the argument buffer) rather than from a stream
  285. * Parameter: buffer - read character from buffer
  286. * Parameter: format - fromat string
  287. * Return: the number of input items assigned, If an error occurred Return: -1.
  288. */
  289. SECUREC_API int sscanf_s(const char *buffer, const char *format, ...);
  290. #endif
  291. #if SECUREC_ENABLE_VSSCANF
  292. /*
  293. * Description: The vsscanf_s function is equivalent to sscanf_s, with the variable argument list
  294. * replaced by argList
  295. * Parameter: buffer - read character from buffer
  296. * Parameter: format - fromat string
  297. * Parameter: argList - instead of a variable number of arguments
  298. * Return: the number of input items assigned, If an error occurred Return: -1.
  299. */
  300. SECUREC_API int vsscanf_s(const char *buffer, const char *format, va_list argList);
  301. #endif
  302. #if SECUREC_ENABLE_FSCANF
  303. /*
  304. * Description: The fscanf_s function is equivalent to fscanf except that the c, s, and [ conversion specifiers
  305. * apply to a pair of arguments (unless assignment suppression is indicated by a*)
  306. * Parameter: stream - stdio file stream
  307. * Parameter: format - fromat string
  308. * Return: the number of input items assigned, If an error occurred Return: -1.
  309. */
  310. SECUREC_API int fscanf_s(FILE *stream, const char *format, ...);
  311. #endif
  312. #if SECUREC_ENABLE_VFSCANF
  313. /*
  314. * Description: The vfscanf_s function is equivalent to fscanf_s, with the variable argument list
  315. * replaced by argList
  316. * Parameter: stream - stdio file stream
  317. * Parameter: format - fromat string
  318. * Parameter: argList - instead of a variable number of arguments
  319. * Return: the number of input items assigned, If an error occurred Return: -1.
  320. */
  321. SECUREC_API int vfscanf_s(FILE *stream, const char *format, va_list argList);
  322. #endif
  323. #if SECUREC_ENABLE_STRTOK
  324. /*
  325. * Description: The strtok_s function parses a string into a sequence of strToken,
  326. * replace all characters in strToken string that match to strDelimit set with 0.
  327. * On the first call to strtok_s the string to be parsed should be specified in strToken.
  328. * In each subsequent call that should parse the same string, strToken should be NULL
  329. * Parameter: strToken - the string to be delimited
  330. * Parameter: strDelimit -specifies a set of characters that delimit the tokens in the parsed string
  331. * Parameter: context -is a pointer to a char * variable that is used internally by strtok_s function
  332. * Return: On the first call returns the address of the first non \0 character, otherwise NULL is returned.
  333. * In subsequent calls, the strtoken is set to NULL, and the context set is the same as the previous call,
  334. * return NULL if the *context string length is equal 0, otherwise return *context.
  335. */
  336. SECUREC_API char *strtok_s(char *strToken, const char *strDelimit, char **context);
  337. #endif
  338. #if SECUREC_ENABLE_GETS && SECUREC_IN_KERNEL == 0
  339. /*
  340. * Description: The gets_s function reads at most one less than the number of characters specified
  341. * by destMax from the stream pointed to by stdin, into the array pointed to by buffer
  342. * Parameter: buffer - destination address
  343. * Parameter: destMax -The maximum length of destination buffer(including the terminating null character)
  344. * Return: buffer if there was no runtime-constraint violation,If an error occurred Return: NULL.
  345. */
  346. SECUREC_API char *gets_s(char *buffer, size_t destMax);
  347. #endif
  348. #if SECUREC_ENABLE_WCHAR_FUNC
  349. #if SECUREC_ENABLE_MEMCPY
  350. /*
  351. * Description: The wmemcpy_s function copies n successive wide characters from the object pointed to
  352. * by src into the object pointed to by dest.
  353. * Parameter: dest - destination address
  354. * Parameter: destMax -The maximum length of destination buffer
  355. * Parameter: src -source address
  356. * Parameter: count -copies count wide characters from the src
  357. * Return: EOK if there was no runtime-constraint violation
  358. */
  359. SECUREC_API errno_t wmemcpy_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
  360. #endif
  361. #if SECUREC_ENABLE_MEMMOVE
  362. /*
  363. * Description: The wmemmove_s function copies n successive wide characters from the object
  364. * pointed to by src into the object pointed to by dest.
  365. * Parameter: dest - destination address
  366. * Parameter: destMax -The maximum length of destination buffer
  367. * Parameter: src -source address
  368. * Parameter: count -copies count wide characters from the src
  369. * Return: EOK if there was no runtime-constraint violation
  370. */
  371. SECUREC_API errno_t wmemmove_s(wchar_t *dest, size_t destMax, const wchar_t *src, size_t count);
  372. #endif
  373. #if SECUREC_ENABLE_STRCPY
  374. /*
  375. * Description: The wcscpy_s function copies the wide string pointed to by strSrc (including theterminating
  376. * null wide character) into the array pointed to by strDest
  377. * Parameter: strDest - destination address
  378. * Parameter: destMax -The maximum length of destination buffer
  379. * Parameter: strSrc -source address
  380. * Return: EOK if there was no runtime-constraint violation
  381. */
  382. SECUREC_API errno_t wcscpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
  383. #endif
  384. #if SECUREC_ENABLE_STRNCPY
  385. /*
  386. * Description: The wcsncpy_s function copies not more than n successive wide characters (not including the
  387. * terminating null wide character) from the array pointed to by strSrc to the array pointed to by strDest
  388. * Parameter: strDest - destination address
  389. * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
  390. * Parameter: strSrc -source address
  391. * Parameter: count -copies count wide characters from the src
  392. * Return: EOK if there was no runtime-constraint violation
  393. */
  394. SECUREC_API errno_t wcsncpy_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
  395. #endif
  396. #if SECUREC_ENABLE_STRCAT
  397. /*
  398. * Description: The wcscat_s function appends a copy of the wide string pointed to by strSrc (including the
  399. * terminating null wide character) to the end of the wide string pointed to by strDest
  400. * Parameter: strDest - destination address
  401. * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
  402. * Parameter: strSrc -source address
  403. * Return: EOK if there was no runtime-constraint violation
  404. */
  405. SECUREC_API errno_t wcscat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc);
  406. #endif
  407. #if SECUREC_ENABLE_STRNCAT
  408. /*
  409. * Description: The wcsncat_s function appends not more than n successive wide characters (not including the
  410. * terminating null wide character) from the array pointed to by strSrc to the end of the wide string pointed to
  411. * by strDest.
  412. * Parameter: strDest - destination address
  413. * Parameter: destMax -The maximum length of destination buffer(including the terminating wide character)
  414. * Parameter: strSrc -source address
  415. * Parameter: count -copies count wide characters from the src
  416. * Return: EOK if there was no runtime-constraint violation
  417. */
  418. SECUREC_API errno_t wcsncat_s(wchar_t *strDest, size_t destMax, const wchar_t *strSrc, size_t count);
  419. #endif
  420. #if SECUREC_ENABLE_STRTOK
  421. /*
  422. * Description: The wcstok_s function is the wide-character equivalent of the strtok_s function
  423. * Parameter: strToken - the string to be delimited
  424. * Parameter: strDelimit -specifies a set of characters that delimit the tokens in the parsed string
  425. * Parameter: context -is a pointer to a char * variable that is used internally by strtok_s function
  426. * Return: a pointer to the first character of a token, or a null pointer if there is no token
  427. * or there is a runtime-constraint violation.
  428. */
  429. SECUREC_API wchar_t *wcstok_s(wchar_t *strToken, const wchar_t *strDelimit, wchar_t **context);
  430. #endif
  431. #if SECUREC_ENABLE_VSPRINTF
  432. /*
  433. * Description: The vswprintf_s function is the wide-character equivalent of the vsprintf_s function
  434. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  435. * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
  436. * Parameter: format - fromat string
  437. * Parameter: argList - instead of a variable number of arguments
  438. * Return: the number of characters printed(not including the terminating null wide characte),
  439. * If an error occurred Return: -1.
  440. */
  441. SECUREC_API int vswprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, va_list argList);
  442. #endif
  443. #if SECUREC_ENABLE_SPRINTF
  444. /*
  445. * Description: The swprintf_s function is the wide-character equivalent of the sprintf_s function
  446. * Parameter: strDest - produce output according to a format ,write to the character string strDest
  447. * Parameter: destMax - The maximum length of destination buffer(including the terminating null )
  448. * Parameter: format - fromat string
  449. * Return: the number of characters printed(not including the terminating null wide characte),
  450. * If an error occurred Return: -1.
  451. */
  452. SECUREC_API int swprintf_s(wchar_t *strDest, size_t destMax, const wchar_t *format, ...);
  453. #endif
  454. #if SECUREC_ENABLE_FSCANF
  455. /*
  456. * Description: The fwscanf_s function is the wide-character equivalent of the fscanf_s function
  457. * Parameter: stream - stdio file stream
  458. * Parameter: format - fromat string
  459. * Return: the number of input items assigned, If an error occurred Return: -1.
  460. */
  461. SECUREC_API int fwscanf_s(FILE *stream, const wchar_t *format, ...);
  462. #endif
  463. #if SECUREC_ENABLE_VFSCANF
  464. /*
  465. * Description: The vfwscanf_s function is the wide-character equivalent of the vfscanf_s function
  466. * Parameter: stream - stdio file stream
  467. * Parameter: format - fromat string
  468. * Parameter: argList - instead of a variable number of arguments
  469. * Return: the number of input items assigned, If an error occurred Return: -1.
  470. */
  471. SECUREC_API int vfwscanf_s(FILE *stream, const wchar_t *format, va_list argList);
  472. #endif
  473. #if SECUREC_ENABLE_SCANF
  474. /*
  475. * Description: The wscanf_s function is the wide-character equivalent of the scanf_s function
  476. * Parameter: format - fromat string
  477. * Return: the number of input items assigned, If an error occurred Return: -1.
  478. */
  479. SECUREC_API int wscanf_s(const wchar_t *format, ...);
  480. #endif
  481. #if SECUREC_ENABLE_VSCANF
  482. /*
  483. * Description: The vwscanf_s function is the wide-character equivalent of the vscanf_s function
  484. * Parameter: format - fromat string
  485. * Parameter: argList - instead of a variable number of arguments
  486. * Return: the number of input items assigned, If an error occurred Return: -1.
  487. */
  488. SECUREC_API int vwscanf_s(const wchar_t *format, va_list argList);
  489. #endif
  490. #if SECUREC_ENABLE_SSCANF
  491. /*
  492. * Description: The swscanf_s function is the wide-character equivalent of the sscanf_s function
  493. * Parameter: buffer - read character from buffer
  494. * Parameter: format - fromat string
  495. * Return: the number of input items assigned, If an error occurred Return: -1.
  496. */
  497. SECUREC_API int swscanf_s(const wchar_t *buffer, const wchar_t *format, ...);
  498. #endif
  499. #if SECUREC_ENABLE_VSSCANF
  500. /*
  501. * Description: The vswscanf_s function is the wide-character equivalent of the vsscanf_s function
  502. * Parameter: buffer - read character from buffer
  503. * Parameter: format - fromat string
  504. * Parameter: argList - instead of a variable number of arguments
  505. * Return: the number of input items assigned, If an error occurred Return: -1.
  506. */
  507. SECUREC_API int vswscanf_s(const wchar_t *buffer, const wchar_t *format, va_list argList);
  508. #endif
  509. #endif /* SECUREC_ENABLE_WCHAR_FUNC */
  510. #endif
  511. /* those functions are used by macro ,must declare hare , also for without function declaration warning */
  512. extern errno_t strncpy_error(char *strDest, size_t destMax, const char *strSrc, size_t count);
  513. extern errno_t strcpy_error(char *strDest, size_t destMax, const char *strSrc);
  514. #if SECUREC_WITH_PERFORMANCE_ADDONS
  515. /* those functions are used by macro */
  516. extern errno_t memset_sOptAsm(void *dest, size_t destMax, int c, size_t count);
  517. extern errno_t memset_sOptTc(void *dest, size_t destMax, int c, size_t count);
  518. extern errno_t memcpy_sOptAsm(void *dest, size_t destMax, const void *src, size_t count);
  519. extern errno_t memcpy_sOptTc(void *dest, size_t destMax, const void *src, size_t count);
  520. /* strcpy_sp is a macro, NOT a function in performance optimization mode. */
  521. #define strcpy_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
  522. __builtin_constant_p((src))) ? \
  523. SECUREC_STRCPY_SM((dest), (destMax), (src)) : \
  524. strcpy_s((dest), (destMax), (src)))
  525. /* strncpy_sp is a macro, NOT a function in performance optimization mode. */
  526. #define strncpy_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
  527. __builtin_constant_p((destMax)) && \
  528. __builtin_constant_p((src))) ? \
  529. SECUREC_STRNCPY_SM((dest), (destMax), (src), (count)) : \
  530. strncpy_s((dest), (destMax), (src), (count)))
  531. /* strcat_sp is a macro, NOT a function in performance optimization mode. */
  532. #define strcat_sp(dest, destMax, src) ((__builtin_constant_p((destMax)) && \
  533. __builtin_constant_p((src))) ? \
  534. SECUREC_STRCAT_SM((dest), (destMax), (src)) : \
  535. strcat_s((dest), (destMax), (src)))
  536. /* strncat_sp is a macro, NOT a function in performance optimization mode. */
  537. #define strncat_sp(dest, destMax, src, count) ((__builtin_constant_p((count)) && \
  538. __builtin_constant_p((destMax)) && \
  539. __builtin_constant_p((src))) ? \
  540. SECUREC_STRNCAT_SM((dest), (destMax), (src), (count)) : \
  541. strncat_s((dest), (destMax), (src), (count)))
  542. /* memcpy_sp is a macro, NOT a function in performance optimization mode. */
  543. #define memcpy_sp(dest, destMax, src, count) (__builtin_constant_p((count)) ? \
  544. (SECUREC_MEMCPY_SM((dest), (destMax), (src), (count))) : \
  545. (__builtin_constant_p((destMax)) ? \
  546. (((size_t)(destMax) > 0 && \
  547. (((unsigned long long)(destMax) & \
  548. (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
  549. memcpy_sOptTc((dest), (destMax), (src), (count)) : ERANGE) : \
  550. memcpy_sOptAsm((dest), (destMax), (src), (count))))
  551. /* memset_sp is a macro, NOT a function in performance optimization mode. */
  552. #define memset_sp(dest, destMax, c, count) (__builtin_constant_p((count)) ? \
  553. (SECUREC_MEMSET_SM((dest), (destMax), (c), (count))) : \
  554. (__builtin_constant_p((destMax)) ? \
  555. (((size_t)(destMax) > 0 && \
  556. (((unsigned long long)(destMax) & \
  557. (unsigned long long)(-2)) < SECUREC_MEM_MAX_LEN)) ? \
  558. memset_sOptTc((dest), (destMax), (c), (count)) : ERANGE) : \
  559. memset_sOptAsm((dest), (destMax), (c), (count))))
  560. #else
  561. #define strcpy_sp strcpy_s
  562. #define strncpy_sp strncpy_s
  563. #define strcat_sp strcat_s
  564. #define strncat_sp strncat_s
  565. #define memcpy_sp memcpy_s
  566. #define memset_sp memset_s
  567. #endif
  568. #ifdef __cplusplus
  569. }
  570. #endif /* __cplusplus */
  571. #endif /* __SECUREC_H__5D13A042_DC3F_4ED9_A8D1_882811274C27 */

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示