wpa_supplicant / hostapd
2.5
|
OS specific functions. More...
Go to the source code of this file.
Data Structures | |
struct | os_time |
struct | os_reltime |
struct | os_tm |
Typedefs | |
typedef long | os_time_t |
Functions | |
void | os_sleep (os_time_t sec, os_time_t usec) |
Sleep (sec, usec) More... | |
int | os_get_time (struct os_time *t) |
Get current time (sec, usec) More... | |
int | os_get_reltime (struct os_reltime *t) |
Get relative time (sec, usec) More... | |
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. More... | |
int | os_gmtime (os_time_t t, struct os_tm *tm) |
int | os_daemonize (const char *pid_file) |
Run in the background (detach from the controlling terminal) More... | |
void | os_daemonize_terminate (const char *pid_file) |
Stop running in the background (remove pid file) More... | |
int | os_get_random (unsigned char *buf, size_t len) |
Get cryptographically strong pseudo random data. More... | |
unsigned long | os_random (void) |
Get pseudo random value (not necessarily very strong) More... | |
char * | os_rel2abs_path (const char *rel_path) |
Get an absolute path for a file. More... | |
int | os_program_init (void) |
Program initialization (called at start) More... | |
void | os_program_deinit (void) |
Program deinitialization (called just before exit) More... | |
int | os_setenv (const char *name, const char *value, int overwrite) |
Set environment variable. More... | |
int | os_unsetenv (const char *name) |
Delete environent variable. More... | |
char * | os_readfile (const char *name, size_t *len) |
Read a file to an allocated memory buffer. More... | |
int | os_file_exists (const char *fname) |
Check whether the specified file exists. More... | |
int | os_fdatasync (FILE *stream) |
Sync a file's (for a given stream) state with storage device. More... | |
void * | os_zalloc (size_t size) |
Allocate and zero memory. More... | |
size_t | os_strlcpy (char *dest, const char *src, size_t siz) |
Copy a string with size bound and NUL-termination. More... | |
int | os_memcmp_const (const void *a, const void *b, size_t len) |
Constant time memory comparison. More... | |
int | os_exec (const char *program, const char *arg, int wait_completion) |
Execute an external program. More... | |
OS specific functions.
int os_daemonize | ( | const char * | pid_file | ) |
Run in the background (detach from the controlling terminal)
pid_file | File name to write the process ID to or NULL to skip this |
void os_daemonize_terminate | ( | const char * | pid_file | ) |
Stop running in the background (remove pid file)
pid_file | File name to write the process ID to or NULL to skip this |
int os_exec | ( | const char * | program, |
const char * | arg, | ||
int | wait_completion | ||
) |
Execute an external program.
program | Path to the program |
arg | Command line argument string |
wait_completion | Whether to wait until the program execution completes |
int os_fdatasync | ( | FILE * | stream | ) |
Sync a file's (for a given stream) state with storage device.
stream | the stream to be flushed |
int os_file_exists | ( | const char * | fname | ) |
Check whether the specified file exists.
fname | Path and name of the file |
int os_get_random | ( | unsigned char * | buf, |
size_t | len | ||
) |
Get cryptographically strong pseudo random data.
buf | Buffer for pseudo random data |
len | Length of the buffer |
int os_get_reltime | ( | struct os_reltime * | t | ) |
Get relative time (sec, usec)
t | Pointer to buffer for the time |
int os_get_time | ( | struct os_time * | t | ) |
Get current time (sec, usec)
t | Pointer to buffer for the time |
int os_memcmp_const | ( | const void * | a, |
const void * | b, | ||
size_t | len | ||
) |
Constant time memory comparison.
a | First buffer to compare |
b | Second buffer to compare |
len | Number of octets to compare |
This function is meant for comparing passwords or hash values where difference in execution time could provide external observer information about the location of the difference in the memory buffers. The return value does not behave like os_memcmp(), i.e., os_memcmp_const() cannot be used to sort items into a defined order. Unlike os_memcmp(), execution time of os_memcmp_const() does not depend on the contents of the compared memory buffers, but only on the total compared length.
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.
year | Four digit year |
month | Month (1 .. 12) |
day | Day of month (1 .. 31) |
hour | Hour (0 .. 23) |
min | Minute (0 .. 59) |
sec | Second (0 .. 60) |
t | Buffer for returning calendar time representation (seconds since 1970-01-01 00:00:00) |
Note: The result is in seconds from Epoch, i.e., in UTC, not in local time which is used by POSIX mktime().
void os_program_deinit | ( | void | ) |
Program deinitialization (called just before exit)
This function is called just before a program exists. If there are any OS specific processing, e.g., freeing resourced allocated in os_program_init(), it should be done here. It is also acceptable for this function to do nothing.
int os_program_init | ( | void | ) |
Program initialization (called at start)
This function is called when a programs starts. If there are any OS specific processing that is needed, it can be placed here. It is also acceptable to just return 0 if not special processing is needed.
unsigned long os_random | ( | void | ) |
Get pseudo random value (not necessarily very strong)
char* os_readfile | ( | const char * | name, |
size_t * | len | ||
) |
Read a file to an allocated memory buffer.
name | Name of the file to read |
len | For returning the length of the allocated buffer |
This function allocates memory and reads the given file to this buffer. Both binary and text files can be read with this function. The caller is responsible for freeing the returned buffer with os_free().
char* os_rel2abs_path | ( | const char * | rel_path | ) |
Get an absolute path for a file.
rel_path | Relative path to a file |
This function tries to convert a relative path of a file to an absolute path in order for the file to be found even if current working directory has changed. The returned value is allocated and caller is responsible for freeing it. It is acceptable to just return the same path in an allocated buffer, e.g., return strdup(rel_path). This function is only used to find configuration files when os_daemonize() may have changed the current working directory and relative path would be pointing to a different location.
int os_setenv | ( | const char * | name, |
const char * | value, | ||
int | overwrite | ||
) |
Set environment variable.
name | Name of the variable |
value | Value to set to the variable |
overwrite | Whether existing variable should be overwritten |
This function is only used for wpa_cli action scripts. OS wrapper does not need to implement this if such functionality is not needed.
void os_sleep | ( | os_time_t | sec, |
os_time_t | usec | ||
) |
Sleep (sec, usec)
sec | Number of seconds to sleep |
usec | Number of microseconds to sleep |
size_t os_strlcpy | ( | char * | dest, |
const char * | src, | ||
size_t | siz | ||
) |
Copy a string with size bound and NUL-termination.
dest | Destination |
src | Source |
siz | Size of the target buffer |
This function matches in behavior with the strlcpy(3) function in OpenBSD.
int os_unsetenv | ( | const char * | name | ) |
Delete environent variable.
name | Name of the variable |
This function is only used for wpa_cli action scripts. OS wrapper does not need to implement this if such functionality is not needed.
void* os_zalloc | ( | size_t | size | ) |
Allocate and zero memory.
size | Number of bytes to allocate |
Caller is responsible for freeing the returned buffer with os_free().