mirror of
https://github.com/uselessd/alcove.git
synced 2026-04-15 09:15:19 +00:00
Add lseek(2)
This commit is contained in:
@@ -582,6 +582,13 @@ probably confuse the process.
|
||||
|
||||
kill(2) : terminate a process
|
||||
|
||||
lseek(Drv, FD, Offset, Whence) -> ok | {error, posix()}
|
||||
lseek(Drv, Pids, FD, Offset, Whence) -> ok | {error, posix()}
|
||||
|
||||
Types Offset = Whence = integer()
|
||||
|
||||
lseek(2) : set file offset for read/write
|
||||
|
||||
mkdir(Drv, Path, Mode) -> ok | {error, posix()}
|
||||
mkdir(Drv, Pids, Path, Mode) -> ok | {error, posix()}
|
||||
|
||||
|
||||
@@ -69,6 +69,11 @@
|
||||
? ERL_INT_UVALUE(x) \
|
||||
: ERL_LL_UVALUE(x))
|
||||
|
||||
#define ALCOVE_LL_VALUE(x) \
|
||||
((ERL_IS_INTEGER(x)) \
|
||||
? ERL_INT_VALUE(x) \
|
||||
: ERL_LL_VALUE(x))
|
||||
|
||||
#define ALCOVE_SETOPT(x,k,v) \
|
||||
(x)->opt = (v) ? (x)->opt | (k) : (x)->opt & ~(k)
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ getpid/0
|
||||
getrlimit/1
|
||||
getuid/0
|
||||
kill/2
|
||||
lseek/3
|
||||
mkdir/2
|
||||
mount/5
|
||||
mount_define/1
|
||||
|
||||
@@ -115,6 +115,51 @@ BADARG:
|
||||
return erl_mk_atom("badarg");
|
||||
}
|
||||
|
||||
/*
|
||||
* lseek(2)
|
||||
*
|
||||
*/
|
||||
ETERM *
|
||||
alcove_lseek(alcove_state_t *ap, ETERM *arg)
|
||||
{
|
||||
ETERM *hd = NULL;
|
||||
int fd = 0;
|
||||
off_t offset = 0;
|
||||
int whence = 0;
|
||||
|
||||
/* fd */
|
||||
arg = alcove_list_head(&hd, arg);
|
||||
if (!hd || !ERL_IS_INTEGER(hd))
|
||||
goto BADARG;
|
||||
|
||||
fd = ERL_INT_VALUE(hd);
|
||||
|
||||
/* offset */
|
||||
arg = alcove_list_head(&hd, arg);
|
||||
if (!hd || !ALCOVE_IS_LONGLONG(hd))
|
||||
goto BADARG;
|
||||
|
||||
offset = ALCOVE_LL_VALUE(hd);
|
||||
|
||||
/* whence */
|
||||
arg = alcove_list_head(&hd, arg);
|
||||
if (!hd || !ERL_IS_INTEGER(hd))
|
||||
goto BADARG;
|
||||
|
||||
offset = ERL_INT_VALUE(hd);
|
||||
|
||||
/* stdin, stdout, stderr, ctl are reserved */
|
||||
if (fd < 4)
|
||||
return alcove_errno(EBADF);
|
||||
|
||||
return (lseek(fd, offset, whence) == -1)
|
||||
? alcove_errno(errno)
|
||||
: erl_mk_atom("ok");
|
||||
|
||||
BADARG:
|
||||
return erl_mk_atom("badarg");
|
||||
}
|
||||
|
||||
/*
|
||||
* read(2)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user