c - Is it possible to implement readdir() in Ubuntu 12.10 (kernel 3.5)? -
in 8.6 of k & r
, authors implemented simple version of readdir()
. code follows:
#include <sys/dir.h> /* local directory structure */ /* readdir: read directory entries in sequence */ dirent *readdir(dir *dp) { struct direct dirbuf; /* local directory structure */ static dirent d; /* return: portable structure */ while (read(dp->fd, (char *) &dirbuf, sizeof(dirbuf)) == sizeof(dirbuf)) { if (dirbuf.d_ino == 0) /* slot not in use */ continue; d.ino = dirbuf.d_ino; strncpy(d.name, dirbuf.d_name, dirsiz); d.name[dirsiz] = '\0'; /* ensure termination */ return &d; } return null; }
in opinion, in line read()
, dp->fd
file descriptor of directory. authors used read()
struct direct
directly directory file.
however, in ubuntu, not possible read directory file. when tried read directory, got strange.
i read in apue in systems, action not allowed. there other ways realize own readdir()
?
you looking @ code 40 years ago. directories not implemented on modern platform. read documentation filesystem (ext4 if on linux) if need write code manipulate it.
Comments
Post a Comment