Changeset d4067a7 in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2017-04-02T13:11:46Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1e2e5795
Parents:
ce04ea44
Message:

Separate the dirent functions to dirent.c

File:
1 edited

Legend:

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

    rce04ea44 rd4067a7  
    3939#include <macros.h>
    4040#include <stdlib.h>
    41 #include <unistd.h>
    4241#include <dirent.h>
    43 #include <stdio.h>
    4442#include <sys/types.h>
    4543#include <ipc/services.h>
     
    632630}
    633631
    634 /** Open directory.
    635  *
    636  * @param dirname Directory pathname
    637  *
    638  * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
    639  */
    640 DIR *opendir(const char *dirname)
    641 {
    642         DIR *dirp = malloc(sizeof(DIR));
    643         if (!dirp) {
    644                 errno = ENOMEM;
    645                 return NULL;
    646         }
    647        
    648         int fd = vfs_lookup(dirname, WALK_DIRECTORY);
    649         if (fd < 0) {
    650                 free(dirp);
    651                 errno = fd;
    652                 return NULL;
    653         }
    654        
    655         int rc = vfs_open(fd, MODE_READ);
    656         if (rc < 0) {
    657                 free(dirp);
    658                 vfs_put(fd);
    659                 errno = rc;
    660                 return NULL;
    661         }
    662        
    663         dirp->fd = fd;
    664         dirp->pos = 0;
    665         return dirp;
    666 }
    667 
    668 /** Read directory entry.
    669  *
    670  * @param dirp Open directory
    671  * @return Non-NULL pointer to directory entry on success. On error returns
    672  *         @c NULL and sets errno.
    673  */
    674 struct dirent *readdir(DIR *dirp)
    675 {
    676         int rc;
    677         ssize_t len = 0;
    678        
    679         rc = vfs_read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0],
    680             NAME_MAX + 1, &len);
    681         if (rc != EOK) {
    682                 errno = rc;
    683                 return NULL;
    684         }
    685        
    686         dirp->pos += len;
    687        
    688         return &dirp->res;
    689 }
    690 
    691 /** Rewind directory position to the beginning.
    692  *
    693  * @param dirp Open directory
    694  */
    695 void rewinddir(DIR *dirp)
    696 {
    697         dirp->pos = 0;
    698 }
    699 
    700 /** Close directory.
    701  *
    702  * @param dirp Open directory
    703  * @return 0 on success. On error returns -1 and sets errno.
    704  */
    705 int closedir(DIR *dirp)
    706 {
    707         int rc;
    708        
    709         rc = vfs_put(dirp->fd);
    710         free(dirp);
    711 
    712         /* On error errno was set by close() */
    713         return rc;
    714 }
    715 
    716632int vfs_link(int parent, const char *child, vfs_file_kind_t kind)
    717633{
Note: See TracChangeset for help on using the changeset viewer.