📄 os_unix.c
字号:
/* * wpa_supplicant/hostapd / OS specific functions for UNIX/POSIX systems * 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. */#include "includes.h"#include "os.h"void os_sleep(os_time_t sec, os_time_t usec){ if (sec) sleep(sec); if (usec) usleep(usec);}int os_get_time(struct os_time *t){ int res; struct timeval tv; res = gettimeofday(&tv, NULL); t->sec = tv.tv_sec; t->usec = tv.tv_usec; return res;}int os_daemonize(const char *pid_file){ if (daemon(0, 0)) { perror("daemon"); return -1; } if (pid_file) { FILE *f = fopen(pid_file, "w"); if (f) { fprintf(f, "%u\n", getpid()); fclose(f); } } return -0;}void os_daemonize_terminate(const char *pid_file){ if (pid_file) unlink(pid_file);}int os_get_random(unsigned char *buf, size_t len){ FILE *f; size_t rc; f = fopen("/dev/urandom", "r"); if (f == NULL) { printf("Could not open /dev/urandom.\n"); return -1; } rc = fread(buf, 1, len, f); fclose(f); return rc != len ? -1 : 0;}unsigned long os_random(void){ return random();}char * os_rel2abs_path(const char *rel_path){ char *buf = NULL, *cwd, *ret; size_t len = 128, cwd_len, rel_len, ret_len; if (rel_path[0] == '/') return strdup(rel_path); for (;;) { buf = malloc(len); if (buf == NULL) return NULL; cwd = getcwd(buf, len); if (cwd == NULL) { free(buf); if (errno != ERANGE) { return NULL; } len *= 2; } else { break; } } cwd_len = strlen(cwd); rel_len = strlen(rel_path); ret_len = cwd_len + 1 + rel_len + 1; ret = malloc(ret_len); if (ret) { memcpy(ret, cwd, cwd_len); ret[cwd_len] = '/'; memcpy(ret + cwd_len + 1, rel_path, rel_len); ret[ret_len - 1] = '\0'; } free(buf); return ret;}int os_program_init(void){ return 0;}void os_program_deinit(void){}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -