os.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * OS specific functions
  3. * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef OS_H
  9. #define OS_H
  10. #include <stdlib.h>
  11. typedef long os_time_t;
  12. /**
  13. * os_sleep - Sleep (sec, usec)
  14. * @sec: Number of seconds to sleep
  15. * @usec: Number of microseconds to sleep
  16. */
  17. void os_sleep(os_time_t sec, os_time_t usec);
  18. struct os_time {
  19. os_time_t sec;
  20. os_time_t usec;
  21. };
  22. struct os_reltime {
  23. os_time_t sec;
  24. os_time_t usec;
  25. };
  26. /**
  27. * os_get_time - Get current time (sec, usec)
  28. * @t: Pointer to buffer for the time
  29. * Returns: 0 on success, -1 on failure
  30. */
  31. int os_get_time(struct os_time *t);
  32. /**
  33. * os_get_reltime - Get relative time (sec, usec)
  34. * @t: Pointer to buffer for the time
  35. * Returns: 0 on success, -1 on failure
  36. */
  37. int os_get_reltime(struct os_reltime *t);
  38. /* Helpers for handling struct os_time */
  39. static inline int os_time_before(struct os_time *a, struct os_time *b)
  40. {
  41. return (a->sec < b->sec) ||
  42. (a->sec == b->sec && a->usec < b->usec);
  43. }
  44. static inline void os_time_sub(struct os_time *a, struct os_time *b,
  45. struct os_time *res)
  46. {
  47. res->sec = a->sec - b->sec;
  48. res->usec = a->usec - b->usec;
  49. if (res->usec < 0) {
  50. res->sec--;
  51. res->usec += 1000000;
  52. }
  53. }
  54. /* Helpers for handling struct os_reltime */
  55. static inline int os_reltime_before(struct os_reltime *a,
  56. struct os_reltime *b)
  57. {
  58. return (a->sec < b->sec) ||
  59. (a->sec == b->sec && a->usec < b->usec);
  60. }
  61. static inline void os_reltime_sub(struct os_reltime *a, struct os_reltime *b,
  62. struct os_reltime *res)
  63. {
  64. res->sec = a->sec - b->sec;
  65. res->usec = a->usec - b->usec;
  66. if (res->usec < 0) {
  67. res->sec--;
  68. res->usec += 1000000;
  69. }
  70. }
  71. static inline void os_reltime_age(struct os_reltime *start,
  72. struct os_reltime *age)
  73. {
  74. struct os_reltime now;
  75. os_get_reltime(&now);
  76. os_reltime_sub(&now, start, age);
  77. }
  78. static inline int os_reltime_expired(struct os_reltime *now,
  79. struct os_reltime *ts,
  80. os_time_t timeout_secs)
  81. {
  82. struct os_reltime age;
  83. os_reltime_sub(now, ts, &age);
  84. return (age.sec > timeout_secs) ||
  85. (age.sec == timeout_secs && age.usec > 0);
  86. }
  87. static inline int os_reltime_initialized(struct os_reltime *t)
  88. {
  89. return t->sec != 0 || t->usec != 0;
  90. }
  91. /**
  92. * os_mktime - Convert broken-down time into seconds since 1970-01-01
  93. * @year: Four digit year
  94. * @month: Month (1 .. 12)
  95. * @day: Day of month (1 .. 31)
  96. * @hour: Hour (0 .. 23)
  97. * @min: Minute (0 .. 59)
  98. * @sec: Second (0 .. 60)
  99. * @t: Buffer for returning calendar time representation (seconds since
  100. * 1970-01-01 00:00:00)
  101. * Returns: 0 on success, -1 on failure
  102. *
  103. * Note: The result is in seconds from Epoch, i.e., in UTC, not in local time
  104. * which is used by POSIX mktime().
  105. */
  106. int os_mktime(int year, int month, int day, int hour, int min, int sec,
  107. os_time_t *t);
  108. struct os_tm {
  109. int sec; /* 0..59 or 60 for leap seconds */
  110. int min; /* 0..59 */
  111. int hour; /* 0..23 */
  112. int day; /* 1..31 */
  113. int month; /* 1..12 */
  114. int year; /* Four digit year */
  115. };
  116. int os_gmtime(os_time_t t, struct os_tm *tm);
  117. /**
  118. * os_daemonize - Run in the background (detach from the controlling terminal)
  119. * @pid_file: File name to write the process ID to or %NULL to skip this
  120. * Returns: 0 on success, -1 on failure
  121. */
  122. int os_daemonize(const char *pid_file);
  123. /**
  124. * os_daemonize_terminate - Stop running in the background (remove pid file)
  125. * @pid_file: File name to write the process ID to or %NULL to skip this
  126. */
  127. void os_daemonize_terminate(const char *pid_file);
  128. /**
  129. * os_get_random - Get cryptographically strong pseudo random data
  130. * @buf: Buffer for pseudo random data
  131. * @len: Length of the buffer
  132. * Returns: 0 on success, -1 on failure
  133. */
  134. int os_get_random(unsigned char *buf, size_t len);
  135. /**
  136. * os_random - Get pseudo random value (not necessarily very strong)
  137. * Returns: Pseudo random value
  138. */
  139. unsigned long os_random(void);
  140. /**
  141. * os_rel2abs_path - Get an absolute path for a file
  142. * @rel_path: Relative path to a file
  143. * Returns: Absolute path for the file or %NULL on failure
  144. *
  145. * This function tries to convert a relative path of a file to an absolute path
  146. * in order for the file to be found even if current working directory has
  147. * changed. The returned value is allocated and caller is responsible for
  148. * freeing it. It is acceptable to just return the same path in an allocated
  149. * buffer, e.g., return strdup(rel_path). This function is only used to find
  150. * configuration files when os_daemonize() may have changed the current working
  151. * directory and relative path would be pointing to a different location.
  152. */
  153. char *os_rel2abs_path(const char *rel_path);
  154. /**
  155. * os_program_init - Program initialization (called at start)
  156. * Returns: 0 on success, -1 on failure
  157. *
  158. * This function is called when a programs starts. If there are any OS specific
  159. * processing that is needed, it can be placed here. It is also acceptable to
  160. * just return 0 if not special processing is needed.
  161. */
  162. int os_program_init(void);
  163. /**
  164. * os_program_deinit - Program deinitialization (called just before exit)
  165. *
  166. * This function is called just before a program exists. If there are any OS
  167. * specific processing, e.g., freeing resourced allocated in os_program_init(),
  168. * it should be done here. It is also acceptable for this function to do
  169. * nothing.
  170. */
  171. void os_program_deinit(void);
  172. /**
  173. * os_setenv - Set environment variable
  174. * @name: Name of the variable
  175. * @value: Value to set to the variable
  176. * @overwrite: Whether existing variable should be overwritten
  177. * Returns: 0 on success, -1 on error
  178. *
  179. * This function is only used for fota_cli action scripts. OS wrapper does not
  180. * need to implement this if such functionality is not needed.
  181. */
  182. int os_setenv(const char *name, const char *value, int overwrite);
  183. /**
  184. * os_unsetenv - Delete environent variable
  185. * @name: Name of the variable
  186. * Returns: 0 on success, -1 on error
  187. *
  188. * This function is only used for fota_cli action scripts. OS wrapper does not
  189. * need to implement this if such functionality is not needed.
  190. */
  191. int os_unsetenv(const char *name);
  192. /**
  193. * os_readfile - Read a file to an allocated memory buffer
  194. * @name: Name of the file to read
  195. * @len: For returning the length of the allocated buffer
  196. * Returns: Pointer to the allocated buffer or %NULL on failure
  197. *
  198. * This function allocates memory and reads the given file to this buffer. Both
  199. * binary and text files can be read with this function. The caller is
  200. * responsible for freeing the returned buffer with os_free().
  201. */
  202. char *os_readfile(const char *name, size_t *len);
  203. /**
  204. * os_file_exists - Check whether the specified file exists
  205. * @fname: Path and name of the file
  206. * Returns: 1 if the file exists or 0 if not
  207. */
  208. int os_file_exists(const char *fname);
  209. /**
  210. * os_fdatasync - Sync a file's (for a given stream) state with storage device
  211. * @stream: the stream to be flushed
  212. * Returns: 0 if the operation succeeded or -1 on failure
  213. */
  214. int os_fdatasync(FILE *stream);
  215. /**
  216. * os_zalloc - Allocate and zero memory
  217. * @size: Number of bytes to allocate
  218. * Returns: Pointer to allocated and zeroed memory or %NULL on failure
  219. *
  220. * Caller is responsible for freeing the returned buffer with os_free().
  221. */
  222. void *os_zalloc(size_t size);
  223. /**
  224. * os_calloc - Allocate and zero memory for an array
  225. * @nmemb: Number of members in the array
  226. * @size: Number of bytes in each member
  227. * Returns: Pointer to allocated and zeroed memory or %NULL on failure
  228. *
  229. * This function can be used as a wrapper for os_zalloc(nmemb * size) when an
  230. * allocation is used for an array. The main benefit over os_zalloc() is in
  231. * having an extra check to catch integer overflows in multiplication.
  232. *
  233. * Caller is responsible for freeing the returned buffer with os_free().
  234. */
  235. static inline void *os_calloc(size_t nmemb, size_t size)
  236. {
  237. if (size && nmemb > (~(size_t) 0) / size) {
  238. return NULL;
  239. }
  240. return os_zalloc(nmemb * size);
  241. }
  242. /*
  243. * The following functions are wrapper for standard ANSI C or POSIX functions.
  244. * By default, they are just defined to use the standard function name and no
  245. * os_*.c implementation is needed for them. This avoids extra function calls
  246. * by allowing the C pre-processor take care of the function name mapping.
  247. *
  248. * If the target system uses a C library that does not provide these functions,
  249. * build_config.h can be used to define the wrappers to use a different
  250. * function name. This can be done on function-by-function basis since the
  251. * defines here are only used if build_config.h does not define the os_* name.
  252. * If needed, os_*.c file can be used to implement the functions that are not
  253. * included in the C library on the target system. Alternatively,
  254. * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
  255. * these functions need to be implemented in os_*.c file for the target system.
  256. */
  257. #ifdef OS_NO_C_LIB_DEFINES
  258. /**
  259. * os_malloc - Allocate dynamic memory
  260. * @size: Size of the buffer to allocate
  261. * Returns: Allocated buffer or %NULL on failure
  262. *
  263. * Caller is responsible for freeing the returned buffer with os_free().
  264. */
  265. void *os_malloc(size_t size);
  266. /**
  267. * os_realloc - Re-allocate dynamic memory
  268. * @ptr: Old buffer from os_malloc() or os_realloc()
  269. * @size: Size of the new buffer
  270. * Returns: Allocated buffer or %NULL on failure
  271. *
  272. * Caller is responsible for freeing the returned buffer with os_free().
  273. * If re-allocation fails, %NULL is returned and the original buffer (ptr) is
  274. * not freed and caller is still responsible for freeing it.
  275. */
  276. void *os_realloc(void *ptr, size_t size);
  277. /**
  278. * os_free - Free dynamic memory
  279. * @ptr: Old buffer from os_malloc() or os_realloc(); can be %NULL
  280. */
  281. void os_free(void *ptr);
  282. /**
  283. * os_memcpy - Copy memory area
  284. * @dest: Destination
  285. * @src: Source
  286. * @n: Number of bytes to copy
  287. * Returns: dest
  288. *
  289. * The memory areas src and dst must not overlap. os_memmove() can be used with
  290. * overlapping memory.
  291. */
  292. void *os_memcpy(void *dest, const void *src, size_t n);
  293. /**
  294. * os_memmove - Copy memory area
  295. * @dest: Destination
  296. * @src: Source
  297. * @n: Number of bytes to copy
  298. * Returns: dest
  299. *
  300. * The memory areas src and dst may overlap.
  301. */
  302. void *os_memmove(void *dest, const void *src, size_t n);
  303. /**
  304. * os_memset - Fill memory with a constant byte
  305. * @s: Memory area to be filled
  306. * @c: Constant byte
  307. * @n: Number of bytes started from s to fill with c
  308. * Returns: s
  309. */
  310. void *os_memset(void *s, int c, size_t n);
  311. /**
  312. * os_memcmp - Compare memory areas
  313. * @s1: First buffer
  314. * @s2: Second buffer
  315. * @n: Maximum numbers of octets to compare
  316. * Returns: An integer less than, equal to, or greater than zero if s1 is
  317. * found to be less than, to match, or be greater than s2. Only first n
  318. * characters will be compared.
  319. */
  320. int os_memcmp(const void *s1, const void *s2, size_t n);
  321. /**
  322. * os_strdup - Duplicate a string
  323. * @s: Source string
  324. * Returns: Allocated buffer with the string copied into it or %NULL on failure
  325. *
  326. * Caller is responsible for freeing the returned buffer with os_free().
  327. */
  328. char *os_strdup(const char *s);
  329. /**
  330. * os_strlen - Calculate the length of a string
  331. * @s: '\0' terminated string
  332. * Returns: Number of characters in s (not counting the '\0' terminator)
  333. */
  334. size_t os_strlen(const char *s);
  335. /**
  336. * os_strcasecmp - Compare two strings ignoring case
  337. * @s1: First string
  338. * @s2: Second string
  339. * Returns: An integer less than, equal to, or greater than zero if s1 is
  340. * found to be less than, to match, or be greatred than s2
  341. */
  342. int os_strcasecmp(const char *s1, const char *s2);
  343. /**
  344. * os_strncasecmp - Compare two strings ignoring case
  345. * @s1: First string
  346. * @s2: Second string
  347. * @n: Maximum numbers of characters to compare
  348. * Returns: An integer less than, equal to, or greater than zero if s1 is
  349. * found to be less than, to match, or be greater than s2. Only first n
  350. * characters will be compared.
  351. */
  352. int os_strncasecmp(const char *s1, const char *s2, size_t n);
  353. /**
  354. * os_strchr - Locate the first occurrence of a character in string
  355. * @s: String
  356. * @c: Character to search for
  357. * Returns: Pointer to the matched character or %NULL if not found
  358. */
  359. char *os_strchr(const char *s, int c);
  360. /**
  361. * os_strrchr - Locate the last occurrence of a character in string
  362. * @s: String
  363. * @c: Character to search for
  364. * Returns: Pointer to the matched character or %NULL if not found
  365. */
  366. char *os_strrchr(const char *s, int c);
  367. /**
  368. * os_strcmp - Compare two strings
  369. * @s1: First string
  370. * @s2: Second string
  371. * Returns: An integer less than, equal to, or greater than zero if s1 is
  372. * found to be less than, to match, or be greatred than s2
  373. */
  374. int os_strcmp(const char *s1, const char *s2);
  375. /**
  376. * os_strncmp - Compare two strings
  377. * @s1: First string
  378. * @s2: Second string
  379. * @n: Maximum numbers of characters to compare
  380. * Returns: An integer less than, equal to, or greater than zero if s1 is
  381. * found to be less than, to match, or be greater than s2. Only first n
  382. * characters will be compared.
  383. */
  384. int os_strncmp(const char *s1, const char *s2, size_t n);
  385. /**
  386. * os_strstr - Locate a substring
  387. * @haystack: String (haystack) to search from
  388. * @needle: Needle to search from haystack
  389. * Returns: Pointer to the beginning of the substring or %NULL if not found
  390. */
  391. char *os_strstr(const char *haystack, const char *needle);
  392. /**
  393. * os_snprintf - Print to a memory buffer
  394. * @str: Memory buffer to print into
  395. * @size: Maximum length of the str buffer
  396. * @format: printf format
  397. * Returns: Number of characters printed (not including trailing '\0').
  398. *
  399. * If the output buffer is truncated, number of characters which would have
  400. * been written is returned. Since some C libraries return -1 in such a case,
  401. * the caller must be prepared on that value, too, to indicate truncation.
  402. *
  403. * Note: Some C library implementations of snprintf() may not guarantee null
  404. * termination in case the output is truncated. The OS wrapper function of
  405. * os_snprintf() should provide this guarantee, i.e., to null terminate the
  406. * output buffer if a C library version of the function is used and if that
  407. * function does not guarantee null termination.
  408. *
  409. * If the target system does not include snprintf(), see, e.g.,
  410. * http://www.ijs.si/software/snprintf/ for an example of a portable
  411. * implementation of snprintf.
  412. */
  413. int os_snprintf(char *str, size_t size, const char *format, ...);
  414. #else /* OS_NO_C_LIB_DEFINES */
  415. #ifdef FOTA_TRACE
  416. void *os_malloc(size_t size);
  417. void *os_realloc(void *ptr, size_t size);
  418. void os_free(void *ptr);
  419. char *os_strdup(const char *s);
  420. #else /* FOTA_TRACE */
  421. #ifndef os_malloc
  422. #define os_malloc(s) malloc((s))
  423. #endif
  424. #ifndef os_realloc
  425. #define os_realloc(p, s) realloc((p), (s))
  426. #endif
  427. #ifndef os_free
  428. #define os_free(p) free((p))
  429. #endif
  430. #ifndef os_strdup
  431. #ifdef _MSC_VER
  432. #define os_strdup(s) _strdup(s)
  433. #else
  434. #define os_strdup(s) strdup(s)
  435. #endif
  436. #endif
  437. #endif /* FOTA_TRACE */
  438. #ifndef os_memcpy
  439. #define os_memcpy(d, s, n) memcpy((d), (s), (n))
  440. #endif
  441. #ifndef os_memmove
  442. #define os_memmove(d, s, n) memmove((d), (s), (n))
  443. #endif
  444. #ifndef os_memset
  445. #define os_memset(s, c, n) memset(s, c, n)
  446. #endif
  447. #ifndef os_memcmp
  448. #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
  449. #endif
  450. #ifndef os_strlen
  451. #define os_strlen(s) strlen(s)
  452. #endif
  453. #ifndef os_strcasecmp
  454. #ifdef _MSC_VER
  455. #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
  456. #else
  457. #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
  458. #endif
  459. #endif
  460. #ifndef os_strncasecmp
  461. #ifdef _MSC_VER
  462. #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
  463. #else
  464. #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
  465. #endif
  466. #endif
  467. #ifndef os_strchr
  468. #define os_strchr(s, c) strchr((s), (c))
  469. #endif
  470. #ifndef os_strcmp
  471. #define os_strcmp(s1, s2) strcmp((s1), (s2))
  472. #endif
  473. #ifndef os_strncmp
  474. #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
  475. #endif
  476. #ifndef os_strrchr
  477. #define os_strrchr(s, c) strrchr((s), (c))
  478. #endif
  479. #ifndef os_strstr
  480. #define os_strstr(h, n) strstr((h), (n))
  481. #endif
  482. #ifndef os_snprintf
  483. #ifdef _MSC_VER
  484. #define os_snprintf _snprintf
  485. #else
  486. #define os_snprintf snprintf
  487. #endif
  488. #endif
  489. #endif /* OS_NO_C_LIB_DEFINES */
  490. static inline int os_snprintf_error(size_t size, int res)
  491. {
  492. return res < 0 || (unsigned int) res >= size;
  493. }
  494. static inline void *os_realloc_array(void *ptr, size_t nmemb, size_t size)
  495. {
  496. if (size && nmemb > (~(size_t) 0) / size) {
  497. return NULL;
  498. }
  499. return os_realloc(ptr, nmemb * size);
  500. }
  501. /**
  502. * os_remove_in_array - Remove a member from an array by index
  503. * @ptr: Pointer to the array
  504. * @nmemb: Current member count of the array
  505. * @size: The size per member of the array
  506. * @idx: Index of the member to be removed
  507. */
  508. static inline void os_remove_in_array(void *ptr, size_t nmemb, size_t size,
  509. size_t idx)
  510. {
  511. if (idx < nmemb - 1)
  512. os_memmove(((unsigned char *) ptr) + idx * size,
  513. ((unsigned char *) ptr) + (idx + 1) * size,
  514. (nmemb - idx - 1) * size);
  515. }
  516. /**
  517. * os_strlcpy - Copy a string with size bound and NUL-termination
  518. * @dest: Destination
  519. * @src: Source
  520. * @siz: Size of the target buffer
  521. * Returns: Total length of the target string (length of src) (not including
  522. * NUL-termination)
  523. *
  524. * This function matches in behavior with the strlcpy(3) function in OpenBSD.
  525. */
  526. size_t os_strlcpy(char *dest, const char *src, size_t siz);
  527. /**
  528. * os_memcmp_const - Constant time memory comparison
  529. * @a: First buffer to compare
  530. * @b: Second buffer to compare
  531. * @len: Number of octets to compare
  532. * Returns: 0 if buffers are equal, non-zero if not
  533. *
  534. * This function is meant for comparing passwords or hash values where
  535. * difference in execution time could provide external observer information
  536. * about the location of the difference in the memory buffers. The return value
  537. * does not behave like os_memcmp(), i.e., os_memcmp_const() cannot be used to
  538. * sort items into a defined order. Unlike os_memcmp(), execution time of
  539. * os_memcmp_const() does not depend on the contents of the compared memory
  540. * buffers, but only on the total compared length.
  541. */
  542. int os_memcmp_const(const void *a, const void *b, size_t len);
  543. /**
  544. * os_memdup - Allocate duplicate of passed memory chunk
  545. * @src: Source buffer to duplicate
  546. * @len: Length of source buffer
  547. * Returns: %NULL if allocation failed, copy of src buffer otherwise
  548. *
  549. * This function allocates a memory block like os_malloc() would, and
  550. * copies the given source buffer into it.
  551. */
  552. void *os_memdup(const void *src, size_t len);
  553. /**
  554. * os_exec - Execute an external program
  555. * @program: Path to the program
  556. * @arg: Command line argument string
  557. * @wait_completion: Whether to wait until the program execution completes
  558. * Returns: 0 on success, -1 on error
  559. */
  560. int os_exec(const char *program, const char *arg, int wait_completion);
  561. #ifdef OS_REJECT_C_LIB_FUNCTIONS
  562. #define malloc OS_DO_NOT_USE_malloc
  563. #define realloc OS_DO_NOT_USE_realloc
  564. #define free OS_DO_NOT_USE_free
  565. #define memcpy OS_DO_NOT_USE_memcpy
  566. #define memmove OS_DO_NOT_USE_memmove
  567. #define memset OS_DO_NOT_USE_memset
  568. #define memcmp OS_DO_NOT_USE_memcmp
  569. #undef strdup
  570. #define strdup OS_DO_NOT_USE_strdup
  571. #define strlen OS_DO_NOT_USE_strlen
  572. #define strcasecmp OS_DO_NOT_USE_strcasecmp
  573. #define strncasecmp OS_DO_NOT_USE_strncasecmp
  574. #undef strchr
  575. #define strchr OS_DO_NOT_USE_strchr
  576. #undef strcmp
  577. #define strcmp OS_DO_NOT_USE_strcmp
  578. #undef strncmp
  579. #define strncmp OS_DO_NOT_USE_strncmp
  580. #undef strncpy
  581. #define strncpy OS_DO_NOT_USE_strncpy
  582. #define strrchr OS_DO_NOT_USE_strrchr
  583. #define strstr OS_DO_NOT_USE_strstr
  584. #undef snprintf
  585. #define snprintf OS_DO_NOT_USE_snprintf
  586. #define strcpy OS_DO_NOT_USE_strcpy
  587. #endif /* OS_REJECT_C_LIB_FUNCTIONS */
  588. #if defined(FOTA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
  589. #define TEST_FAIL() testing_test_fail()
  590. int testing_test_fail(void);
  591. extern char fota_trace_fail_func[256];
  592. extern unsigned int fota_trace_fail_after;
  593. extern char fota_trace_test_fail_func[256];
  594. extern unsigned int fota_trace_test_fail_after;
  595. #else
  596. #define TEST_FAIL() 0
  597. #endif
  598. #endif /* OS_H */