diff options
author | Anton Kling <anton@kling.gg> | 2023-10-24 14:10:07 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2023-10-24 14:10:07 +0200 |
commit | 2292b11e82a3d6d70e7bb932c512155dc13c5025 (patch) | |
tree | da7d90e778495bc9a67ee0e09b32813c11dc6fe5 /userland | |
parent | e93a49d1eadf4a4b36369e67f112f8c45a0d567e (diff) |
VFS/LibC: Create ftruncate function and corresponding syscall and libc implementation
Previously this function was only used for shared memory region created
by shm_open because I was lazy. Now exists for all files.
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/Makefile | 2 | ||||
-rw-r--r-- | userland/libc/include/unistd.h | 2 | ||||
-rw-r--r-- | userland/libc/libc.c | 5 | ||||
-rw-r--r-- | userland/libc/unistd/ftruncate.c | 6 |
4 files changed, 8 insertions, 7 deletions
diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 0681eda..704bf79 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -2,7 +2,7 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" CFLAGS = -ggdb -ffreestanding -O2 -Wall -pedantic -Wimplicit-fallthrough -I./include/ -static -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o all: libc.a %.o: %.c diff --git a/userland/libc/include/unistd.h b/userland/libc/include/unistd.h index e43dc33..7d74097 100644 --- a/userland/libc/include/unistd.h +++ b/userland/libc/include/unistd.h @@ -10,7 +10,7 @@ extern int opterr, optind, optopt; extern char *optarg; int close(int fildes); -int ftruncate(int fildes, uint64_t length); +int ftruncate(int fildes, size_t length); int execv(char *path, char **argv); int pipe(int fd[2]); int dup2(int org_fd, int new_fd); diff --git a/userland/libc/libc.c b/userland/libc/libc.c index 90c0323..e2f064d 100644 --- a/userland/libc/libc.c +++ b/userland/libc/libc.c @@ -315,8 +315,3 @@ int shm_open(const char *name, int oflag, mode_t mode) { }; RC_ERRNO(syscall(SYS_SHM_OPEN, &args, 0, 0, 0, 0)); } - -int ftruncate(int fildes, uint64_t length) { - SYS_FTRUNCATE_PARAMS args = {.fildes = fildes, .length = length}; - RC_ERRNO(syscall(SYS_FTRUNCATE, &args, 0, 0, 0, 0)); -} diff --git a/userland/libc/unistd/ftruncate.c b/userland/libc/unistd/ftruncate.c new file mode 100644 index 0000000..cf35944 --- /dev/null +++ b/userland/libc/unistd/ftruncate.c @@ -0,0 +1,6 @@ +#include <syscall.h> +#include <unistd.h> + +int ftruncate(int fildes, size_t length) { + RC_ERRNO(syscall(SYS_FTRUNCATE, fildes, length, 0, 0, 0)); +} |