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

📄 strlist.c

📁 UNIX环境高级编程第二版(英文版)配书的源代码
💻 C
字号:
#include "apue.h"#include <fcntl.h>#include <stropts.h>#include <sys/conf.h>intmain(int argc, char *argv[]){	int					fd, i, nmods;	struct str_list		list;	if (argc != 2)		err_quit("usage: %s <pathname>", argv[0]);	if ((fd = open(argv[1], O_RDONLY)) < 0)		err_sys("can't open %s", argv[1]);	if (isastream(fd) == 0)		err_quit("%s is not a stream", argv[1]);	/*	 * Fetch number of modules.	 */	if ((nmods = ioctl(fd, I_LIST, (void *) 0)) < 0)		err_sys("I_LIST error for nmods");	printf("#modules = %d\n", nmods);	/*	 * Allocate storage for all the module names.	 */	list.sl_modlist = calloc(nmods, sizeof(struct str_mlist));	if (list.sl_modlist == NULL)		err_sys("calloc error");	list.sl_nmods = nmods;	/*	 * Fetch the module names.	 */	if (ioctl(fd, I_LIST, &list) < 0)		err_sys("I_LIST error for list");	/*	 * Print the names.	 */	for (i = 1; i <= nmods; i++)		printf("  %s: %s\n", (i == nmods) ? "driver" : "module",		  list.sl_modlist++->l_name);	exit(0);}

⌨️ 快捷键说明

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