Getdents implementation in library/vfs/mfs.
Changed readdir, etc. to use getdents
This commit is contained in:
@@ -10,6 +10,7 @@ libc_FILES=" \
|
||||
_cprofile.c \
|
||||
_devctl.c \
|
||||
__pm_findproc.c \
|
||||
_getdents.c \
|
||||
_getnpid.c \
|
||||
_getsigset.c \
|
||||
_getnprocnr.c \
|
||||
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#include <lib.h>
|
||||
#define getdents _getdents
|
||||
#include <dirent.h>
|
||||
|
||||
PUBLIC ssize_t getdents(fd, buffer, nbytes)
|
||||
int fd;
|
||||
struct dirent *buffer;
|
||||
size_t nbytes;
|
||||
{
|
||||
message m;
|
||||
|
||||
m.m1_i1 = fd;
|
||||
m.m1_i2 = nbytes;
|
||||
m.m1_p1 = (char *) buffer;
|
||||
return _syscall(FS, GETDENTS, &m);
|
||||
}
|
||||
@@ -19,14 +19,8 @@ int seekdir(DIR *dp, off_t pos)
|
||||
if (dp == nil) { errno= EBADF; return -1; }
|
||||
|
||||
dp->_count= 0;
|
||||
dp->_ptr= dp->_buf;
|
||||
|
||||
off= pos & (sizeof(dp->_buf) - 1);
|
||||
dp->_pos= pos - off;
|
||||
|
||||
if (lseek(dp->_fd, dp->_pos, SEEK_SET) == -1) return -1;
|
||||
|
||||
while (dp->_pos < pos && readdir(dp) != nil) {}
|
||||
if (lseek(dp->_fd, pos, SEEK_SET) == -1) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+12
-1
@@ -6,11 +6,22 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
off_t telldir(DIR *dp)
|
||||
/* Return the current read position in a directory. */
|
||||
{
|
||||
struct dirent *dep;
|
||||
|
||||
if (dp == nil) { errno= EBADF; return -1; }
|
||||
|
||||
return dp->_pos;
|
||||
if (dp->_pos < dp->_count)
|
||||
{
|
||||
/* Use position in next entry */
|
||||
dep= (struct dirent *)&dp->_buf[dp->_pos];
|
||||
return dep->d_off;
|
||||
}
|
||||
|
||||
/* Get current offset in directory */
|
||||
return lseek(dp->_fd, 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user