ref: 3abef8578c5831bacfdaf0c16a1651052d2313fd
parent: c5a443dfdd529810012e9e9b5990bc4cb39493f6
author: Ori Bernstein <[email protected]>
date: Tue Sep 23 10:15:16 EDT 2014
Add unlink() syscall.
--- a/libstd/sys-linux.myr
+++ b/libstd/sys-linux.myr
@@ -557,6 +557,7 @@
const openmode : (path:byte[:], opts:fdopt, mode:int64 -> fd)
const close : (fd:fd -> int64)
const creat : (path:byte[:], mode:int64 -> fd)
+ const unlink : (path:byte[:] -> int)
const read : (fd:fd, buf:byte[:] -> size)
const write : (fd:fd, buf:byte[:] -> size)
const lseek : (fd:fd, off:uint64, whence:int64 -> int64)
@@ -670,6 +671,7 @@
const openmode = {path, opts, mode; -> syscall(Sysopen, cstring(path), a(opts), a(mode)) castto(fd)}
const close = {fd; -> syscall(Sysclose, a(fd))}
const creat = {path, mode; -> syscall(Syscreat, cstring(path), a(mode)) castto(fd)}
+const unlink = {path; -> syscall(Sysunlink, cstring(path)) castto(int)}
const read = {fd, buf; -> syscall(Sysread, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
const write = {fd, buf; -> syscall(Syswrite, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
const lseek = {fd, off, whence; -> syscall(Syslseek, a(fd), a(off), a(whence))}
--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -92,7 +92,7 @@
;;
type dirent64 = struct
- ino : uint64
+ ino : uint64
seekoff : uint64 /* seek offset (optional, used by servers) */
reclen : uint16 /* length of this record */
namlen : uint16 /* length of string in d_name */
@@ -166,7 +166,7 @@
const Mprotwr : mprot = 0x2
const Mprotexec : mprot = 0x4
const Mprotrw : mprot = 0x3
-
+
/* mmap options */
const Mshared : mopt = 0x1
const Mpriv : mopt = 0x2
@@ -567,6 +567,7 @@
const openmode : (path:byte[:], opts:fdopt, mode:int64 -> fd)
const close : (fd:fd -> int64)
const creat : (path:byte[:], mode:int64 -> fd)
+ const unlink : (path:byte[:] -> int)
const read : (fd:fd, buf:byte[:] -> size)
const write : (fd:fd, buf:byte[:] -> size)
const lseek : (fd:fd, off:uint64, whence:int64 -> int64)
@@ -587,8 +588,8 @@
const kevent : (q : fd, cl : kevent[:], el : kevent[:], flg : kflags, timeout : timespec# -> int64)
const kevent64 : (q : fd, cl : kevent64[:], el : kevent64[:], flg : kflags, timeout : timespec# -> int64)
-
+
/* networking */
const socket : (dom : sockfam, stype : socktype, proto : sockproto -> fd)
const connect : (sock : fd, addr : sockaddr#, len : size -> int)
@@ -614,7 +615,7 @@
const sysctl : (mib : int[:], old : byte[:]#, new : byte[:] -> int)
;;
-/*
+/*
wraps a syscall argument, converting it to 64 bits for the syscall function. This is
the same as casting, but more concise than writing castto(int64)
*/
@@ -647,7 +648,7 @@
const fork = {; -> __osx_fork()}
const wait4 = {pid, loc, opt, rusage; -> syscall(Syswait4, a(pid), a(loc), a(opt), a(rusage))}
const waitpid = {pid, loc, opt;
- -> wait4(pid, loc, opt, 0 castto(rusage#))
+ -> wait4(pid, loc, opt, 0 castto(rusage#))
}
const execv = {cmd, args
@@ -678,7 +679,7 @@
/*
copy the env.
of course we fucking have to duplicate this code everywhere,
- since we want to stack allocate...
+ since we want to stack allocate...
*/
p = alloca((env.len + 1)*sizeof(byte#))
cenv = (p castto(byte##))[:env.len]
@@ -696,6 +697,7 @@
const openmode = {path, opts, mode; -> syscall(Sysopen, cstring(path), a(opts), a(mode)) castto(fd)}
const close = {fd; -> syscall(Sysclose, a(fd))}
const creat = {path, mode; -> openmode(path, Ocreat | Otrunc | Owronly, mode) castto(fd)}
+const unlink = {path; -> syscall(Sysunlink, cstring(path)) castto(int)}
const read = {fd, buf; -> syscall(Sysread, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
const write = {fd, buf; -> syscall(Syswrite, a(fd), buf castto(byte#), a(buf.len)) castto(size)}
const lseek = {fd, off, whence; -> syscall(Syslseek, a(fd), a(off), a(whence))}
@@ -745,7 +747,7 @@
/* memory management */
const munmap = {addr, len; -> syscall(Sysmunmap, a(addr), a(len))}
-const mmap = {addr, len, prot, flags, fd, off;
+const mmap = {addr, len, prot, flags, fd, off;
-> syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) castto(byte#)}
/* time */
@@ -771,7 +773,7 @@
const clock_settime = {clk, ts
var tv
-
+
tv.sec = ts.sec
tv.usec = ts.nsec / 1000
-> settimeofday(&tv, 0 castto(timezone#))
@@ -778,7 +780,7 @@
}
/* system information */
-const uname = {buf;
+const uname = {buf;
var mib : int[2]
var ret
var sys