Browse Source

libc wip

master
Mathieu Serandour 4 months ago
parent
commit
88815fcf63
  1. 12
      blib/include/dirent.h
  2. 8
      blib/src/dirent.c
  3. 5
      blib/src/unistd.c

12
blib/include/dirent.h

@ -30,12 +30,14 @@
struct dirent {
ino_t d_ino;
off_t d_off;
ino_t ino; /* Inode number */
size_t d_reclen; /* Length of this record */
unsigned char d_type; /* Type of file; not supported
by all filesystem types */
unsigned short int d_reclen;
unsigned char d_type;
char d_name[256]; /* We must not include limits.h! */
uint8_t reserved[7];
char d_name[256]; /* Null-terminated filename */
};

8
blib/src/dirent.c

@ -16,13 +16,14 @@ typedef struct DIR {
} DIR;
DIR *opendir (const char* name) {
int fd = open(name, 0, 0);
int fd = open(name, O_DIR, 0);
if(fd < 0) {
return NULL;
}
// read the dir
// compute dir size
size_t size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
@ -47,10 +48,9 @@ DIR *opendir (const char* name) {
return NULL;
}
// fill the other fields
dir->fd = fd;
dir->len = size;
dir->len = size / sizeof(struct dirent);
dir->cur = 0;
return dir;

5
blib/src/unistd.c

@ -227,7 +227,7 @@ int forkexec(char const* const cmdline[]) {
int chdir (const char *__path) {
struct sc_chdir_args args = {
.path = __path,
.path_len = strlen(__path),
.path_len = strlen(__path) + 1,
};
return syscall(SC_CHDIR, &args, sizeof(args));
@ -297,6 +297,7 @@ int __attribute__ ((__const__)) getpagesize (void) {
void __attribute__ ((__noreturn__)) _exit (int status) {
syscall(SC_EXIT, &status, sizeof(status));
uint64_t sc_args = status;
syscall(SC_EXIT, &status, sizeof(sc_args));
__builtin_unreachable();
}

Loading…
Cancel
Save