1: \ syscalls386.fs
2: \
3: \ Selected Unix system calls for gforth >=0.7.x
4:
5: \ Replacement for the original non-portable syscalls386 implementation
6: \ this one ports to other Gforth installations, other architectures,
7: \ and other Unix implementations.
8:
9: \ The following original note is probably still applicable.
10:
11: \ 3) Compatibility with low-level kForth words is maintained to allow
12: \ kForth code to be used under gforth, e.g. serial.fs, terminal.fs.
13: \ Other driver interface examples from kForth should also
14: \ work, e.g. the National Instruments GPIB interface nigpib.4th.
15:
16: c-library syscalls386
17:
18: \c #include <sys/types.h>
19: \c #include <sys/stat.h>
20: \c #include <fcntl.h>
21: \c #include <unistd.h>
22: \c #include <sys/ioctl.h>
23:
24: \ sysexit ( code -- | exit to system with code )
25: \ sysexit is NOT the recommended way to exit back to the
26: \ system from Forth. It is provided here as a demo of a very
27: \ simple syscall.
28: c-function sysexit _exit n -- void
29: c-function getpid getpid -- n ( -- u | get process id )
30: c-function open open a n -- n ( ^zaddr flags -- fd )
31: \ file descriptor is returned)
32: \ Note zaddr points to a buffer containing the counted filename
33: \ string terminated with a null character.
34: c-function close close n -- n ( fd -- flag )
35: c-function read read n a n -- n ( fd buf count -- n )
36: \ read count byes into buf from file
37: c-function write write n a n -- n ( fd buf count -- n )
38: \ write count bytes from buf to file
39: c-function lseek lseek n n n -- n ( fd offset type -- offs )
40: \ reposition the file ptr
41: c-function ioctl ioctl n n a -- n ( fd request argp -- error )
42:
43: end-c-library
44:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>