データ構造 | |
struct | dir_buf |
関数 | |
DIR * | opendir (const char *dname) |
dirent * | readdir (DIR *dir) |
long | telldir (const DIR *dir) long telldir(DIR *dir) |
int | seekdir (DIR *dir, long ofs) void seekdir(DIR *dir |
DIR* opendir | ( | const char * | dname | ) |
repdir_getdirentries.c の 70 行で定義されています。
参照先 errno.
00071 { 00072 struct dir_buf *d; 00073 struct stat sb; 00074 d = malloc(sizeof(*d)); 00075 if (d == NULL) { 00076 errno = ENOMEM; 00077 return NULL; 00078 } 00079 d->fd = open(dname, O_RDONLY); 00080 if (d->fd == -1) { 00081 free(d); 00082 return NULL; 00083 } 00084 if (fstat(d->fd, &sb) < 0) { 00085 close(d->fd); 00086 free(d); 00087 return NULL; 00088 } 00089 if (!S_ISDIR(sb.st_mode)) { 00090 close(d->fd); 00091 free(d); 00092 errno = ENOTDIR; 00093 return NULL; 00094 } 00095 d->ofs = 0; 00096 d->seekpos = 0; 00097 d->nbytes = 0; 00098 return (DIR *)d; 00099 }
struct dirent* readdir | ( | DIR * | dir | ) |
repdir_getdirentries.c の 101 行で定義されています。
参照先 dir_buf::buf・dir_buf::fd・dir_buf::nbytes・dir_buf::ofs・dir_buf::seekpos.
00102 { 00103 struct dir_buf *d = (struct dir_buf *)dir; 00104 struct dirent *de; 00105 00106 if (d->ofs >= d->nbytes) { 00107 long pos; 00108 d->nbytes = getdirentries(d->fd, d->buf, DIR_BUF_SIZE, &pos); 00109 d->seekpos = pos; 00110 d->ofs = 0; 00111 } 00112 if (d->ofs >= d->nbytes) { 00113 return NULL; 00114 } 00115 de = (struct dirent *)&d->buf[d->ofs]; 00116 d->ofs += de->d_reclen; 00117 return de; 00118 }
long telldir | ( | const DIR * | dir | ) |
repdir_getdirentries.c の 121 行で定義されています。
参照先 dir_buf::fd・dir_buf::nbytes・dir_buf::ofs・dir_buf::seekpos.
00125 { 00126 struct dir_buf *d = (struct dir_buf *)dir; 00127 if (d->ofs >= d->nbytes) { 00128 d->seekpos = lseek(d->fd, 0, SEEK_CUR); 00129 d->ofs = 0; 00130 d->nbytes = 0; 00131 } 00132 /* this relies on seekpos always being a multiple of 00133 DIR_BUF_SIZE. Is that always true on BSD systems? */ 00134 if (d->seekpos & (DIR_BUF_SIZE-1)) { 00135 abort(); 00136 } 00137 return d->seekpos + d->ofs; 00138 }
int seekdir | ( | DIR * | dir, | |
long | ofs | |||
) |