Changeset 5973fd0 in mainline for uspace/lib/libc/generic/vfs.c


Ignore:
Timestamp:
2008-01-18T23:45:16Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ae78b53
Parents:
62da45a
Message:

Finish implementation of readdir(). Functions from this family are implemented
via using file descriptors for directories. For example, readdir() is
implemented as read() from an open directory. Of course, FS implementations
must understand that they are asked to read a directory and behave accordingly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/vfs.c

    r62da45a r5973fd0  
    244244                return NULL;
    245245        dirp->fd = open(dirname, 0);    /* TODO: must be a directory */
    246         if (!dirp->fd) {
     246        if (dirp->fd < 0) {
    247247                free(dirp);
    248248                return NULL;
    249249        }
    250         dirp->pos = 0;
    251250        return dirp;
    252251}
     
    254253struct dirent *readdir(DIR *dirp)
    255254{
    256         return NULL;    /* TODO */     
     255        ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1);
     256        if (len <= 0)
     257                return NULL;
     258        return &dirp->res;
    257259}
    258260
    259261void rewinddir(DIR *dirp)
    260262{
    261         dirp->pos = 0;
     263        (void) lseek(dirp->fd, 0, SEEK_SET);
    262264}
    263265
Note: See TracChangeset for help on using the changeset viewer.