os.h 20 KB

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