Add test for creating a new file and add openc macro to use openat with the mode option
This commit is contained in:
parent
eda1bbca23
commit
faab7a9622
@ -28,9 +28,14 @@ int main() {
|
|||||||
// Test the read syscall
|
// Test the read syscall
|
||||||
#define INPUT_BUFFER_LEN 4096
|
#define INPUT_BUFFER_LEN 4096
|
||||||
char input_buffer[INPUT_BUFFER_LEN] = {0};
|
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);
|
write(STDOUT, "Enter some text:", 16);
|
||||||
intptr_t n_read = read(STDIN, input_buffer, INPUT_BUFFER_LEN);
|
intptr_t n_read = read(STDIN, input_buffer, INPUT_BUFFER_LEN);
|
||||||
write(STDOUT, input_buffer, n_read);
|
write(STDOUT, input_buffer, n_read);
|
||||||
|
if(fout > 0) {
|
||||||
|
write(fout, input_buffer, n_read);
|
||||||
|
}
|
||||||
|
|
||||||
// Test the open syscall
|
// Test the open syscall
|
||||||
int32_t file = open("/proc/version", O_RDONLY);
|
int32_t file = open("/proc/version", O_RDONLY);
|
||||||
|
|||||||
20
sys.h
20
sys.h
@ -13,11 +13,25 @@ intptr_t read(int32_t fd, const void* buf, intptr_t size);
|
|||||||
#define O_WRONLY 01
|
#define O_WRONLY 01
|
||||||
#define O_RDWR 02
|
#define O_RDWR 02
|
||||||
#define AT_FDCWD -100
|
#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);
|
int32_t openat(int32_t fd, const char* filename, uint32_t flags, uint32_t mode);
|
||||||
#define open(...) openat(AT_FDCWD, __VA_ARGS__, 0)
|
#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);}
|
#define openc(...) openat(AT_FDCWD, __VA_ARGS__)
|
||||||
//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);}
|
|
||||||
|
|
||||||
uint32_t fork();
|
uint32_t fork();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user