os.h

Go to the documentation of this file.
00001 
00016 #ifndef OS_H
00017 #define OS_H
00018 
00019 typedef long os_time_t;
00020 
00027 void os_sleep(os_time_t sec, os_time_t usec);
00028 
00029 struct os_time {
00030         os_time_t sec;
00031         os_time_t usec;
00032 };
00033 
00040 int os_get_time(struct os_time *t);
00041 
00042 
00043 /* Helper macros for handling struct os_time */
00044 
00045 #define os_time_before(a, b) \
00046         ((a)->sec < (b)->sec || \
00047          ((a)->sec == (b)->sec && (a)->usec < (b)->usec))
00048 
00049 #define os_time_sub(a, b, res) do { \
00050         (res)->sec = (a)->sec - (b)->sec; \
00051         (res)->usec = (a)->usec - (b)->usec; \
00052         if ((res)->usec < 0) { \
00053                 (res)->sec--; \
00054                 (res)->usec += 1000000; \
00055         } \
00056 } while (0)
00057 
00071 int os_mktime(int year, int month, int day, int hour, int min, int sec,
00072               os_time_t *t);
00073 
00074 
00081 int os_daemonize(const char *pid_file);
00082 
00088 void os_daemonize_terminate(const char *pid_file);
00089 
00097 int os_get_random(unsigned char *buf, size_t len);
00098 
00104 unsigned long os_random(void);
00105 
00120 char * os_rel2abs_path(const char *rel_path);
00121 
00131 int os_program_init(void);
00132 
00142 void os_program_deinit(void);
00143 
00155 int os_setenv(const char *name, const char *value, int overwrite);
00156 
00166 int os_unsetenv(const char *name);
00167 
00179 char * os_readfile(const char *name, size_t *len);
00180 
00189 void * os_zalloc(size_t size);
00190 
00191 
00192 /*
00193  * The following functions are wrapper for standard ANSI C or POSIX functions.
00194  * By default, they are just defined to use the standard function name and no
00195  * os_*.c implementation is needed for them. This avoids extra function calls
00196  * by allowing the C pre-processor take care of the function name mapping.
00197  *
00198  * If the target system uses a C library that does not provide these functions,
00199  * build_config.h can be used to define the wrappers to use a different
00200  * function name. This can be done on function-by-function basis since the
00201  * defines here are only used if build_config.h does not define the os_* name.
00202  * If needed, os_*.c file can be used to implement the functions that are not
00203  * included in the C library on the target system. Alternatively,
00204  * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
00205  * these functions need to be implemented in os_*.c file for the target system.
00206  */
00207 
00208 #ifdef OS_NO_C_LIB_DEFINES
00209 
00218 void * os_malloc(size_t size);
00219 
00231 void * os_realloc(void *ptr, size_t size);
00232 
00238 void os_free(void *ptr);
00239 
00251 void * os_memcpy(void *dest, const void *src, size_t n);
00252 
00263 void * os_memmove(void *dest, const void *src, size_t n);
00264 
00273 void * os_memset(void *s, int c, size_t n);
00274 
00285 int os_memcmp(const void *s1, const void *s2, size_t n);
00286 
00295 char * os_strdup(const char *s);
00296 
00303 size_t os_strlen(const char *s);
00304 
00313 int os_strcasecmp(const char *s1, const char *s2);
00314 
00325 int os_strncasecmp(const char *s1, const char *s2, size_t n);
00326 
00334 char * os_strchr(const char *s, int c);
00335 
00343 char * os_strrchr(const char *s, int c);
00344 
00353 int os_strcmp(const char *s1, const char *s2);
00354 
00365 int os_strncmp(const char *s1, const char *s2, size_t n);
00366 
00375 char * os_strncpy(char *dest, const char *src, size_t n);
00376 
00384 char * os_strstr(const char *haystack, const char *needle);
00385 
00408 int os_snprintf(char *str, size_t size, const char *format, ...);
00409 
00410 #else /* OS_NO_C_LIB_DEFINES */
00411 
00412 #ifndef os_malloc
00413 #define os_malloc(s) malloc((s))
00414 #endif
00415 #ifndef os_realloc
00416 #define os_realloc(p, s) realloc((p), (s))
00417 #endif
00418 #ifndef os_free
00419 #define os_free(p) free((p))
00420 #endif
00421 
00422 #ifndef os_memcpy
00423 #define os_memcpy(d, s, n) memcpy((d), (s), (n))
00424 #endif
00425 #ifndef os_memmove
00426 #define os_memmove(d, s, n) memmove((d), (s), (n))
00427 #endif
00428 #ifndef os_memset
00429 #define os_memset(s, c, n) memset(s, c, n)
00430 #endif
00431 #ifndef os_memcmp
00432 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
00433 #endif
00434 
00435 #ifndef os_strdup
00436 #ifdef _MSC_VER
00437 #define os_strdup(s) _strdup(s)
00438 #else
00439 #define os_strdup(s) strdup(s)
00440 #endif
00441 #endif
00442 #ifndef os_strlen
00443 #define os_strlen(s) strlen(s)
00444 #endif
00445 #ifndef os_strcasecmp
00446 #ifdef _MSC_VER
00447 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
00448 #else
00449 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
00450 #endif
00451 #endif
00452 #ifndef os_strncasecmp
00453 #ifdef _MSC_VER
00454 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
00455 #else
00456 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
00457 #endif
00458 #endif
00459 #ifndef os_strchr
00460 #define os_strchr(s, c) strchr((s), (c))
00461 #endif
00462 #ifndef os_strcmp
00463 #define os_strcmp(s1, s2) strcmp((s1), (s2))
00464 #endif
00465 #ifndef os_strncmp
00466 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
00467 #endif
00468 #ifndef os_strncpy
00469 #define os_strncpy(d, s, n) strncpy((d), (s), (n))
00470 #endif
00471 #ifndef os_strrchr
00472 #define os_strrchr(s, c) strrchr((s), (c))
00473 #endif
00474 #ifndef os_strstr
00475 #define os_strstr(h, n) strstr((h), (n))
00476 #endif
00477 
00478 #ifndef os_snprintf
00479 #ifdef _MSC_VER
00480 #define os_snprintf _snprintf
00481 #else
00482 #define os_snprintf snprintf
00483 #endif
00484 #endif
00485 
00486 #endif /* OS_NO_C_LIB_DEFINES */
00487 
00488 
00489 #ifdef OS_REJECT_C_LIB_FUNCTIONS
00490 #define malloc OS_DO_NOT_USE_malloc
00491 #define realloc OS_DO_NOT_USE_realloc
00492 #define free OS_DO_NOT_USE_free
00493 #define memcpy OS_DO_NOT_USE_memcpy
00494 #define memmove OS_DO_NOT_USE_memmove
00495 #define memset OS_DO_NOT_USE_memset
00496 #define memcmp OS_DO_NOT_USE_memcmp
00497 #undef strdup
00498 #define strdup OS_DO_NOT_USE_strdup
00499 #define strlen OS_DO_NOT_USE_strlen
00500 #define strcasecmp OS_DO_NOT_USE_strcasecmp
00501 #define strncasecmp OS_DO_NOT_USE_strncasecmp
00502 #undef strchr
00503 #define strchr OS_DO_NOT_USE_strchr
00504 #undef strcmp
00505 #define strcmp OS_DO_NOT_USE_strcmp
00506 #undef strncmp
00507 #define strncmp OS_DO_NOT_USE_strncmp
00508 #undef strncpy
00509 #define strncpy OS_DO_NOT_USE_strncpy
00510 #define strrchr OS_DO_NOT_USE_strrchr
00511 #define strstr OS_DO_NOT_USE_strstr
00512 #undef snprintf
00513 #define snprintf OS_DO_NOT_USE_snprintf
00514 
00515 #define strcpy OS_DO_NOT_USE_strcpy
00516 #endif /* OS_REJECT_C_LIB_FUNCTIONS */
00517 
00518 #endif /* OS_H */
00519 

Generated on Sun Dec 31 13:43:28 2006 for hostapd by  doxygen 1.4.2