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 
00074 int os_mktime(int year, int month, int day, int hour, int min, int sec,
00075               os_time_t *t);
00076 
00077 
00084 int os_daemonize(const char *pid_file);
00085 
00091 void os_daemonize_terminate(const char *pid_file);
00092 
00100 int os_get_random(unsigned char *buf, size_t len);
00101 
00107 unsigned long os_random(void);
00108 
00123 char * os_rel2abs_path(const char *rel_path);
00124 
00134 int os_program_init(void);
00135 
00145 void os_program_deinit(void);
00146 
00158 int os_setenv(const char *name, const char *value, int overwrite);
00159 
00169 int os_unsetenv(const char *name);
00170 
00182 char * os_readfile(const char *name, size_t *len);
00183 
00192 void * os_zalloc(size_t size);
00193 
00194 
00195 /*
00196  * The following functions are wrapper for standard ANSI C or POSIX functions.
00197  * By default, they are just defined to use the standard function name and no
00198  * os_*.c implementation is needed for them. This avoids extra function calls
00199  * by allowing the C pre-processor take care of the function name mapping.
00200  *
00201  * If the target system uses a C library that does not provide these functions,
00202  * build_config.h can be used to define the wrappers to use a different
00203  * function name. This can be done on function-by-function basis since the
00204  * defines here are only used if build_config.h does not define the os_* name.
00205  * If needed, os_*.c file can be used to implement the functions that are not
00206  * included in the C library on the target system. Alternatively,
00207  * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
00208  * these functions need to be implemented in os_*.c file for the target system.
00209  */
00210 
00211 #ifdef OS_NO_C_LIB_DEFINES
00212 
00221 void * os_malloc(size_t size);
00222 
00234 void * os_realloc(void *ptr, size_t size);
00235 
00241 void os_free(void *ptr);
00242 
00254 void * os_memcpy(void *dest, const void *src, size_t n);
00255 
00266 void * os_memmove(void *dest, const void *src, size_t n);
00267 
00276 void * os_memset(void *s, int c, size_t n);
00277 
00288 int os_memcmp(const void *s1, const void *s2, size_t n);
00289 
00298 char * os_strdup(const char *s);
00299 
00306 size_t os_strlen(const char *s);
00307 
00316 int os_strcasecmp(const char *s1, const char *s2);
00317 
00328 int os_strncasecmp(const char *s1, const char *s2, size_t n);
00329 
00337 char * os_strchr(const char *s, int c);
00338 
00346 char * os_strrchr(const char *s, int c);
00347 
00356 int os_strcmp(const char *s1, const char *s2);
00357 
00368 int os_strncmp(const char *s1, const char *s2, size_t n);
00369 
00378 char * os_strncpy(char *dest, const char *src, size_t n);
00379 
00387 char * os_strstr(const char *haystack, const char *needle);
00388 
00411 int os_snprintf(char *str, size_t size, const char *format, ...);
00412 
00413 #else /* OS_NO_C_LIB_DEFINES */
00414 
00415 #ifndef os_malloc
00416 #define os_malloc(s) malloc((s))
00417 #endif
00418 #ifndef os_realloc
00419 #define os_realloc(p, s) realloc((p), (s))
00420 #endif
00421 #ifndef os_free
00422 #define os_free(p) free((p))
00423 #endif
00424 
00425 #ifndef os_memcpy
00426 #define os_memcpy(d, s, n) memcpy((d), (s), (n))
00427 #endif
00428 #ifndef os_memmove
00429 #define os_memmove(d, s, n) memmove((d), (s), (n))
00430 #endif
00431 #ifndef os_memset
00432 #define os_memset(s, c, n) memset(s, c, n)
00433 #endif
00434 #ifndef os_memcmp
00435 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
00436 #endif
00437 
00438 #ifndef os_strdup
00439 #ifdef _MSC_VER
00440 #define os_strdup(s) _strdup(s)
00441 #else
00442 #define os_strdup(s) strdup(s)
00443 #endif
00444 #endif
00445 #ifndef os_strlen
00446 #define os_strlen(s) strlen(s)
00447 #endif
00448 #ifndef os_strcasecmp
00449 #ifdef _MSC_VER
00450 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
00451 #else
00452 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
00453 #endif
00454 #endif
00455 #ifndef os_strncasecmp
00456 #ifdef _MSC_VER
00457 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
00458 #else
00459 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
00460 #endif
00461 #endif
00462 #ifndef os_strchr
00463 #define os_strchr(s, c) strchr((s), (c))
00464 #endif
00465 #ifndef os_strcmp
00466 #define os_strcmp(s1, s2) strcmp((s1), (s2))
00467 #endif
00468 #ifndef os_strncmp
00469 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
00470 #endif
00471 #ifndef os_strncpy
00472 #define os_strncpy(d, s, n) strncpy((d), (s), (n))
00473 #endif
00474 #ifndef os_strrchr
00475 #define os_strrchr(s, c) strrchr((s), (c))
00476 #endif
00477 #ifndef os_strstr
00478 #define os_strstr(h, n) strstr((h), (n))
00479 #endif
00480 
00481 #ifndef os_snprintf
00482 #ifdef _MSC_VER
00483 #define os_snprintf _snprintf
00484 #else
00485 #define os_snprintf snprintf
00486 #endif
00487 #endif
00488 
00489 #endif /* OS_NO_C_LIB_DEFINES */
00490 
00491 
00503 size_t os_strlcpy(char *dest, const char *src, size_t siz);
00504 
00505 
00506 #ifdef OS_REJECT_C_LIB_FUNCTIONS
00507 #define malloc OS_DO_NOT_USE_malloc
00508 #define realloc OS_DO_NOT_USE_realloc
00509 #define free OS_DO_NOT_USE_free
00510 #define memcpy OS_DO_NOT_USE_memcpy
00511 #define memmove OS_DO_NOT_USE_memmove
00512 #define memset OS_DO_NOT_USE_memset
00513 #define memcmp OS_DO_NOT_USE_memcmp
00514 #undef strdup
00515 #define strdup OS_DO_NOT_USE_strdup
00516 #define strlen OS_DO_NOT_USE_strlen
00517 #define strcasecmp OS_DO_NOT_USE_strcasecmp
00518 #define strncasecmp OS_DO_NOT_USE_strncasecmp
00519 #undef strchr
00520 #define strchr OS_DO_NOT_USE_strchr
00521 #undef strcmp
00522 #define strcmp OS_DO_NOT_USE_strcmp
00523 #undef strncmp
00524 #define strncmp OS_DO_NOT_USE_strncmp
00525 #undef strncpy
00526 #define strncpy OS_DO_NOT_USE_strncpy
00527 #define strrchr OS_DO_NOT_USE_strrchr
00528 #define strstr OS_DO_NOT_USE_strstr
00529 #undef snprintf
00530 #define snprintf OS_DO_NOT_USE_snprintf
00531 
00532 #define strcpy OS_DO_NOT_USE_strcpy
00533 #endif /* OS_REJECT_C_LIB_FUNCTIONS */
00534 
00535 #endif /* OS_H */
00536 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:54 2009 for hostapd by  doxygen 1.6.1