Rev 2694 | Rev 2700 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2694 | Rev 2699 | ||
---|---|---|---|
Line 241... | Line 241... | ||
241 | { |
241 | { |
242 | DIR *dirp = malloc(sizeof(DIR)); |
242 | DIR *dirp = malloc(sizeof(DIR)); |
243 | if (!dirp) |
243 | if (!dirp) |
244 | return NULL; |
244 | return NULL; |
245 | dirp->fd = open(dirname, 0); /* TODO: must be a directory */ |
245 | dirp->fd = open(dirname, 0); /* TODO: must be a directory */ |
246 | if (!dirp->fd) { |
246 | if (dirp->fd < 0) { |
247 | free(dirp); |
247 | free(dirp); |
248 | return NULL; |
248 | return NULL; |
249 | } |
249 | } |
250 | dirp->pos = 0; |
- | |
251 | return dirp; |
250 | return dirp; |
252 | } |
251 | } |
253 | 252 | ||
254 | struct dirent *readdir(DIR *dirp) |
253 | struct dirent *readdir(DIR *dirp) |
255 | { |
254 | { |
- | 255 | ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); |
|
- | 256 | if (len <= 0) |
|
256 | return NULL; /* TODO */ |
257 | return NULL; |
- | 258 | return &dirp->res; |
|
257 | } |
259 | } |
258 | 260 | ||
259 | void rewinddir(DIR *dirp) |
261 | void rewinddir(DIR *dirp) |
260 | { |
262 | { |
261 | dirp->pos = 0; |
263 | (void) lseek(dirp->fd, 0, SEEK_SET); |
262 | } |
264 | } |
263 | 265 | ||
264 | int closedir(DIR *dirp) |
266 | int closedir(DIR *dirp) |
265 | { |
267 | { |
266 | (void) close(dirp->fd); |
268 | (void) close(dirp->fd); |