ldso: notify the debugger when we're doing a dlopen
[musl.git] / src / dirent / readdir.c
blob569fc70577378836df852b9187a53d1bddbc3cde
1 #include <dirent.h>
2 #include <errno.h>
3 #include <stddef.h>
4 #include "__dirent.h"
5 #include "syscall.h"
7 typedef char dirstream_buf_alignment_check[1-2*(int)(
8 offsetof(struct __dirstream, buf) % sizeof(off_t))];
10 struct dirent *readdir(DIR *dir)
12 struct dirent *de;
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;
20 dir->buf_end = len;
21 dir->buf_pos = 0;
23 de = (void *)(dir->buf + dir->buf_pos);
24 dir->buf_pos += de->d_reclen;
25 dir->tell = de->d_off;
26 return de;
29 weak_alias(readdir, readdir64);