case SYS_fork: return sys_fork();
case SYS_pipe: return sys_pipe(a);
case SYS_dup2: return sys_dup2(a,b);
+ case SYS_dup: return sys_dup(a);
case SYS_waitpid: return sys_waitpid(a,b,c);
case SYS_stat: return sys_stat(a,b);
case SYS_lstat: return sys_lstat(a,b);
return 0;
}
+ private int sys_dup(int oldd) {
+ if(oldd < 0 || oldd >= OPEN_MAX) return -EBADFD;
+ if(fds[oldd] == null) return -EBADFD;
+ FD fd = fds[oldd].dup();
+ int newd = addFD(fd);
+ if(newd < 0) { fd.close(); return -ENFILE; }
+ return newd;
+ }
+
private int sys_stat(int cstring, int addr) throws FaultException, ErrnoException {
FStat s = gs.stat(this,normalizePath(cstring(cstring)));
if(s == null) return -ENOENT;
public static final int SYS_getdents = 36;
public static final int SYS_memcpy = 37;
public static final int SYS_memset = 38;
+ public static final int SYS_dup = 39;
public static final int EPERM = 1; /* Not super-user */
public static final int ENOENT = 2; /* No such file or directory */
public static final int ESRCH = 3; /* No such process */
SYSCALL_R(getdents)
SYSCALL(memcpy)
SYSCALL(memset)
+SYSCALL_R(dup)
REENT_WRAPPER2(fchmod,int,mode_t)
REENT_WRAPPER2(lstat,const char *,struct stat *)
REENT_WRAPPER4(getdents,int, char *, size_t,long *)
+REENT_WRAPPER1(dup,int)
extern int __execve_r(struct _reent *ptr, const char *path, char *const argv[], char *const envp[]);
int _execve(const char *path, char *const argv[], char *const envp[]) {
}
}
+pid_t _wait_r(struct _reent *ptr, int *status) {
+ return _waitpid_r(ptr,-1,status,0);
+}
+
DIR *opendir(const char *path) {
struct stat sb;
int fd;
#define SYS_getdents 36
#define SYS_memcpy 37
#define SYS_memset 38
+#define SYS_dup 39