summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-31 16:10:13 +0100
committerAnton Kling <anton@kling.gg>2024-12-31 16:10:13 +0100
commit4b1577f80962e8cce055fdb4d6f641187df0bbe0 (patch)
tree9bc62b9478650a244158cd9ae3eb1db41eb7c556
parent934d8d5ee4c2ce756fea79d74d8562ad597cc5e5 (diff)
libc: opendir should not keep a internal offset
-rw-r--r--include/dirent.h1
-rw-r--r--userland/libc/dirent/opendir.c2
-rw-r--r--userland/libc/dirent/readdir.c13
3 files changed, 5 insertions, 11 deletions
diff --git a/include/dirent.h b/include/dirent.h
index 66e8e8f..be9c928 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -17,7 +17,6 @@ struct dirent {
typedef struct {
int fd;
struct dirent internal_direntry;
- int dir_num;
} DIR;
#ifndef KERNEL
diff --git a/userland/libc/dirent/opendir.c b/userland/libc/dirent/opendir.c
index efe8b6d..8f5d818 100644
--- a/userland/libc/dirent/opendir.c
+++ b/userland/libc/dirent/opendir.c
@@ -6,7 +6,6 @@ DIR *fdopendir(int fd) {
return NULL;
}
rc->fd = fd;
- rc->dir_num = 0;
return rc;
}
@@ -20,6 +19,5 @@ DIR *opendir(const char *dirname) {
return NULL;
}
rc->fd = fd;
- rc->dir_num = 0;
return rc;
}
diff --git a/userland/libc/dirent/readdir.c b/userland/libc/dirent/readdir.c
index a7f0d66..3e1460c 100644
--- a/userland/libc/dirent/readdir.c
+++ b/userland/libc/dirent/readdir.c
@@ -1,30 +1,27 @@
#include <dirent.h>
+#include <stdio.h>
#include <unistd.h>
int readdir_multi(DIR *dir, struct dirent *entries, int num_entries) {
- size_t offset = dir->dir_num * sizeof(struct dirent);
int rc;
- if (-1 == (rc = pread(dir->fd, entries, num_entries * sizeof(struct dirent),
- offset))) {
+ if (-1 ==
+ (rc = read(dir->fd, entries, num_entries * sizeof(struct dirent)))) {
return -1;
}
int num_read_entries = rc / sizeof(struct dirent);
- dir->dir_num += num_read_entries;
return num_read_entries;
}
struct dirent *readdir(DIR *dir) {
- size_t offset = dir->dir_num * sizeof(struct dirent);
int rc;
- if (-1 == (rc = pread(dir->fd, &dir->internal_direntry, sizeof(struct dirent),
- offset))) {
+ if (-1 ==
+ (rc = read(dir->fd, &dir->internal_direntry, sizeof(struct dirent)))) {
return NULL;
}
if (rc < (int)sizeof(struct dirent)) {
return NULL;
}
- dir->dir_num++;
return &(dir->internal_direntry);
}