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