From 1a10a3725e7bea67e558715f6e9f78abcb415b3a Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 30 Apr 2025 21:07:46 -0400 Subject: finish syscall impls --- user/include/stdio.h | 6 +++--- user/include/sys/types.h | 15 +++++++++++++++ user/include/unistd.h | 16 +++++++--------- 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 user/include/sys/types.h (limited to 'user/include') diff --git a/user/include/stdio.h b/user/include/stdio.h index fe29c9d..bb57c6d 100644 --- a/user/include/stdio.h +++ b/user/include/stdio.h @@ -252,7 +252,7 @@ extern size_t fwrite(const void *restrict ptr, size_t size, size_t n, * @param stream - the stream to seek * @param off - the offset from whence * @param whence - where to seek from (SEEK_SET, SEEK_CUR, SEEK_END) - * @returns 0 on success, -1 on error setting errno + * @returns new offset on success, -1 on error */ extern int fseek(FILE *stream, long int off, int whence); @@ -260,9 +260,9 @@ extern int fseek(FILE *stream, long int off, int whence); * return the current position of stream * * @param stream - the stream to tell - * @return the position on success, -1 on error setting errno + * @returns new offset on success, -1 on error */ -extern long int ftell(FILE *stream); +extern long ftell(FILE *stream); /** * rewing to the begining of a stream diff --git a/user/include/sys/types.h b/user/include/sys/types.h new file mode 100644 index 0000000..f1b3266 --- /dev/null +++ b/user/include/sys/types.h @@ -0,0 +1,15 @@ +/** + * @file types.h + * + * @author Freya Murphy + * + * System types + */ + +#ifndef _TYPES_H +#define _TYPES_H + +typedef long int off_t; +typedef unsigned short pid_t; + +#endif /* types.h */ diff --git a/user/include/unistd.h b/user/include/unistd.h index cad3a81..4f582d2 100644 --- a/user/include/unistd.h +++ b/user/include/unistd.h @@ -11,11 +11,10 @@ #include #include +#include /* System Call Definitions */ -typedef unsigned short pid_t; - enum { S_SET = 0, S_CUR = 1, @@ -27,7 +26,7 @@ enum { O_RDONLY = 0x02, O_WRONLY = 0x04, O_APPEND = 0x08, - O_RDWR = O_RDONLY | O_WRONLY, + O_RDWR = 0x010, }; /** @@ -67,11 +66,9 @@ extern int fork(void); * * @param prog - program table index of the program to exec * @param args - the command-line argument vector - * - * Does not return if it succeeds; if it returns, something has - * gone wrong. + * @returns error code on failure */ -extern void exec(const char *filename, char **args); +extern int exec(const char *filename, const char **args); /** * open a stream with a given filename @@ -85,8 +82,9 @@ extern int open(const char *filename, int flags); * closes a stream with the given file descriptior * * @param fd - the file descriptior of the open stream + * @returns 0 on success, error code on invalid fd */ -extern void close(int fd); +extern int close(int fd); /** * read into a buffer from a stream @@ -116,7 +114,7 @@ extern int write(int fd, const void *buffer, size_t nbytes); * @param whence - whence to seek * @return 0 on success, or an error code */ -extern int seek(int fd, long int off, int whence); +extern off_t seek(int fd, off_t off, int whence); /** * gets the pid of the calling process -- cgit v1.2.3-freya