# @(#)Makefile 5.4 (Berkeley) 9/5/85
#
-SRCS= chmod.c chown.c close.c fchmod.c fchown.c fstat.c ftruncate.c \
- getpagesize.c getpid.c isatty.c link.c linux.c lseek.c read.c readv.c \
- sbrk.c sigvec.c stat.c symlink.c truncate.c umask.c unlink.c vopen.c \
- write.c writev.c _exit.c
-OBJS= chmod.o chown.o close.o fchmod.o fchown.o fstat.o ftruncate.o \
- getpagesize.o getpid.o isatty.o link.o linux.o lseek.o read.o readv.o \
- sbrk.o sigvec.o stat.o symlink.o truncate.o umask.o unlink.o vopen.o \
- write.o writev.o _exit.o
+SRCS= chmod.c chown.c close.c dup2.c dup.c _exit.c fchmod.c fchown.c \
+ fstat.c ftruncate.c getdtablesize.c getegid.c geteuid.c getgid.c \
+ getpagesize.c getpgrp.c getpid.c getppid.c gettimeofday.c getuid.c \
+ ioctl.c isatty.c link.c linux.c lseek.c lstat.c read.c readv.c sbrk.c \
+ setpgrp.c setregid.c setreuid.c settimeofday.c sigvec.c stat.c \
+ symlink.c sync.c truncate.c umask.c unlink.c vopen.c write.c writev.c
+
+OBJS= chmod.o chown.o close.o dup2.o dup.o _exit.o fchmod.o fchown.o \
+ fstat.o ftruncate.o getdtablesize.o getegid.o geteuid.o getgid.o \
+ getpagesize.o getpgrp.o getpid.o getppid.o gettimeofday.o getuid.o \
+ ioctl.o isatty.o link.o linux.o lseek.o lstat.o read.o readv.o sbrk.o \
+ setpgrp.o setregid.o setreuid.o settimeofday.o sigvec.o stat.o \
+ symlink.o sync.o truncate.o umask.o unlink.o vopen.o write.o writev.o
TAGSFILE=tags
.c.o:
--- /dev/null
+#include <nox_errno.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys/file.h>
+#include "linux.h"
+
+int dup(f) int f; {
+ int res;
+
+ res = nox_dup((nox_int)f);
+ if (res == (nox_int)-1)
+ errno = htot_errno(nox_errno);
+ return (int)res;
+}
--- /dev/null
+#include <nox_errno.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys/file.h>
+#include "linux.h"
+
+int dup2(o, n) int o; int n; {
+ int res;
+
+ res = nox_dup2((nox_int)o, (nox_int)n);
+ if (res == (nox_int)-1)
+ errno = htot_errno(nox_errno);
+ return (int)res;
+}
--- /dev/null
+#include <nox_unistd.h>
+
+#include <sys.h>
+
+int getdtablesize() {
+ return (int)nox_getdtablesize();
+}
--- /dev/null
+#include <nox_unistd.h>
+#include <sys/nox_types.h>
+
+#include <sys.h>
+#include <sys/types.h>
+
+gid_t getegid() {
+ return (gid_t)nox_getegid();
+}
--- /dev/null
+#include <nox_unistd.h>
+#include <sys/nox_types.h>
+
+#include <sys.h>
+#include <sys/types.h>
+
+uid_t geteuid() {
+ return (uid_t)nox_geteuid();
+}
--- /dev/null
+#include <nox_unistd.h>
+#include <sys/nox_types.h>
+
+#include <sys.h>
+#include <sys/types.h>
+
+gid_t getgid() {
+ return (gid_t)nox_getgid();
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys.h>
+#include "linux.h"
+
+int getpgrp(p) int p; {
+ nox_pid_t res;
+
+ res = nox_getpgid((nox_pid_t)p);
+ if (res == (nox_pid_t)-1) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ return res;
+}
--- /dev/null
+#include <nox_unistd.h>
+
+int getpid() {
+ return (int)nox_getppid();
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_time.h>
+#include <sys/nox_types.h>
+
+#include <errno.h>
+#include <sys/time.h>
+#include "linux.h"
+
+int gettimeofday(t, z) struct timeval *t; struct timezone *z; {
+ struct nox_timeval tv;
+ struct nox_timezone tz;
+
+ if (nox_gettimeofday(&tv, &tz)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ if (t) {
+ t->tv_sec = (long)tv.nox_tv_sec;
+ t->tv_usec = (long)tv.nox_tv_usec;
+ }
+ if (z) {
+ z->tz_minuteswest = (int)tz.nox_tz_minuteswest;
+ z->tz_dsttime = (int)tz.nox_tz_dsttime;
+ }
+ return 0;
+}
--- /dev/null
+#include <nox_unistd.h>
+#include <sys/nox_types.h>
+
+#include <sys.h>
+#include <sys/types.h>
+
+uid_t getuid() {
+ return (uid_t)nox_getuid();
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_ioctl.h>
+#include <sys/nox_types.h>
+
+#include <sys/errno.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include "linux.h"
+
+int ioctl(d, r, p) int d; u_long r; void *p; {
+ switch (r) {
+ case TIOCGWINSZ: {
+ struct nox_winsize ws;
+ if (nox_ioctl((nox_int)d, nox_TIOCGWINSZ, &ws)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ ((struct winsize *)p)->ws_row = (unsigned short)ws.nox_ws_row;
+ ((struct winsize *)p)->ws_col = (unsigned short)ws.nox_ws_col;
+ ((struct winsize *)p)->ws_xpixel = (unsigned short)ws.nox_ws_xpixel;
+ ((struct winsize *)p)->ws_ypixel = (unsigned short)ws.nox_ws_ypixel;
+ return 0;
+ }
+ default:
+ errno = ENOTTY;
+ return -1;
+ }
+}
+#include <nox_dirent.h>
#include <nox_errno.h>
#include <nox_stdlib.h>
+#include <nox_string.h>
+#include <sys/nox_types.h>
#include <nox_unistd.h>
#include <string.h>
+#include <sys/dir.h>
#include <sys/errno.h>
#include <sys/signal.h>
#include "linux.h"
return res;
}
-void htot_stat(statbuf, res) struct nox_stat *statbuf; struct stat *res; {
+void htot_stat(stat, res) struct nox_stat *stat; struct stat *res; {
bzero(res, sizeof(struct stat));
- res->st_dev = (dev_t)statbuf->nox_st_dev;
- res->st_ino = (ino_t)statbuf->nox_st_ino;
- res->st_mode = (unsigned short)statbuf->nox_st_mode;
- res->st_nlink = (short)statbuf->nox_st_nlink;
- res->st_uid = (uid_t)statbuf->nox_st_uid;
- res->st_gid = (gid_t)statbuf->nox_st_gid;
- res->st_rdev = (dev_t)statbuf->nox_st_rdev;
- res->st_size = (off_t)statbuf->nox_st_size;
- res->st_atime = (time_t)statbuf->nox_st_atime;
- res->st_mtime = (time_t)statbuf->nox_st_mtime;
- res->st_ctime = (time_t)statbuf->nox_st_ctime;
- res->st_blksize = /*0x2000;*/ (long)statbuf->nox_st_blksize;
- res->st_blocks = (long)statbuf->nox_st_blocks;
+ res->st_dev = (dev_t)stat->nox_st_dev;
+ res->st_ino = (ino_t)stat->nox_st_ino;
+ res->st_mode = (unsigned short)stat->nox_st_mode;
+ res->st_nlink = (short)stat->nox_st_nlink;
+ res->st_uid = (uid_t)stat->nox_st_uid;
+ res->st_gid = (gid_t)stat->nox_st_gid;
+ res->st_rdev = (dev_t)stat->nox_st_rdev;
+ res->st_size = (off_t)stat->nox_st_size;
+ res->st_atime = (time_t)stat->nox_st_atime;
+ res->st_mtime = (time_t)stat->nox_st_mtime;
+ res->st_ctime = (time_t)stat->nox_st_ctime;
+ res->st_blksize = /*0x2000;*/ (long)stat->nox_st_blksize;
+ res->st_blocks = (long)stat->nox_st_blocks;
+}
+
+static void htot_direct(dirent, res) struct nox_dirent *dirent; struct direct *res; {
+ res->d_ino = (ino_t)dirent->nox_d_ino;
+ if (res->d_ino == 0) {
+ nox_write((nox_int)2, "htot_direct(): null inode\n", (nox_size_t)27);
+ nox_abort();
+ }
+ res->d_namlen = strlen(dirent->nox_d_name);
+ if (res->d_namlen > MAXNAMLEN) {
+ nox_write((nox_int)2, "htot_direct(): name too long\n", (nox_size_t)29);
+ nox_abort();
+ }
+ strncpy(res->d_name, dirent->nox_d_name, (res->d_namlen + 4) & ~3);
+ res->d_reclen = DIRSIZ(res);
+}
+
+nox_int htot_dir(fd) nox_int fd; {
+ nox_int res;
+ static char tempfile[] = "/tmp/dirXXXXXX";
+ nox_DIR *dp;
+ struct nox_dirent *d;
+ char buf[DIRBLKSIZ + sizeof(struct direct)], *p, *q;
+
+ res = nox_mkstemp(tempfile);
+ if (res == -1) {
+ errno = htot_errno(nox_errno);
+ return (nox_int)-1;
+ }
+ if (nox_unlink(tempfile) || (dp = nox_fdopendir(fd)) == 0) {
+ errno = htot_errno(nox_errno);
+ nox_close(fd);
+ return (nox_int)-1;
+ }
+ if ((d = nox_readdir(dp)) != 0) {
+ htot_direct(d, (struct direct *)buf);
+ p = buf;
+ while ((d = nox_readdir(dp)) != 0) {
+ q = p + ((struct direct *)p)->d_reclen;
+ htot_direct(d, q);
+ if (q + ((struct direct *)q)->d_reclen > buf + DIRBLKSIZ) {
+ /*nox_memset(q, 0xaa, buf + DIRBLKSIZ - q);*/
+ ((struct direct *)p)->d_reclen = buf + DIRBLKSIZ - p;
+ nox_errno = nox_ENOSPC;
+ if (nox_write(res, buf, (nox_size_t)DIRBLKSIZ) != (nox_ssize_t)DIRBLKSIZ)
+ goto nogood;
+ /*htot_direct(d, q);*/
+ nox_memcpy(buf, q, ((struct direct *)q)->d_reclen);
+ q = buf;
+ }
+ p = q;
+ }
+ /*q = p + ((struct direct *)p)->d_reclen;*/
+ /*nox_memset(q, 0xaa, buf + DIRBLKSIZ - q);*/
+ ((struct direct *)p)->d_reclen = buf + DIRBLKSIZ - p;
+ nox_errno = nox_ENOSPC;
+ if (nox_write(res, buf, (nox_size_t)DIRBLKSIZ) != (nox_ssize_t)DIRBLKSIZ)
+ goto nogood;
+ }
+ if (nox_lseek(res, (nox_off_t)0, nox_SEEK_SET) == (nox_off_t)-1) {
+ nogood:
+ errno = htot_errno(nox_errno);
+ nox_closedir(dp);
+ nox_close(res);
+ return (nox_int)-1;
+ }
+ nox_closedir(dp);
+ return res;
}
void ttoh_sigmask(int m, nox_sigset_t *res);
int htot_sigmask(nox_sigset_t *set);
void htot_stat(struct nox_stat *statbuf, struct stat *res);
+int htot_dir(nox_int fd);
#endif
#include "linux.h"
off_t lseek(f, o, d) int f; off_t o; int d; {
- nox_int cmd;
+ nox_int whence;
nox_off_t res;
switch (d) {
case L_SET:
- cmd = nox_SEEK_SET;
+ whence = nox_SEEK_SET;
break;
case L_INCR:
- cmd = nox_SEEK_CUR;
+ whence = nox_SEEK_CUR;
break;
case L_XTND:
- cmd = nox_SEEK_END;
+ whence = nox_SEEK_END;
break;
default:
- write(2, "lseek()\n", 8);
+ write(2, "lseek(): invalid whence\n", 24);
abort();
}
- res = nox_lseek(f, (nox_off_t)o, cmd);
+ res = nox_lseek(f, (nox_off_t)o, whence);
if (res == (nox_off_t)-1)
errno = htot_errno(nox_errno);
return (off_t)res;
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_stat.h>
+#include <nox_unistd.h>
+
+#include <sys/errno.h>
+#include <sys/stat.h>
+#include "linux.h"
+
+int lstat(s, b) char *s; struct stat *b; {
+ struct nox_stat statbuf;
+
+ if (nox_lstat(s, &statbuf)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ htot_stat(&statbuf, b);
+ return 0;
+}
nox_int res;
if (l > 8) {
- write(2, "readv()\n", 8);
+ write(2, "readv(): iovec too large\n", 25);
abort();
}
for (i = 0; i < l; ++i) {
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys.h>
+#include "linux.h"
+
+int setpgrp(g, pg) int g; int pg; {
+ if (nox_setpgid((nox_pid_t)g, (nox_pid_t)pg)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ return 0;
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys.h>
+#include "linux.h"
+
+int setregid(r, e) int r; int e; {
+ if (nox_setregid((nox_gid_t)r, (nox_gid_t)e)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ return 0;
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_types.h>
+#include <nox_unistd.h>
+
+#include <errno.h>
+#include <sys.h>
+#include "linux.h"
+
+int setreuid(r, e) int r; int e; {
+ if (nox_setreuid((nox_uid_t)r, (nox_uid_t)e)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ return 0;
+}
--- /dev/null
+#include <nox_errno.h>
+#include <sys/nox_time.h>
+#include <sys/nox_types.h>
+
+#include <errno.h>
+#include <sys/time.h>
+#include "linux.h"
+
+int settimeofday(t, z) struct timeval *t; struct timezone *z; {
+ struct nox_timeval tv, *tv_p;
+ struct nox_timezone tz, *tz_p;
+
+ tv_p = 0;
+ if (t) {
+ tv.nox_tv_sec = (nox_time_t)t->tv_sec;
+ tv.nox_tv_usec = (nox_suseconds_t)t->tv_usec;
+ tv_p = &tv;
+ }
+ tz_p = 0;
+ if (z) {
+ tz.nox_tz_minuteswest = (nox_int)z->tz_minuteswest;
+ tz.nox_tz_dsttime = (nox_int)z->tz_dsttime;
+ tz_p = &tz;
+ }
+ if (nox_settimeofday(tv_p, tz_p)) {
+ errno = htot_errno(nox_errno);
+ return -1;
+ }
+ return 0;
+}
act.nox_sa_flags = nox_SA_RESTART | nox_SA_SIGINFO;
if (f->sv_flags & SV_ONSTACK)
act.nox_sa_flags |= nox_SA_ONSTACK;
- if (f->sv_flags & SV_INTERRUPT)
- goto nogood;
+ if (f->sv_flags & SV_INTERRUPT) {
+ write(2, "sigvec(): SV_INTERRUPT\n", 23);
+ abort();
+ }
if (c < 0 || c >= NSIG) {
- nogood:
- write(2, "sigvec()\n", 9);
+ write(2, "sigvec(): out of range\n", 23);
abort();
}
if (nox_sigaction(ttoh_signo[c], &act, &oldact)) {
--- /dev/null
+#include <nox_unistd.h>
+
+#include <sys.h>
+
+void sync() {
+ nox_sync();
+}
#include <nox_errno.h>
#include <nox_fcntl.h>
+#include <sys/nox_stat.h>
+#include <nox_unistd.h>
#include <gen.h>
#include <sys/errno.h>
nox_int flags;
nox_mode_t mode;
nox_int res;
+ struct nox_stat stat;
+ nox_int res2;
switch (m & 3) {
case O_RDONLY:
if (m & O_EXCL)
flags |= nox_O_EXCL;
res = nox_open(f, flags, mode);
- if (res == (nox_int)-1)
+ if (res == (nox_int)-1) {
errno = htot_errno(nox_errno);
+ return -1;
+ }
+ if (nox_fstat(res, &stat)) {
+ errno = htot_errno(nox_errno);
+ nox_close(res);
+ return -1;
+ }
+ if (nox_S_ISDIR(stat.nox_st_mode)) {
+ res2 = htot_dir(res);
+ if (res2 == (nox_int)-1)
+ return -1;
+ if (nox_dup2(res2, res) == (nox_int)-1) {
+ errno = htot_errno(nox_errno);
+ nox_close(res2);
+ return -1;
+ }
+ }
return (int)res;
}
nox_int res;
if (l > 8) {
- write(2, "writev()\n", 9);
+ write(2, "writev(): iovec too large\n", 26);
abort();
}
for (i = 0; i < l; ++i) {