Changeset df4f7c30 in mainline


Ignore:
Timestamp:
2026-03-17T12:37:07Z (27 hours ago)
Author:
Vít Skalický <skalicky@…>
Children:
128a311
Parents:
7c2a3c7
git-author:
Vít Skalický <skalicky@…> (2026-03-16 14:01:00)
git-committer:
Vít Skalický <skalicky@…> (2026-03-17 12:37:07)
Message:

Add opendir_handle() ot dirent.c

Add function to open a directory by its handle instead of pathname to
dirent.c.

Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    r7c2a3c7 rdf4f7c30  
    4747};
    4848
    49 /** Open directory.
     49/** Open directory by its handle (a.k.a. file descriptor).
     50 *
     51 * @param handle Directory handle
     52 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
     53 */
     54DIR *opendir_handle(int handle)
     55{
     56        DIR *dirp = malloc(sizeof(DIR));
     57        if (!dirp) {
     58                errno = ENOMEM;
     59                return NULL;
     60        }
     61
     62        errno_t rc = vfs_open(handle, MODE_READ);
     63        if (rc != EOK) {
     64                free(dirp);
     65                errno = rc;
     66                return NULL;
     67        }
     68
     69        dirp->fd = handle;
     70        dirp->pos = 0;
     71        return dirp;
     72}
     73
     74/** Open directory by its pathname.
    5075 *
    5176 * @param dirname Directory pathname
     
    5580DIR *opendir(const char *dirname)
    5681{
    57         DIR *dirp = malloc(sizeof(DIR));
    58         if (!dirp) {
    59                 errno = ENOMEM;
    60                 return NULL;
    61         }
    62 
    6382        int fd;
    6483        errno_t rc = vfs_lookup(dirname, WALK_DIRECTORY, &fd);
    6584        if (rc != EOK) {
    66                 free(dirp);
    6785                errno = rc;
    6886                return NULL;
    6987        }
    7088
    71         rc = vfs_open(fd, MODE_READ);
     89        DIR *dirp = opendir_handle(fd);
     90        rc = errno;
    7291        if (rc != EOK) {
    73                 free(dirp);
    7492                vfs_put(fd);
    7593                errno = rc;
    7694                return NULL;
    7795        }
    78 
    79         dirp->fd = fd;
    80         dirp->pos = 0;
    8196        return dirp;
    8297}
  • uspace/lib/c/include/dirent.h

    r7c2a3c7 rdf4f7c30  
    4646typedef struct __dirstream DIR;
    4747
     48extern DIR *opendir_handle(int handle);
    4849extern DIR *opendir(const char *);
    4950extern struct dirent *readdir(DIR *);
Note: See TracChangeset for help on using the changeset viewer.