⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gethos~2.c

📁 操作系统源代码
💻 C
字号:
/* gethostname(2) system call emulation */#include <sys/types.h>#include <fcntl.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <net/gen/netdb.h>#define HOSTNAME_FILE "/etc/hostname.file"int gethostname(char *buf, size_t len){	int fd;	int r;	char *nl;	if ((fd= open(HOSTNAME_FILE, O_RDONLY)) < 0) return -1;	r= read(fd, buf, len);	close(fd);	if (r == -1) return -1;	buf[len-1]= '\0';	if ((nl= strchr(buf, '\n')) != NULL) *nl= '\0';	return 0;}

⌨️ 快捷键说明

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