Changeset 128a311 in mainline for uspace/lib/c/generic/dirent.c


Ignore:
Timestamp:
2026-03-17T12:37:31Z (32 hours ago)
Author:
Vít Skalický <skalicky@…>
Children:
8c35ebd
Parents:
df4f7c30
git-author:
Vít Skalický <skalicky@…> (2026-03-16 14:27:57)
git-committer:
Vít Skalický <skalicky@…> (2026-03-17 12:37:31)
Message:

Use vfs_clone in opendir_handle()

Before, the handle passed to it would be saved and later put by
closedir. However, the handle is owned by the caller of opendir_handle()
and it their responsibility to put it, not our.

File:
1 edited

Legend:

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

    rdf4f7c30 r128a311  
    4747};
    4848
    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  */
    54 DIR *opendir_handle(int handle)
     49/** Like opendir_handle, but takes ownership of the handle if successful. */
     50static DIR *opendir_internal(int handle)
    5551{
    5652        DIR *dirp = malloc(sizeof(DIR));
     
    7268}
    7369
     70/** Open directory by its handle (a.k.a. file descriptor).
     71 *
     72 * @param handle Directory handle
     73 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
     74 */
     75DIR *opendir_handle(int handle)
     76{
     77        int my_handle;
     78        errno_t rc = vfs_clone(handle, -1, false, &my_handle); // Clone the file handle, otherwise closedir would put the
     79                                                               // handle that was passed to us here by the caller and that we don't own.
     80        if (rc != EOK) {
     81                errno = rc;
     82                return NULL;
     83        }
     84
     85        DIR *dirp = opendir_internal(my_handle);
     86        rc = errno;
     87        if (rc != EOK) {
     88                vfs_put(my_handle);
     89                errno = rc;
     90                return NULL;
     91        }
     92        return dirp;
     93}
     94
    7495/** Open directory by its pathname.
    7596 *
     
    87108        }
    88109
    89         DIR *dirp = opendir_handle(fd);
     110        DIR *dirp = opendir_internal(fd);
    90111        rc = errno;
    91112        if (rc != EOK) {
     
    97118}
    98119
    99 /** Read directory entry.
     120/** Read current directory entry and advance to the next one.
    100121 *
    101122 * @param dirp Open directory
Note: See TracChangeset for help on using the changeset viewer.