diff --git a/sys/include/sys/sysproto_posix.h b/sys/include/sys/sysproto_posix.h index e14e374..36a0afa 100644 --- a/sys/include/sys/sysproto_posix.h +++ b/sys/include/sys/sysproto_posix.h @@ -807,6 +807,17 @@ int sys_setrlimit(struct thread *, struct sys_setrlimit_args *); +struct sys_dup2_args { + char from_l_[PADL_(u_int)]; + u_int from; + char from_r_[PADR_(u_int)]; + char to_l_[PADL_(u_int)]; + u_int to; + char to_r_[PADR_(u_int)]; +}; + +int sys_dup2(struct thread*, struct sys_dup2_args*); + //Func Defs int sys_invalid(struct thread *, void *); int sys_exit(struct thread *, struct sys_exit_args *); @@ -892,4 +903,6 @@ int sys_pread(struct thread *td, struct sys_pread_args *); + + #endif /* END _SYS_SYSPROTO_POSIX_H_ */ diff --git a/sys/kernel/descrip.c b/sys/kernel/descrip.c index 107daf5..37a6dca 100644 --- a/sys/kernel/descrip.c +++ b/sys/kernel/descrip.c @@ -45,15 +45,15 @@ return (-1); } - fp = (struct file *) td->o_files[uap->fd]; + fp = (struct file*) td->o_files[uap->fd]; switch (uap->cmd) { case 3: td->td_retval[0] = fp->f_flag; - break; + break; case 4: fp->f_flag &= ~FCNTLFLAGS; fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS; - break; + break; default: kprintf("ERROR DEFAULT: [%i]", uap->fd); } @@ -70,12 +70,12 @@ struct file *fp = 0x0; int i = 0; - fp = (struct file *) kmalloc(sizeof(struct file)); + fp = (struct file*) kmalloc(sizeof(struct file)); /* First 5 Descriptors Are Reserved */ for (i = 5; i < MAX_FILES; i++) { if (td->o_files[i] == 0x0) { - td->o_files[i] = (void *) fp; + td->o_files[i] = (void*) fp; if (resultfd) *resultfd = i; if (resultfp) @@ -115,7 +115,7 @@ kprintf("[%s:%i]",__FILE__,__LINE__); #endif kprintf("[%s:%i]", __FILE__, __LINE__); - kfree((void *) td->o_files[uap->fd]); + kfree((void*) td->o_files[uap->fd]); td->o_files[uap->fd] = 0x0; td->td_retval[0] = 0x0; return (0x0); @@ -140,7 +140,7 @@ kprintf("[%s:%i]",__FILE__,__LINE__); #endif - fp = (struct file *) _current->td.o_files[uap->fd]; + fp = (struct file*) _current->td.o_files[uap->fd]; uap->sb->st_mode = 0x2180; uap->sb->st_blksize = 0x1000; kprintf("fstat: %i", uap->fd); @@ -169,7 +169,7 @@ kprintf("[%s:%i]",__FILE__,__LINE__); #endif - *fp = (struct file *) td->o_files[fd]; + *fp = (struct file*) td->o_files[fd]; if (fp == 0x0) error = -1; @@ -181,7 +181,7 @@ switch (args->com) { case TIOCGETA: if (args->fd == 0 || args->fd == 1) { - struct termios *t = (struct termios *) args->data; + struct termios *t = (struct termios*) args->data; t->c_iflag = 0x2B02; t->c_oflag = 0x3; @@ -217,16 +217,16 @@ else { td->td_retval[0] = -1; } - break; + break; case TIOCGWINSZ: asm("nop"); - struct winsize *win = (struct winsize *) args->data; + struct winsize *win = (struct winsize*) args->data; win->ws_row = 50; win->ws_col = 80; - break; + break; default: kprintf("ioFD:%i:0x%X!", args->fd, args->com); - break; + break; } td->td_retval[0] = 0x0; @@ -295,3 +295,23 @@ return (error); } + +int dup2(struct thread *td, u_int32_t from, u_int32_t to) { + + if (td->o_files[to] != 0x0) { + kprintf("FD IN USE!"); + return (-1); + } + + return (0x0); +} + +int sys_dup2(struct thread *td, struct sys_dup2_args *args) { + + int error = 0x0; + + if ((td->td_retval[0] = dup2(td, args->from, args->to)) == -1) + error = -1; + + return (error); +} diff --git a/sys/kernel/syscalls_posix.c b/sys/kernel/syscalls_posix.c index b48b452..3fdda5d 100644 --- a/sys/kernel/syscalls_posix.c +++ b/sys/kernel/syscalls_posix.c @@ -482,10 +482,10 @@ sys_invalid, SYSCALL_NOTIMP }, /* 89 - gettablesize */ { - 0, + ARG_COUNT(sys_dup2_args), "dup2", - sys_invalid, - SYSCALL_NOTIMP }, /* 90 - dup2 */ + sys_dup2, + SYSCALL_VALID }, /* 90 - dup2 */ { 0, "getdopt",