[cat] Some error handling
This commit is contained in:
parent
ad7d5d7acc
commit
9e3d03da4f
@ -30,7 +30,7 @@ static int exit(int retval) {
|
||||
}
|
||||
|
||||
static int read(int fd, char * ptr, int len) {
|
||||
if (fd >= current_task->next_fd) {
|
||||
if (fd >= current_task->next_fd || fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
fs_node_t * node = current_task->descriptors[fd];
|
||||
@ -40,7 +40,7 @@ static int read(int fd, char * ptr, int len) {
|
||||
}
|
||||
|
||||
static int write(int fd, char * ptr, int len) {
|
||||
if (fd >= current_task->next_fd) {
|
||||
if (fd >= current_task->next_fd || fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
fs_node_t * node = current_task->descriptors[fd];
|
||||
@ -60,7 +60,7 @@ static int open(const char * file, int flags, int mode) {
|
||||
}
|
||||
|
||||
static int close(int fd) {
|
||||
if (fd <= current_task->next_fd) {
|
||||
if (fd <= current_task->next_fd || fd < 0) {
|
||||
return -1;
|
||||
}
|
||||
close_fs(current_task->descriptors[fd]);
|
||||
|
@ -6,6 +6,12 @@ int main(int argc, char ** argv) {
|
||||
return -1;
|
||||
} else {
|
||||
int i = syscall_open(argv[1], 0, 0);
|
||||
if (i < 0) {
|
||||
syscall_print("cat: could not open '");
|
||||
syscall_print(argv[1]);
|
||||
syscall_print("': no such file or directory\n");
|
||||
return 1;
|
||||
}
|
||||
char dat[2] = {0, 0};
|
||||
int read = 0;
|
||||
while ((read = syscall_read(i, dat, 1))) {
|
||||
|
Loading…
Reference in New Issue
Block a user