os.h
Go to the documentation of this file.
00001 /*
00002  * OS specific functions
00003  * Copyright (c) 2005-2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #ifndef OS_H
00016 #define OS_H
00017 
00018 typedef long os_time_t;
00019 
00025 void os_sleep(os_time_t sec, os_time_t usec);
00026 
00027 struct os_time {
00028         os_time_t sec;
00029         os_time_t usec;
00030 };
00031 
00037 int os_get_time(struct os_time *t);
00038 
00039 
00040 /* Helper macros for handling struct os_time */
00041 
00042 #define os_time_before(a, b) \
00043         ((a)->sec < (b)->sec || \
00044          ((a)->sec == (b)->sec && (a)->usec < (b)->usec))
00045 
00046 #define os_time_sub(a, b, res) do { \
00047         (res)->sec = (a)->sec - (b)->sec; \
00048         (res)->usec = (a)->usec - (b)->usec; \
00049         if ((res)->usec < 0) { \
00050                 (res)->sec--; \
00051                 (res)->usec += 1000000; \
00052         } \
00053 } while (0)
00054 
00070 int os_mktime(int year, int month, int day, int hour, int min, int sec,
00071               os_time_t *t);
00072 
00073 
00079 int os_daemonize(const char *pid_file);
00080 
00085 void os_daemonize_terminate(const char *pid_file);
00086 
00093 int os_get_random(unsigned char *buf, size_t len);
00094 
00099 unsigned long os_random(void);
00100 
00114 char * os_rel2abs_path(const char *rel_path);
00115 
00124 int os_program_init(void);
00125 
00134 void os_program_deinit(void);
00135 
00146 int os_setenv(const char *name, const char *value, int overwrite);
00147 
00156 int os_unsetenv(const char *name);
00157 
00168 char * os_readfile(const char *name, size_t *len);
00169 
00177 void * os_zalloc(size_t size);
00178 
00179 
00180 /*
00181  * The following functions are wrapper for standard ANSI C or POSIX functions.
00182  * By default, they are just defined to use the standard function name and no
00183  * os_*.c implementation is needed for them. This avoids extra function calls
00184  * by allowing the C pre-processor take care of the function name mapping.
00185  *
00186  * If the target system uses a C library that does not provide these functions,
00187  * build_config.h can be used to define the wrappers to use a different
00188  * function name. This can be done on function-by-function basis since the
00189  * defines here are only used if build_config.h does not define the os_* name.
00190  * If needed, os_*.c file can be used to implement the functions that are not
00191  * included in the C library on the target system. Alternatively,
00192  * OS_NO_C_LIB_DEFINES can be defined to skip all defines here in which case
00193  * these functions need to be implemented in os_*.c file for the target system.
00194  */
00195 
00196 #ifdef OS_NO_C_LIB_DEFINES
00197 
00205 void * os_malloc(size_t size);
00206 
00217 void * os_realloc(void *ptr, size_t size);
00218 
00223 void os_free(void *ptr);
00224 
00235 void * os_memcpy(void *dest, const void *src, size_t n);
00236 
00246 void * os_memmove(void *dest, const void *src, size_t n);
00247 
00255 void * os_memset(void *s, int c, size_t n);
00256 
00266 int os_memcmp(const void *s1, const void *s2, size_t n);
00267 
00275 char * os_strdup(const char *s);
00276 
00282 size_t os_strlen(const char *s);
00283 
00291 int os_strcasecmp(const char *s1, const char *s2);
00292 
00302 int os_strncasecmp(const char *s1, const char *s2, size_t n);
00303 
00310 char * os_strchr(const char *s, int c);
00311 
00318 char * os_strrchr(const char *s, int c);
00319 
00327 int os_strcmp(const char *s1, const char *s2);
00328 
00338 int os_strncmp(const char *s1, const char *s2, size_t n);
00339 
00347 char * os_strncpy(char *dest, const char *src, size_t n);
00348 
00355 char * os_strstr(const char *haystack, const char *needle);
00356 
00378 int os_snprintf(char *str, size_t size, const char *format, ...);
00379 
00380 #else /* OS_NO_C_LIB_DEFINES */
00381 
00382 #ifdef WPA_TRACE
00383 void * os_malloc(size_t size);
00384 void * os_realloc(void *ptr, size_t size);
00385 void os_free(void *ptr);
00386 char * os_strdup(const char *s);
00387 #else /* WPA_TRACE */
00388 #ifndef os_malloc
00389 #define os_malloc(s) malloc((s))
00390 #endif
00391 #ifndef os_realloc
00392 #define os_realloc(p, s) realloc((p), (s))
00393 #endif
00394 #ifndef os_free
00395 #define os_free(p) free((p))
00396 #endif
00397 #ifndef os_strdup
00398 #ifdef _MSC_VER
00399 #define os_strdup(s) _strdup(s)
00400 #else
00401 #define os_strdup(s) strdup(s)
00402 #endif
00403 #endif
00404 #endif /* WPA_TRACE */
00405 
00406 #ifndef os_memcpy
00407 #define os_memcpy(d, s, n) memcpy((d), (s), (n))
00408 #endif
00409 #ifndef os_memmove
00410 #define os_memmove(d, s, n) memmove((d), (s), (n))
00411 #endif
00412 #ifndef os_memset
00413 #define os_memset(s, c, n) memset(s, c, n)
00414 #endif
00415 #ifndef os_memcmp
00416 #define os_memcmp(s1, s2, n) memcmp((s1), (s2), (n))
00417 #endif
00418 
00419 #ifndef os_strlen
00420 #define os_strlen(s) strlen(s)
00421 #endif
00422 #ifndef os_strcasecmp
00423 #ifdef _MSC_VER
00424 #define os_strcasecmp(s1, s2) _stricmp((s1), (s2))
00425 #else
00426 #define os_strcasecmp(s1, s2) strcasecmp((s1), (s2))
00427 #endif
00428 #endif
00429 #ifndef os_strncasecmp
00430 #ifdef _MSC_VER
00431 #define os_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n))
00432 #else
00433 #define os_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n))
00434 #endif
00435 #endif
00436 #ifndef os_strchr
00437 #define os_strchr(s, c) strchr((s), (c))
00438 #endif
00439 #ifndef os_strcmp
00440 #define os_strcmp(s1, s2) strcmp((s1), (s2))
00441 #endif
00442 #ifndef os_strncmp
00443 #define os_strncmp(s1, s2, n) strncmp((s1), (s2), (n))
00444 #endif
00445 #ifndef os_strncpy
00446 #define os_strncpy(d, s, n) strncpy((d), (s), (n))
00447 #endif
00448 #ifndef os_strrchr
00449 #define os_strrchr(s, c) strrchr((s), (c))
00450 #endif
00451 #ifndef os_strstr
00452 #define os_strstr(h, n) strstr((h), (n))
00453 #endif
00454 
00455 #ifndef os_snprintf
00456 #ifdef _MSC_VER
00457 #define os_snprintf _snprintf
00458 #else
00459 #define os_snprintf snprintf
00460 #endif
00461 #endif
00462 
00463 #endif /* OS_NO_C_LIB_DEFINES */
00464 
00465 
00476 size_t os_strlcpy(char *dest, const char *src, size_t siz);
00477 
00478 
00479 #ifdef OS_REJECT_C_LIB_FUNCTIONS
00480 #define malloc OS_DO_NOT_USE_malloc
00481 #define realloc OS_DO_NOT_USE_realloc
00482 #define free OS_DO_NOT_USE_free
00483 #define memcpy OS_DO_NOT_USE_memcpy
00484 #define memmove OS_DO_NOT_USE_memmove
00485 #define memset OS_DO_NOT_USE_memset
00486 #define memcmp OS_DO_NOT_USE_memcmp
00487 #undef strdup
00488 #define strdup OS_DO_NOT_USE_strdup
00489 #define strlen OS_DO_NOT_USE_strlen
00490 #define strcasecmp OS_DO_NOT_USE_strcasecmp
00491 #define strncasecmp OS_DO_NOT_USE_strncasecmp
00492 #undef strchr
00493 #define strchr OS_DO_NOT_USE_strchr
00494 #undef strcmp
00495 #define strcmp OS_DO_NOT_USE_strcmp
00496 #undef strncmp
00497 #define strncmp OS_DO_NOT_USE_strncmp
00498 #undef strncpy
00499 #define strncpy OS_DO_NOT_USE_strncpy
00500 #define strrchr OS_DO_NOT_USE_strrchr
00501 #define strstr OS_DO_NOT_USE_strstr
00502 #undef snprintf
00503 #define snprintf OS_DO_NOT_USE_snprintf
00504 
00505 #define strcpy OS_DO_NOT_USE_strcpy
00506 #endif /* OS_REJECT_C_LIB_FUNCTIONS */
00507 
00508 #endif /* OS_H */


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:35