Changeset df4f7c30 in mainline
- Timestamp:
- 2026-03-17T12:37:07Z (27 hours ago)
- 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)
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
-
generic/dirent.c (modified) (2 diffs)
-
include/dirent.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/dirent.c
r7c2a3c7 rdf4f7c30 47 47 }; 48 48 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 */ 54 DIR *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. 50 75 * 51 76 * @param dirname Directory pathname … … 55 80 DIR *opendir(const char *dirname) 56 81 { 57 DIR *dirp = malloc(sizeof(DIR));58 if (!dirp) {59 errno = ENOMEM;60 return NULL;61 }62 63 82 int fd; 64 83 errno_t rc = vfs_lookup(dirname, WALK_DIRECTORY, &fd); 65 84 if (rc != EOK) { 66 free(dirp);67 85 errno = rc; 68 86 return NULL; 69 87 } 70 88 71 rc = vfs_open(fd, MODE_READ); 89 DIR *dirp = opendir_handle(fd); 90 rc = errno; 72 91 if (rc != EOK) { 73 free(dirp);74 92 vfs_put(fd); 75 93 errno = rc; 76 94 return NULL; 77 95 } 78 79 dirp->fd = fd;80 dirp->pos = 0;81 96 return dirp; 82 97 } -
uspace/lib/c/include/dirent.h
r7c2a3c7 rdf4f7c30 46 46 typedef struct __dirstream DIR; 47 47 48 extern DIR *opendir_handle(int handle); 48 49 extern DIR *opendir(const char *); 49 50 extern struct dirent *readdir(DIR *);
Note:
See TracChangeset
for help on using the changeset viewer.
