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