summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/lib/readdir.c
blob: 689f5d08bd0fc215df7fc3d1513e4c0d39768c03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "dietdirent.h"
#include <unistd.h>
#include <dirent.h>
#include <stdlib.h>

struct dirent* readdir(DIR *d) {
  if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) {
    int res=getdents(d->fd,(struct dirent*)d->buf,1023);
    if (res<=0) return 0;
    d->num=res; d->cur=0;
  }
  return (struct dirent*)(d->buf+d->cur);
}