diff --git a/buildtest.c b/buildtest.c index fcbc330..3ae2429 100644 --- a/buildtest.c +++ b/buildtest.c @@ -28,9 +28,14 @@ int main() { // Test the read syscall #define INPUT_BUFFER_LEN 4096 char input_buffer[INPUT_BUFFER_LEN] = {0}; + int32_t fout = openc("outfile", O_RDWR | O_CREAT | O_TRUNC, 0664); + write(STDOUT, "Enter some text:", 16); intptr_t n_read = read(STDIN, input_buffer, INPUT_BUFFER_LEN); write(STDOUT, input_buffer, n_read); + if(fout > 0) { + write(fout, input_buffer, n_read); + } // Test the open syscall int32_t file = open("/proc/version", O_RDONLY); diff --git a/sys.h b/sys.h index 3bdefff..2bce1db 100644 --- a/sys.h +++ b/sys.h @@ -13,11 +13,25 @@ intptr_t read(int32_t fd, const void* buf, intptr_t size); #define O_WRONLY 01 #define O_RDWR 02 #define AT_FDCWD -100 + +#if defined(__mips__) + // linux/arch/mips/include/uapi/asm/fcntl.h + #define O_APPEND 0x0008 + #define O_CREAT 0x0100 /* not fcntl */ + #define O_TRUNC 0x0200 /* not fcntl */ + #define O_EXCL 0x0400 /* not fcntl */ + #define O_NOCTTY 0x0800 /* not fcntl */ +#else + // linux/include/uapi/asm-generic/fcntl.h + #define O_CREAT 1<<6 + #define O_EXCL 1<<7 + #define O_NOCTTY 1<<8 + #define O_TRUNC 1<<9 + #define O_APPEND 1<<10 +#endif int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode); #define open(...) openat(AT_FDCWD, __VA_ARGS__, 0) -//inline int32_t openat(int32_t fd, const char* filename, uint32_t flags) {return openat(fd, filename, flags, 0);} -//inline int32_t open(const char* filename, uint32_t flags, uint32_t mode) {return openat(AT_FDCWD, filename, flags, mode);} -//inline int32_t open(const char* filename, uint32_t flags) {return openat(AT_FDCWD, filename, flags, 0);} +#define openc(...) openat(AT_FDCWD, __VA_ARGS__) uint32_t fork();