readdir.c

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 51 行

C
51
字号
/* Copyright (c) 1982 Regents of the University of California */static char sccsid[] = "@(#)readdir.c 4.3 8/8/82";#include <sys/types.h>#include <dir.h>/* * read an old stlye directory entry and present it as a new one */#define	ODIRSIZ	14struct	olddirect {	ino_t	od_ino;	char	od_name[ODIRSIZ];};/* * get next entry in a directory. */struct direct *readdir(dirp)	register DIR *dirp;{	register struct olddirect *dp;	static struct direct dir;	for (;;) {		if (dirp->dd_loc == 0) {			dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 			    DIRBLKSIZ);			if (dirp->dd_size <= 0)				return NULL;		}		if (dirp->dd_loc >= dirp->dd_size) {			dirp->dd_loc = 0;			continue;		}		dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);		dirp->dd_loc += sizeof(struct olddirect);		if (dp->od_ino == 0)			continue;		dir.d_ino = dp->od_ino;		strncpy(dir.d_name, dp->od_name, ODIRSIZ);		dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */		dir.d_namlen = strlen(dir.d_name);		dir.d_reclen = DIRBLKSIZ;		return (&dir);	}}

⌨️ 快捷键说明

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