os.h

来自「hostapd源代码」· C头文件 代码 · 共 119 行

H
119
字号
/* * wpa_supplicant/hostapd / OS specific functions * Copyright (c) 2005, Jouni Malinen <jkmaline@cc.hut.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of BSD * license. * * See README and COPYING for more details. */#ifndef OS_H#define OS_Htypedef long os_time_t;/** * os_sleep - Sleep (sec, usec) * @sec: Number of seconds to sleep * @usec: Number of microseconds to sleep */void os_sleep(os_time_t sec, os_time_t usec);struct os_time {	os_time_t sec;	os_time_t usec;};/** * os_get_time - Get current time (sec, usec) * @t: Pointer to buffer for the time * Returns: 0 on success, -1 on failure */int os_get_time(struct os_time *t);/* Helper macros for handling struct os_time */#define os_time_before(a, b) \	((a)->sec < (b)->sec || \	 ((a)->sec == (b)->sec && (a)->usec < (b)->usec))#define os_time_sub(a, b, res) do { \	(res)->sec = (a)->sec - (b)->sec; \	(res)->usec = (a)->usec - (b)->usec; \	if ((res)->usec < 0) { \		(res)->sec--; \		(res)->usec += 1000000; \	} \} while (0)/** * os_daemonize - Run in the background (detach from the controlling terminal) * @pid_file: File name to write the process ID to or %NULL to skip this * Returns: 0 on success, -1 on failure */int os_daemonize(const char *pid_file);/** * os_daemonize_terminate - Stop running in the background (remove pid file) * @pid_file: File name to write the process ID to or %NULL to skip this */void os_daemonize_terminate(const char *pid_file);/** * os_get_random - Get cryptographically strong pseudo random data * @buf: Buffer for pseudo random data * @len: Length of the buffer * Returns: 0 on success, -1 on failure */int os_get_random(unsigned char *buf, size_t len);/** * os_random - Get pseudo random value (not necessarily very strong) * Returns: Pseudo random value */unsigned long os_random(void);/** * os_rel2abs_path - Get an absolute path for a file * @rel_path: Relative path to a file * Returns: Absolute path for the file or %NULL on failure * * 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. */char * os_rel2abs_path(const char *rel_path);/** * os_program_init - Program initialization (called at start) * Returns: 0 on success, -1 on failure * * 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. */int os_program_init(void);/** * os_program_deinit - 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. */void os_program_deinit(void);#endif /* OS_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?