| 1 | #include <dirent.h> |
| 2 | #include <errno.h> |
| 3 | #include <stddef.h> |
| 4 | #include "__dirent.h" |
| 5 | #include "syscall.h" |
| 6 | |
| 7 | typedef char dirstream_buf_alignment_check[1-2*(int)( |
| 8 | 	offsetof(struct __dirstream, buf) % sizeof(off_t))]; |
| 9 | |
| 10 | struct dirent *readdir(DIR *dir) |
| 11 | { |
| 12 | 	struct dirent *de; |
| 13 | 	 |
| 14 | 	if (dir->buf_pos >= dir->buf_end) { |
| 15 | 		int len = __syscall(SYS_getdents, dir->fd, dir->buf, sizeof dir->buf); |
| 16 | 		if (len <= 0) { |
| 17 | 			if (len < 0 && len != -ENOENT) errno = -len; |
| 18 | 			return 0; |
| 19 | 		} |
| 20 | 		dir->buf_end = len; |
| 21 | 		dir->buf_pos = 0; |
| 22 | 	} |
| 23 | 	de = (void *)(dir->buf + dir->buf_pos); |
| 24 | 	dir->buf_pos += de->d_reclen; |
| 25 | 	dir->tell = de->d_off; |
| 26 | 	return de; |
| 27 | } |