|
wpa_supplicant / hostapd 2.0
|
00001 00010 #ifndef OS_H 00011 #define OS_H 00012 00013 typedef long os_time_t; 00014 00021 void os_sleep(os_time_t sec, os_time_t usec); 00022 00023 struct os_time { 00024 os_time_t sec; 00025 os_time_t usec; 00026 }; 00027 00034 int os_get_time(struct os_time *t); 00035 00036 00037 /* Helper macros for handling struct os_time */ 00038 00039 #define os_time_before(a, b) \ 00040 ((a)->sec < (b)->sec || \ 00041 ((a)->sec == (b)->sec && (a)->usec < (b)->usec)) 00042 00043 #define os_time_sub(a, b, res) do { \ 00044 (res)->sec = (a)->sec - (b)->sec; \ 00045 (res)->usec = (a)->usec - (b)->usec; \ 00046 if ((res)->usec < 0) { \ 00047 (res)->sec--; \ 00048 (res)->usec += 1000000; \ 00049 } \ 00050 } while (0) 00051 00068 int os_mktime(int year, int month, int day, int hour, int min, int sec, 00069 os_time_t *t); 00070 00071 struct os_tm { 00072 int sec; /* 0..59 or 60 for leap seconds */ 00073 int min; /* 0..59 */ 00074 int hour; /* 0..23 */ 00075 int day; /* 1..31 */ 00076 int month; /* 1..12 */ 00077 int year; /* Four digit year */ 00078 }; 00079 00080 int os_gmtime(os_time_t t, struct os_tm *tm); 00081 00088 int os_daemonize(const char *pid_file); 00089 00095 void os_daemonize_terminate(const char *pid_file); 00096 00104 int os_get_random(unsigned char *buf, size_t len); 00105 00111 unsigned long os_random(void); 00112 00127 char * os_rel2abs_path(const char *rel_path); 00128 00138 int os_program_init(void); 00139 00149 void os_program_deinit(void); 00150 00162 int os_setenv(const char *name, const char *value, int overwrite); 00163 00173 int os_unsetenv(const char *name); 00174 00186 char * os_readfile(const char *name, size_t *len); 00187 00196 void * os_zalloc(size_t size); 00197 00198 00199 /* 00200 * The following functions are wrapper for standard ANSI C or POSIX functions. 00201 * By default, they are just defined to use the standard function name and no 00202 * os_*.c implementation is needed for them. This avoids extra function calls 00203 * by allowing the C pre-processor take care of the function name mapping. 00204 * 00205 * If the target system uses a C library that does not provide these functions, 00206 * build_config.h can be used to define the wrappers to use a different 00207 * function name. This can be done on function-by-function basis since the 00208 * defines here are only used if build_config.h does not define the os_* name. 00209 * If needed, os_*.c file can be used to implement the functions that are not 00210 * included in the C library on the target system. Alternatively, 00211 * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case 00212 * these functions need to be implemented in os_*.c file for the target system. 00213 */ 00214 00215 #ifdef OS_NO_C_LIB_DEFINES 00216 00225 void * os_malloc(size_t size); 00226 00238 void * os_realloc(void *ptr, size_t size); 00239 00245 void os_free(void *ptr); 00246 00258 void * os_memcpy(void *dest, const void *src, size_t n); 00259 00270 void * os_memmove(void *dest, const void *src, size_t n); 00271 00280 void * os_memset(void *s, int c, size_t n); 00281 00292 int os_memcmp(const void *s1, const void *s2, size_t n); 00293 00302 char * os_strdup(const char *s); 00303 00310 size_t os_strlen(const char *s); 00311 00320 int os_strcasecmp(const char *s1, const char *s2); 00321 00332 int os_strncasecmp(const char *s1, const char *s2, size_t n); 00333 00341 char * os_strchr(const char *s, int c); 00342 00350 char * os_strrchr(const char *s, int c); 00351 00360 int os_strcmp(const char *s1, const char *s2); 00361 00372 int os_strncmp(const char *s1, const char *s2, size_t n); 00373 00382 char * os_strncpy(char *dest, const char *src, size_t n); 00383 00391 char * os_strstr(const char *haystack, const char *needle); 00392 00415 int os_snprintf(char *str, size_t size, const char *format, ...); 00416 00417 #else /* OS_NO_C_LIB_DEFINES */ 00418 00419 #ifdef WPA_TRACE 00420 void * os_malloc(size_t size); 00421 void * os_realloc(void *ptr, size_t size); 00422 void os_free(void *ptr); 00423 char * os_strdup(const char *s); 00424 #else /* WPA_TRACE */ 00425 #ifndef os_malloc 00426 #define os_malloc(s) malloc((s)) 00427 #endif 00428 #ifndef os_realloc 00429 #define os_realloc(p, s) realloc((p), (s)) 00430 #endif 00431 #ifndef os_free 00432 #define os_free(p) free((p)) 00433 #endif 00434 #ifndef os_strdup 00435 #ifdef _MSC_VER 00436 #define os_strdup(s) _strdup(s) 00437 #else 00438 #define os_strdup(s) strdup(s) 00439 #endif 00440 #endif 00441 #endif /* WPA_TRACE */ 00442 00443 #ifndef os_memcpy 00444 #define os_memcpy(d, s, n) memcpy((d), (s), (n)) 00445 #endif 00446 #ifndef os_memmove 00447 #define os_memmove(d, s, n) memmove((d), (s), (n)) 00448 #endif 00449 #ifndef os_memset 00450 #define os_memset(s, c, n) memset(s, c, n) 00451 #endif 00452 #ifndef os_memcmp 00453 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n)) 00454 #endif 00455 00456 #ifndef os_strlen 00457 #define os_strlen(s) strlen(s) 00458 #endif 00459 #ifndef os_strcasecmp 00460 #ifdef _MSC_VER 00461 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2)) 00462 #else 00463 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2)) 00464 #endif 00465 #endif 00466 #ifndef os_strncasecmp 00467 #ifdef _MSC_VER 00468 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) 00469 #else 00470 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n)) 00471 #endif 00472 #endif 00473 #ifndef os_strchr 00474 #define os_strchr(s, c) strchr((s), (c)) 00475 #endif 00476 #ifndef os_strcmp 00477 #define os_strcmp(s1, s2) strcmp((s1), (s2)) 00478 #endif 00479 #ifndef os_strncmp 00480 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n)) 00481 #endif 00482 #ifndef os_strncpy 00483 #define os_strncpy(d, s, n) strncpy((d), (s), (n)) 00484 #endif 00485 #ifndef os_strrchr 00486 #define os_strrchr(s, c) strrchr((s), (c)) 00487 #endif 00488 #ifndef os_strstr 00489 #define os_strstr(h, n) strstr((h), (n)) 00490 #endif 00491 00492 #ifndef os_snprintf 00493 #ifdef _MSC_VER 00494 #define os_snprintf _snprintf 00495 #else 00496 #define os_snprintf snprintf 00497 #endif 00498 #endif 00499 00500 #endif /* OS_NO_C_LIB_DEFINES */ 00501 00502 00514 size_t os_strlcpy(char *dest, const char *src, size_t siz); 00515 00516 00517 #ifdef OS_REJECT_C_LIB_FUNCTIONS 00518 #define malloc OS_DO_NOT_USE_malloc 00519 #define realloc OS_DO_NOT_USE_realloc 00520 #define free OS_DO_NOT_USE_free 00521 #define memcpy OS_DO_NOT_USE_memcpy 00522 #define memmove OS_DO_NOT_USE_memmove 00523 #define memset OS_DO_NOT_USE_memset 00524 #define memcmp OS_DO_NOT_USE_memcmp 00525 #undef strdup 00526 #define strdup OS_DO_NOT_USE_strdup 00527 #define strlen OS_DO_NOT_USE_strlen 00528 #define strcasecmp OS_DO_NOT_USE_strcasecmp 00529 #define strncasecmp OS_DO_NOT_USE_strncasecmp 00530 #undef strchr 00531 #define strchr OS_DO_NOT_USE_strchr 00532 #undef strcmp 00533 #define strcmp OS_DO_NOT_USE_strcmp 00534 #undef strncmp 00535 #define strncmp OS_DO_NOT_USE_strncmp 00536 #undef strncpy 00537 #define strncpy OS_DO_NOT_USE_strncpy 00538 #define strrchr OS_DO_NOT_USE_strrchr 00539 #define strstr OS_DO_NOT_USE_strstr 00540 #undef snprintf 00541 #define snprintf OS_DO_NOT_USE_snprintf 00542 00543 #define strcpy OS_DO_NOT_USE_strcpy 00544 #endif /* OS_REJECT_C_LIB_FUNCTIONS */ 00545 00546 #endif /* OS_H */ 00547
1.7.3