Changeset d4067a7 in mainline
- Timestamp:
- 2017-04-02T13:11:46Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e2e5795
- Parents:
- ce04ea44
- Location:
- uspace/lib/c
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
rce04ea44 rd4067a7 73 73 generic/device/clock_dev.c \ 74 74 generic/device/led_dev.c \ 75 generic/dirent.c \ 75 76 generic/dhcp.c \ 76 77 generic/dnsr.c \ … … 147 148 generic/stdlib.c \ 148 149 generic/udebug.c \ 150 generic/vfs/canonify.c \ 149 151 generic/vfs/vfs.c \ 150 generic/vfs/canonify.c \151 152 generic/rcu.c \ 152 153 generic/setjmp.c \ -
uspace/lib/c/generic/vfs/vfs.c
rce04ea44 rd4067a7 39 39 #include <macros.h> 40 40 #include <stdlib.h> 41 #include <unistd.h>42 41 #include <dirent.h> 43 #include <stdio.h>44 42 #include <sys/types.h> 45 43 #include <ipc/services.h> … … 632 630 } 633 631 634 /** Open directory.635 *636 * @param dirname Directory pathname637 *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 directory671 * @return Non-NULL pointer to directory entry on success. On error returns672 * @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 directory694 */695 void rewinddir(DIR *dirp)696 {697 dirp->pos = 0;698 }699 700 /** Close directory.701 *702 * @param dirp Open directory703 * @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 716 632 int vfs_link(int parent, const char *child, vfs_file_kind_t kind) 717 633 {
Note:
See TracChangeset
for help on using the changeset viewer.