8 typedef long os_time_t;
15 void os_sleep(os_time_t sec, os_time_t usec);
44 static inline int os_time_before(
struct os_time *a,
struct os_time *b)
46 return (a->sec < b->sec) ||
47 (a->sec == b->sec && a->usec < b->usec);
51 static inline void os_time_sub(
struct os_time *a,
struct os_time *b,
54 res->sec = a->sec - b->sec;
55 res->usec = a->usec - b->usec;
65 static inline int os_reltime_before(
struct os_reltime *a,
68 return (a->sec < b->sec) ||
69 (a->sec == b->sec && a->usec < b->usec);
76 res->sec = a->sec - b->sec;
77 res->usec = a->usec - b->usec;
85 static inline void os_reltime_age(
struct os_reltime *start,
91 os_reltime_sub(&now, start, age);
95 static inline int os_reltime_expired(
struct os_reltime *now,
97 os_time_t timeout_secs)
101 os_reltime_sub(now, ts, &age);
102 return (age.sec > timeout_secs) ||
103 (age.sec == timeout_secs && age.usec > 0);
107 static inline int os_reltime_initialized(
struct os_reltime *t)
109 return t->sec != 0 || t->usec != 0;
128 int os_mktime(
int year,
int month,
int day,
int hour,
int min,
int sec,
140 int os_gmtime(os_time_t t,
struct os_tm *tm);
215 int os_setenv(
const char *name,
const char *value,
int overwrite);
274 static inline void * os_calloc(
size_t nmemb,
size_t size)
276 if (size && nmemb > (~(
size_t) 0) / size)
298 #ifdef OS_NO_C_LIB_DEFINES
307 void * os_malloc(
size_t size);
319 void * os_realloc(
void *ptr,
size_t size);
325 void os_free(
void *ptr);
337 void * os_memcpy(
void *dest,
const void *src,
size_t n);
348 void * os_memmove(
void *dest,
const void *src,
size_t n);
357 void * os_memset(
void *s,
int c,
size_t n);
368 int os_memcmp(
const void *s1,
const void *s2,
size_t n);
377 char * os_strdup(
const char *s);
384 size_t os_strlen(
const char *s);
393 int os_strcasecmp(
const char *s1,
const char *s2);
404 int os_strncasecmp(
const char *s1,
const char *s2,
size_t n);
412 char * os_strchr(
const char *s,
int c);
420 char * os_strrchr(
const char *s,
int c);
429 int os_strcmp(
const char *s1,
const char *s2);
440 int os_strncmp(
const char *s1,
const char *s2,
size_t n);
448 char * os_strstr(
const char *haystack,
const char *needle);
471 int os_snprintf(
char *str,
size_t size,
const char *format, ...);
476 void * os_malloc(
size_t size);
477 void * os_realloc(
void *ptr,
size_t size);
478 void os_free(
void *ptr);
479 char * os_strdup(
const char *s);
482 #define os_malloc(s) malloc((s))
485 #define os_realloc(p, s) realloc((p), (s))
488 #define os_free(p) free((p))
492 #define os_strdup(s) _strdup(s)
494 #define os_strdup(s) strdup(s)
500 #define os_memcpy(d, s, n) memcpy((d), (s), (n))
503 #define os_memmove(d, s, n) memmove((d), (s), (n))
506 #define os_memset(s, c, n) memset(s, c, n)
509 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
513 #define os_strlen(s) strlen(s)
515 #ifndef os_strcasecmp
517 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
519 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
522 #ifndef os_strncasecmp
524 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
526 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
530 #define os_strchr(s, c) strchr((s), (c))
533 #define os_strcmp(s1, s2) strcmp((s1), (s2))
536 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
539 #define os_strrchr(s, c) strrchr((s), (c))
542 #define os_strstr(h, n) strstr((h), (n))
547 #define os_snprintf _snprintf
549 #define os_snprintf snprintf
556 static inline int os_snprintf_error(
size_t size,
int res)
558 return res < 0 || (unsigned int) res >= size;
562 static inline void * os_realloc_array(
void *ptr,
size_t nmemb,
size_t size)
564 if (size && nmemb > (~(
size_t) 0) / size)
566 return os_realloc(ptr, nmemb * size);
576 static inline void os_remove_in_array(
void *ptr,
size_t nmemb,
size_t size,
580 os_memmove(((
unsigned char *) ptr) + idx * size,
581 ((
unsigned char *) ptr) + (idx + 1) * size,
582 (nmemb - idx - 1) * size);
595 size_t os_strlcpy(
char *dest,
const char *src,
size_t siz);
621 int os_exec(
const char *program,
const char *arg,
int wait_completion);
624 #ifdef OS_REJECT_C_LIB_FUNCTIONS
625 #define malloc OS_DO_NOT_USE_malloc
626 #define realloc OS_DO_NOT_USE_realloc
627 #define free OS_DO_NOT_USE_free
628 #define memcpy OS_DO_NOT_USE_memcpy
629 #define memmove OS_DO_NOT_USE_memmove
630 #define memset OS_DO_NOT_USE_memset
631 #define memcmp OS_DO_NOT_USE_memcmp
633 #define strdup OS_DO_NOT_USE_strdup
634 #define strlen OS_DO_NOT_USE_strlen
635 #define strcasecmp OS_DO_NOT_USE_strcasecmp
636 #define strncasecmp OS_DO_NOT_USE_strncasecmp
638 #define strchr OS_DO_NOT_USE_strchr
640 #define strcmp OS_DO_NOT_USE_strcmp
642 #define strncmp OS_DO_NOT_USE_strncmp
644 #define strncpy OS_DO_NOT_USE_strncpy
645 #define strrchr OS_DO_NOT_USE_strrchr
646 #define strstr OS_DO_NOT_USE_strstr
648 #define snprintf OS_DO_NOT_USE_snprintf
650 #define strcpy OS_DO_NOT_USE_strcpy
654 #if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
655 #define TEST_FAIL() testing_test_fail()
656 int testing_test_fail(
void);
658 #define TEST_FAIL() 0
char * os_readfile(const char *name, size_t *len)
Read a file to an allocated memory buffer.
Definition: os_internal.c:211
int os_file_exists(const char *fname)
Check whether the specified file exists.
Definition: os_unix.c:431
void os_sleep(os_time_t sec, os_time_t usec)
Sleep (sec, usec)
Definition: os_internal.c:22
int os_memcmp_const(const void *a, const void *b, size_t len)
Constant time memory comparison.
Definition: os_internal.c:470
int os_program_init(void)
Program initialization (called at start)
Definition: os_internal.c:183
void * os_zalloc(size_t size)
Allocate and zero memory.
Definition: os_internal.c:248
int os_get_random(unsigned char *buf, size_t len)
Get cryptographically strong pseudo random data.
Definition: os_internal.c:120
int os_fdatasync(FILE *stream)
Sync a file's (for a given stream) state with storage device.
Definition: os_internal.c:242
int os_exec(const char *program, const char *arg, int wait_completion)
Execute an external program.
Definition: os_internal.c:515
void os_daemonize_terminate(const char *pid_file)
Stop running in the background (remove pid file)
Definition: os_internal.c:113
void os_program_deinit(void)
Program deinitialization (called just before exit)
Definition: os_internal.c:189
int os_get_time(struct os_time *t)
Get current time (sec, usec)
Definition: os_internal.c:31
int os_mktime(int year, int month, int day, int hour, int min, int sec, os_time_t *t)
Convert broken-down time into seconds since 1970-01-01.
Definition: os_internal.c:53
int os_daemonize(const char *pid_file)
Run in the background (detach from the controlling terminal)
Definition: os_internal.c:94
int os_get_reltime(struct os_reltime *t)
Get relative time (sec, usec)
Definition: os_internal.c:42
size_t os_strlcpy(char *dest, const char *src, size_t siz)
Copy a string with size bound and NUL-termination.
Definition: os_internal.c:445
int os_setenv(const char *name, const char *value, int overwrite)
Set environment variable.
Definition: os_internal.c:194
int os_unsetenv(const char *name)
Delete environent variable.
Definition: os_internal.c:200
char * os_rel2abs_path(const char *rel_path)
Get an absolute path for a file.
Definition: os_internal.c:144
unsigned long os_random(void)
Get pseudo random value (not necessarily very strong)
Definition: os_internal.c:138