aboutsummaryrefslogtreecommitdiff
path: root/sys/src
diff options
context:
space:
mode:
Diffstat (limited to 'sys/src')
-rw-r--r--sys/src/close.c3
-rw-r--r--sys/src/dup.c5
-rw-r--r--sys/src/errno.inc.h89
-rw-r--r--sys/src/errormsg.c26
-rw-r--r--sys/src/internal.h248
-rw-r--r--sys/src/open.c3
-rw-r--r--sys/src/read.c7
-rw-r--r--sys/src/seek.c8
-rw-r--r--sys/src/write.c7
9 files changed, 385 insertions, 11 deletions
diff --git a/sys/src/close.c b/sys/src/close.c
index 88b1e2b..b9da3ab 100644
--- a/sys/src/close.c
+++ b/sys/src/close.c
@@ -3,5 +3,6 @@
int
sys·close(int fd)
{
- return syscall(·Close, fd);
+ intptr ret = syscall(·Close, fd);
+ return error(ret);
}
diff --git a/sys/src/dup.c b/sys/src/dup.c
index 0943f52..5877df3 100644
--- a/sys/src/dup.c
+++ b/sys/src/dup.c
@@ -1,7 +1,8 @@
#include "internal.h"
int
-sys·dup(int fd)
+sys·dup(int oldfd, int newfd)
{
- return syscall(·Dup, fd);
+ intptr ret = syscall(·Dup2, oldfd, newfd);
+ return error(ret);
}
diff --git a/sys/src/errno.inc.h b/sys/src/errno.inc.h
new file mode 100644
index 0000000..58ee427
--- /dev/null
+++ b/sys/src/errno.inc.h
@@ -0,0 +1,89 @@
+E(0, "no error information")
+E(sys·ErrorBadWideChar, "illegal byte sequence")
+E(sys·ErrorBadDomain, "domain error")
+E(sys·ErrorBadResult, "result not representable")
+E(sys·ErrorNotTTY, "not a tty")
+E(sys·ErrorAccess, "permission denied")
+E(sys·ErrorNotPermit, "operation not permitted")
+E(sys·ErrorNoEntry, "no such file or directory")
+E(sys·ErrorNoProc, "no such process")
+E(sys·ErrorExists, "file exists")
+E(sys·ErrorOverflow, "value too large for data type")
+E(sys·ErrorNoSpace, "no space left on device")
+E(sys·ErrorNoMemory, "out of memory")
+E(sys·ErrorBusy, "resource busy")
+E(sys·ErrorInterrupt, "interrupted system call")
+E(sys·ErrorAgain, "resource temporarily unavailable")
+E(sys·ErrorNoSeek, "invalid seek")
+E(sys·ErrorExDevice, "cross-device link")
+E(sys·ErrorReadOnly, "read-only file system")
+E(sys·ErrorNotEmptyDir, "directory not empty")
+E(sys·ErrorResetConnect, "connection reset by peer")
+E(sys·ErrorTimedOut, "operation timed out")
+E(sys·ErrorRefuseConnect, "connection refused")
+E(sys·ErrorHostDown, "host is down")
+E(sys·ErrorHostHang, "host is unreachable")
+E(sys·ErrorAddrInUse, "address in use")
+E(sys·ErrorBadPipe, "broken pipe")
+E(sys·ErrorIO, "i/o error")
+E(sys·ErrorNoDevAddr, "no such device or address")
+E(sys·ErrorNotBlk, "block device required")
+E(sys·ErrorNoDevice, "no such device")
+E(sys·ErrorNotDir, "not a directory")
+E(sys·ErrorIsDir, "is a directory")
+E(sys·ErrorTxtBusy, "text file busy")
+E(sys·ErrorExecFmt, "exec format error")
+E(sys·ErrorBadArg, "invalid argument")
+E(sys·ErrorArgLen, "argument list too long")
+E(sys·ErrorLinkLoop, "symbolic link loop")
+E(sys·ErrorNameLen, "filename too long")
+E(sys·ErrorNoFiles, "too many open files in system")
+E(sys·ErrorNoFd, "no file descriptors available")
+E(sys·ErrorBadFd, "bad file descriptor")
+E(sys·ErrorNoChild, "no child process")
+E(sys·ErrorBadAddr, "bad address")
+E(sys·ErrorBigFile, "file too large")
+E(sys·ErrorNoLink, "too many links")
+E(sys·ErrorNoLock, "no locks available")
+E(sys·ErrorDeadlock, "resource deadlock would occur")
+E(sys·ErrorNoRecover, "state not recoverable")
+E(sys·ErrorOwnerDie, "previous owner died")
+E(sys·ErrorCancel, "operation canceled")
+E(sys·ErrorNoSyscall, "function not implemented")
+E(sys·ErrorNoMsg, "no message of desired type")
+E(sys·ErrorNoIdent, "identifier removed")
+E(sys·ErrorNoStr, "device not a stream")
+E(sys·ErrorNoData, "no data available")
+E(sys·ErrorTimeout, "device timeout")
+E(sys·ErrorNoStream, "out of streams resources")
+E(sys·ErrorDeadLink, "link has been severed")
+E(sys·ErrorProtocol, "protocol error")
+E(sys·ErrorBadMsg, "bad message")
+E(sys·ErrorBadFdState, "file descriptor in bad state")
+E(sys·ErrorNotSocket, "not a socket")
+E(sys·ErrorNeedDstAddr, "destination address required")
+E(sys·ErrorMsgLen, "message too large")
+E(sys·ErrorBadProtocol, "protocol wrong type for socket")
+E(sys·ErrorNoProtocol, "protocol not available")
+E(sys·ErrorNoProtocolSupport, "protocol not supported")
+E(sys·ErrorNoSocketSupport, "socket type not supported")
+E(sys·ErrorNoSupport, "not supported")
+E(sys·ErrorNoPFSupport, "protocol family not supported")
+E(sys·ErrorNoAFSupport, "address family not supported by protocol")
+E(sys·ErrorAddrNotAvail, "address not available")
+E(sys·ErrorNetDown, "network is down")
+E(sys·ErrorNetHang, "network unreachable")
+E(sys·ErrorNetReset, "connection reset by network")
+E(sys·ErrorAbortConnect, "connection aborted")
+E(sys·ErrorNoBuffer, "no buffer space available")
+E(sys·ErrorIsConnect, "socket is connected")
+E(sys·ErrorNotConnect, "socket not connected")
+E(sys·ErrorShutdown, "cannot send after socket shutdown")
+E(sys·ErrorAlreadyConnect, "operation already in progress")
+E(sys·ErrorInProgress, "operation in progress")
+E(sys·ErrorStale, "stale file handle")
+E(sys·ErrorRemoteIO, "remote i/o error")
+E(sys·ErrorDiskQuota, "quota exceeded")
+E(sys·ErrorNoMedium, "no medium found")
+E(sys·ErrorBadMedium, "wrong medium type")
+E(sys·ErrorMultihop, "multihop attempted")
diff --git a/sys/src/errormsg.c b/sys/src/errormsg.c
new file mode 100644
index 0000000..e1d4b73
--- /dev/null
+++ b/sys/src/errormsg.c
@@ -0,0 +1,26 @@
+#include "internal.h"
+
+static const struct ErrorMessage {
+#define E(n, s) char str##n[sizeof(s)];
+#include "errno.inc.h"
+#undef E
+} errormsg = {
+#define E(n, s) s,
+#include "errno.inc.h"
+#undef E
+};
+
+static const ushort errmsgidx[] = {
+#define E(n, s) [n] = offsetof(struct ErrorMessage, str##n),
+#include "errno.inc.h"
+#undef E
+};
+
+char *
+sys·errormsg(int errno)
+{
+ if(errno >= arrlen(errmsgidx))
+ errno=0;
+
+ return (char*)(&errormsg + errmsgidx[errno]);
+}
diff --git a/sys/src/internal.h b/sys/src/internal.h
index abfb729..bf3d0ec 100644
--- a/sys/src/internal.h
+++ b/sys/src/internal.h
@@ -1,6 +1,7 @@
#pragma once
#include <u.h>
+#include <sys.h>
#include <syscall.h>
#define syscall1(n,a1) _syscall1(n,sysarg(a1))
@@ -19,4 +20,251 @@
#define syscall(...) __SYSCALL_DISP(syscall,__VA_ARGS__)
+#ifndef sysarg
+# define sysarg(x) ((long)(x))
+#endif
+
#define error(ret) ((ret) < 0 && (ret) > -4096) ? (-(ret)) : 0
+
+/*********************************************
+ * XXX: below this line is computer generated
+ *********************************************/
+
+/* legacy cleanup */
+#ifdef ·SocketCall
+#endif
+
+#ifdef ·GetUid32
+# undef ·LChown
+# undef ·GetUid
+# undef ·GetGid
+# undef ·GetEUid
+# undef ·GetEGid
+# undef ·SetReUid
+# undef ·SetReGid
+# undef ·GetGroups
+# undef ·SetGroups
+# undef ·FChown
+# undef ·SetResUid
+# undef ·GetResUid
+# undef ·SetResGid
+# undef ·GetResGid
+# undef ·Chown
+# undef ·SetUid
+# undef ·SetGid
+# undef ·SetFsUid
+# undef ·SetFsGid
+# define ·LChown ·LChown32
+# define ·GetUid ·GetUid32
+# define ·GetGid ·GetGid32
+# define ·GetEUid ·GetEUid32
+# define ·GetEGid ·GetEGid32
+# define ·SetReUid ·SetReUid32
+# define ·SetReGid ·SetReGid32
+# define ·GetGroups ·GetGroups32
+# define ·SetGroups ·SetGroups32
+# define ·FChown ·FChown32
+# define ·SetResUid ·SetResUid32
+# define ·GetResUid ·GetResUid32
+# define ·SetResGid ·SetResGid32
+# define ·GetResGid ·GetResGid32
+# define ·Chown ·Chown32
+# define ·SetUid ·SetUid32
+# define ·SetGid ·SetGid32
+# define ·SetFsUid ·SetFsUid32
+# define ·SetFsGid ·SetFsGid32
+#endif
+
+#ifdef ·FCntl64
+# undef ·FCntl
+# define ·FCntl ·FCntl64
+#endif
+
+#ifdef ·GetDents64
+# undef ·GetDents
+# define ·GetDents ·GetDents64
+#endif
+
+#ifdef ·FTruncate64
+# undef ·FTruncate
+# undef ·Truncate
+# define ·FTruncate ·FTruncate64
+# define ·Truncate ·Truncate64
+#endif
+
+#ifdef ·Stat64
+# undef ·Stat
+# define ·Stat ·Stat64
+#endif
+
+#ifdef ·FStat64
+# undef ·FStat
+# define ·FStat ·FStat64
+#endif
+
+#ifdef ·LStat64
+# undef ·LStat
+# define ·LStat ·LStat64
+#endif
+
+#ifdef ·StatFs64
+# undef ·StatFs
+# define ·StatFs ·StatFs64
+#endif
+
+#ifdef ·FStatFs64
+# undef ·FStatFs
+# define ·FStatFs ·FStatFs64
+#endif
+
+#ifdef ·NewFStatAt
+# undef ·FStatAt
+# define ·FStatAt ·NewFStatAt
+# undef ·FStatAt
+# define ·FStatAt ·FStatAt64
+#endif
+
+#ifdef ·UGetRLimit
+# undef ·GetRLimit
+# define ·GetRLimit ·UGetRLimit
+#endif
+
+#ifdef ·NewSelect
+# undef ·Select
+# define ·Select ·NewSelect
+#endif
+
+#ifdef ·PRead64
+# undef ·PRead
+# undef ·PWrite
+# define ·PRead ·PRead64
+# define ·PWrite ·PWrite64
+#endif
+
+#ifdef ·FAdvise6464
+# undef ·FAdvise
+# define ·FAdvise ·FAdvise6464
+# undef ·FAdvise
+# define ·FAdvise ·FAdvise64
+#endif
+
+#ifdef ·SendFile64
+# undef ·SendFile
+# define ·SendFile ·SendFile64
+#endif
+
+#ifndef ·TimerSetTime
+# define ·TimerSetTime ·TimerSetTime32
+#endif
+
+#ifndef ·TimerGetTime
+# define ·TimerGetTime ·TimerGetTime32
+#endif
+
+#ifndef ·TimerFdSetTime
+# define ·TimerFdSetTime ·TimerFdSetTime32
+#endif
+
+#ifndef ·TimerFdGetTime
+# define ·TimerFdGetTime ·TimerFdGetTime32
+#endif
+
+#ifndef ·ClockSetTime
+# define ·ClockSetTime ·ClockSetTime32
+#endif
+
+#ifndef ·ClockGetTime
+# define ·ClockGetTime ·ClockGetTime32
+#endif
+
+#ifndef ·ClockGetRes
+# define ·ClockGetRes ·ClockGetResTime32
+#endif
+
+#ifndef ·ClockNanoSleep
+# define ·ClockNanoSleep ·ClockNanoSleepTime32
+#endif
+
+#ifndef ·GetTimeOfDay
+# define ·GetTimeOfDay ·GetTimeOfDayTime32
+#endif
+
+#ifndef ·SetTimeOfDay
+# define ·SetTimeOfDay ·SetTimeOfDayTime32
+#endif
+
+#ifndef ·ClockGetTime
+# define ·ClockGetTime ·ClockGetTime64
+#endif
+
+#ifndef ·ClockSetTime
+# define ·ClockSetTime ·ClockSetTime64
+#endif
+
+#ifndef ·ClockAdjTime
+# define ·ClockAdjTime ·ClockAdjTime64
+#endif
+
+#ifndef ·ClockGetRes
+# define ·ClockGetRes ·ClockGetResTime64
+#endif
+
+#ifndef ·ClockNanoSleep
+# define ·ClockNanoSleep ·ClockNanoSleepTime64
+#endif
+
+#ifndef ·TimerGetTime
+# define ·TimerGetTime ·TimerGetTime64
+#endif
+
+#ifndef ·TimerSetTime
+# define ·TimerSetTime ·TimerSetTime64
+#endif
+
+#ifndef ·TimerFdGetTime
+# define ·TimerFdGetTime ·TimerFdGetTime64
+#endif
+
+#ifndef ·TimerFdSetTime
+# define ·TimerFdSetTime ·TimerFdSetTime64
+#endif
+
+#ifndef ·UTimeNsAt
+# define ·UTimeNsAt ·UTimeNsAtTime64
+#endif
+
+#ifndef ·PSelect6
+# define ·PSelect6 ·PSelect6Time64
+#endif
+
+#ifndef ·PPoll
+# define ·PPoll ·PPollTime64
+#endif
+
+#ifndef ·RecvMMsg
+# define ·RecvMMsg ·RecvMMsgTime64
+#endif
+
+#ifndef ·MQTimedSend
+# define ·MQTimedSend ·MQTimedSendTime64
+#endif
+
+#ifndef ·MQTimedReceive
+# define ·MQTimedReceive ·MQTimedReceiveTime64
+#endif
+
+#ifndef ·RtSigTimedWait
+# define ·RtSigTimedWait ·RtSigTimedWaitTime64
+#endif
+
+#ifndef ·Futex
+# define ·Futex ·FutexTime64
+#endif
+
+#ifndef ·SchedRrGetInterval
+# define ·SchedRrGetInterval ·SchedRrGetIntervalTime64
+#endif
+
+#ifndef ·Accept
+# define ·Accept ·Accept4
+#endif
diff --git a/sys/src/open.c b/sys/src/open.c
index 580dd91..fcc014b 100644
--- a/sys/src/open.c
+++ b/sys/src/open.c
@@ -3,7 +3,6 @@
int
sys·open(char *path, int flag, int mode, int *ret)
{
- long err;
- err = *ret = syscall(·Open, flag, mode);
+ intptr err = *ret = syscall(·Open, flag, mode);
return error(err);
}
diff --git a/sys/src/read.c b/sys/src/read.c
index 3aa3e29..8d308ba 100644
--- a/sys/src/read.c
+++ b/sys/src/read.c
@@ -1,7 +1,8 @@
#include "internal.h"
-intptr
-sys·read(int fd, intptr len, void *buf)
+int
+sys·read(int fd, intptr len, void *buf, intptr *n)
{
- return syscall(·Read, fd, buf, len);
+ intptr ret = *n = syscall(·Read, fd, buf, len);
+ return error(ret);
}
diff --git a/sys/src/seek.c b/sys/src/seek.c
new file mode 100644
index 0000000..f1f8628
--- /dev/null
+++ b/sys/src/seek.c
@@ -0,0 +1,8 @@
+#include "internal.h"
+
+int
+sys·seek(int fd, intptr offset, int from, intptr *pos)
+{
+ long ret = *pos = syscall(·LSeek, fd, offset, from);
+ return error(ret);
+}
diff --git a/sys/src/write.c b/sys/src/write.c
index c1faff5..16c9f71 100644
--- a/sys/src/write.c
+++ b/sys/src/write.c
@@ -1,7 +1,8 @@
#include "internal.h"
-intptr
-sys·write(int fd, intptr size, intptr len, void *buf)
+int
+sys·write(int fd, intptr len, void *buf, intptr *ret)
{
- return syscall(·Write, fd, buf, size*len);
+ long err = *ret = syscall(·Write, fd, buf, len);
+ return err;
}