%{#
#include \
"libats/libc/CATS/stdio.cats"
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_EXTERN_PREFIX "atslib_libats_libc_"
#define RD(x) x
typedef SHR(a:type) = a
typedef NSH(a:type) = a
sortdef fm = file_mode
stadef r() = file_mode_r()
stadef w() = file_mode_w()
stadef rw() = file_mode_rw()
staload
TYPES =
"libats/libc/SATS/sys/types.sats"
stadef fildes = $TYPES.fildes
stadef fildes_v = $TYPES.fildes_v
absview
FILE_view(l:addr, m:fm)
absvtype
FILEptr_vtype(addr, fm) = ptr
viewdef
FILE_v(l:addr, m:fm) = FILE_view(l, m)
vtypedef
FILEptr(l:addr, m: fm) = FILEptr_vtype(l, m)
vtypedef
FILEptr0(m:fm) =
[l:addr | l >= null] FILEptr(l, m)
vtypedef
FILEptr1(m:fm) = [l:agz] FILEptr(l, m)
vtypedef
FILEptr1 = [l:agz;m:fm] FILEptr(l, m)
stadef fmlte = file_mode_lte
castfn
FILEptr2ptr
{l:addr}{m:fm}(filp: !FILEptr(l, m)):<> ptr(l)
overload ptrcast with FILEptr2ptr
castfn
FILEptr_encode
{l:addr}{m:fm}
(
pf: FILE_v(l, m) | p: ptr(l)
) : FILEptr(l, m)
overload encode with FILEptr_encode
castfn
FILEptr_decode
{l:agz}{m:fm}
(
p0: FILEptr(l, m)
) : (FILE_v(l, m) | ptr(l))
overload decode with FILEptr_decode
praxi
FILEptr_free_null
{l:alez}{m:fm}(p0: FILEptr(l, m)):<prf> void
castfn
FILEptr_refize(filp: FILEptr1):<> FILEref
castfn
FILEref_vttakeout
{m:fm}
(filr: FILEref):<> [l:agz] vttakeout0(FILEptr(l, m))
abst@ype whence_type = int
typedef whence = whence_type
macdef SEEK_SET = $extval(whence, "SEEK_SET")
macdef SEEK_CUR = $extval(whence, "SEEK_CUR")
macdef SEEK_END = $extval(whence, "SEEK_END")
fun
fopen{m:fm}
(
path: NSH(string), fmode(m)
) :<!wrt> FILEptr0(m) = "mac#%"
fun
fopen_exn{m:fm}
(
path: NSH(string), fmode(m)
) :<!exnwrt> FILEptr1(m) = "ext#%"
fun
fopen_ref_exn{m:fm}
(
path: NSH(string), fmode(m)
) :<!exnwrt> FILEref = "ext#%"
symintr fclose
symintr fclose_exn
fun
fclose0
(
filr: FILEref
) :<!wrt> int = "mac#%"
fun
fclose1
{l:addr}{m:fm}
(
filp: !FILEptr(l, m) >> ptr(l)
) :<!wrt>
[i:int | i <= 0]
(
option_v (FILE_v (l, m), i < 0) | int i
) = "mac#%"
overload fclose with fclose0
overload fclose with fclose1
fun
fclose0_exn
(filr: FILEref):<!exnwrt> void = "ext#%"
fun
fclose1_exn
(filp: FILEptr1):<!exnwrt> void = "ext#%"
overload fclose_exn with fclose0_exn
overload fclose_exn with fclose1_exn
symintr freopen
symintr freopen_exn
fun
freopen0{m2:fm}
(
path: NSH(string)
, mode: fmode(m2), filr: FILEref
) :<!wrt> Ptr0 = "mac#%"
fun
freopen1
{m1,m2:fm}{l0:addr}
(
path: NSH(string)
, mode: fmode(m2), filp: FILEptr(l0, m1)
) :<!wrt>
[
l:addr | l==null || l==l0
] (
option_v(FILE_v(l, m2), l > null) | ptr(l)
) = "mac#%"
fun
freopen0_exn{m2:fm}
(
path: NSH(string), mode: fmode(m2), filr: FILEref
) :<!exnwrt> void = "ext#%"
overload freopen with freopen0
overload freopen with freopen1
overload freopen_exn with freopen0_exn
fun
fileno0(filr: FILEref):<> int = "mac#%"
fun
fileno1(filp: !FILEptr1):<> int = "mac#%"
symintr fileno
overload fileno with fileno0
overload fileno with fileno1
dataview
fdopen_v
(
fd:int, addr, m: fmode
) =
| {l:agz}
fdopen_v_succ(fd, l, m) of FILE_v(l, m)
| fdopen_v_fail(fd, null, m) of fildes_v(fd)
fun
fdopen
{fd:int}{m:fm}
(
fd: fildes(fd), m: fmode(m)
) : [l:agez]
(
fdopen_v(fd, l, m) | ptr(l)
) = "mac#%"
fun
fdopen_exn
{fd:int}{m:fm}
(fd: fildes(fd), m: fmode (m)): FILEptr1(m) = "ext#%"
fun
feof0 (filr: FILEref):<> int = "mac#%"
fun
feof1 (filp: !FILEptr1):<> int = "mac#%"
symintr feof
overload feof with feof0
overload feof with feof1
fun
ferror0 (filr: FILEref):<> int = "mac#%"
fun
ferror1 (filp: !FILEptr1):<> int = "mac#%"
symintr ferror
overload ferror with ferror0
overload ferror with ferror1
fun
clearerr0
(filr: FILEref):<!wrt> void = "mac#%"
fun
clearerr1
(filp: !FILEptr1):<!wrt> void = "mac#%"
symintr clearerr
overload clearerr with clearerr0
overload clearerr with clearerr1
fun
fflush0
(out: FILEref):<!wrt> int = "mac#%"
fun
fflush1{m:fm}
(
pf: fmlte(m, w) | out: !FILEptr1(m)
) :<!wrt> [i:int | i <= 0] int(i) = "mac#%"
fun
fflush0_exn
(out: FILEref):<!exnwrt> void = "ext#%"
symintr fflush
symintr fflush_exn
overload fflush with fflush0
overload fflush with fflush1
overload fflush_exn with fflush0_exn
fun fflush_all ():<!exnwrt> void = "ext#%"
fun fflush_stdout ():<!exnwrt> void = "ext#%"
fun
fgetc0
(inp: FILEref):<!wrt> int = "mac#%"
fun
fgetc1 {m:fm}
(
pf: fmlte(m, r()) | inp: !FILEptr1(m)
) :<!wrt> intLte (UCHAR_MAX) = "mac#%"
symintr fgetc
overload fgetc with fgetc0
overload fgetc with fgetc1
macdef getc = fgetc
fun
getchar0():<!wrt> int = "mac#%"
fun
getchar1():<!wrt> [i:int|i <= UCHAR_MAX] int(i) = "mac#%"
fun
fgets0
{sz:int}{n0:pos | n0 <= sz}
(
buf: &b0ytes(sz) >> bytes(sz), n0: int n0, inp: FILEref
) :<!wrt> Ptr0 = "mac#%"
fun
fgets1
{sz:int}{n0:pos | n0 <= sz}{m:fm}
(
pfm: fmlte (m, r)
| buf: &b0ytes(sz) >> bytes(sz), n0: int n0, inp: !FILEptr1(m)
) :<!wrt> Ptr0 = "mac#%"
symintr fgets
overload fgets with fgets0
overload fgets with fgets1
dataview
fgets_v
(
sz:int, n0: int, addr, addr
) =
| {l0:addr}
fgets_v_fail (sz, n0, l0, null) of b0ytes(sz) @ l0
| {n:nat | n < n0} {l0:agz}
fgets_v_succ (sz, n0, l0, l0) of strbuf(sz, n) @ l0
fun
fgets1_err
{sz,n0:int
| 0 < n0
; n0 <= sz}
{l0:addr}{m:fm}
(
pf_mod: fmlte(m, r)
, pf_buf: b0ytes(sz)@l0
| p0: ptr(l0), n0: int(n0), inp: !FILEptr1(m)
) :<> [l1:addr] (fgets_v(sz, n0, l0, l1) | ptr(l1)) = "mac#%"
overload fgets with fgets1_err
fun
fgets0_gc
(bsz: intGte(1), inp: FILEref): Strptr0 = "ext#%"
fun
fgets1_gc{m:fm}
(
pf_mod: fmlte (m, r) | bsz: intGte(1), inp: FILEptr1(m)
) : Strptr0 = "ext#%"
abst@ype fpos_t = $extype"ats_fpos_type"
fun
fgetpos0
(
filp: FILEref, pos: &fpos_t? >> opt (fpos_t, i==0)
) :<!wrt> #[i:int | i <= 0] int (i) = "mac#%"
fun fgetpos1
(
filp: !FILEptr1, pos: &fpos_t? >> opt (fpos_t, i==0)
) :<!wrt> #[i:int | i <= 0] int (i) = "mac#%"
fun
fgetpos0_exn
(filp: FILEref, pos: &fpos_t? >> _) :<!exnwrt> void = "ext#%"
symintr fgetpos
symintr fgetpos_exn
overload fgetpos with fgetpos0
overload fgetpos with fgetpos1
overload fgetpos_exn with fgetpos0_exn
typedef
fputc0_type
(a:t0p) = (a, FILEref) -<0,!wrt> int
fun
fputc0_int : fputc0_type (int) = "mac#%"
fun
fputc0_char : fputc0_type (char) = "mac#%"
symintr fputc
overload fputc with fputc0_int of 0
overload fputc with fputc0_char of 0
typedef
fputc1_type
(a:t0p) = {m:fm}
(
fmlte (m, w()) | a, !FILEptr1 (m)
) -<0,!wrt> intLte (UCHAR_MAX)
fun fputc1_int : fputc1_type (int) = "mac#%"
fun fputc1_char : fputc1_type (char) = "mac#%"
overload fputc with fputc1_int of 10
overload fputc with fputc1_char of 10
typedef
fputc0_exn_type
(a:t0p) = (a, FILEref) -<0,!exnwrt> void
fun
fputc0_exn_int : fputc0_exn_type (int) = "ext#%"
fun
fputc0_exn_char : fputc0_exn_type (char) = "ext#%"
symintr fputc_exn
overload fputc_exn with fputc0_exn_int of 0
overload fputc_exn with fputc0_exn_char of 0
macdef putc = fputc
fun
putchar0 (c: int):<!wrt> int = "mac#%"
fun
putchar1
(c: int):<!wrt> [i:int|i <= UCHAR_MAX] int(i) = "mac#%"
fun
fputs0
(
str: NSH(string), fil: FILEref
) :<!wrt> int = "mac#%"
fun
fputs1{m:fm}
(
pf: fmlte(m, w()) | str: NSH(string), out: !FILEptr1(m)
) :<!wrt> int = "mac#%"
fun
fputs0_exn
(str: NSH(string), fil: FILEref):<!exnwrt> void = "ext#%"
symintr fputs
symintr fputs_exn
overload fputs with fputs0
overload fputs with fputs1
overload fputs_exn with fputs0_exn
fun
puts(inp: NSH(string)):<!wrt> int = "mac#%"
fun
puts_exn(inp: NSH(string)):<!exnwrt> void = "ext#%"
fun
fread0
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
(
buf: &bytes(nbf) >> _
, isz: size_t isz, n: size_t n
, inp: FILEref
) :<!wrt> sizeLte n = "mac#%"
fun
fread1
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
{m:fm}
(
pfm: fmlte (m, r)
| buf: &bytes(nbf) >> _
, isz: size_t isz, n: size_t n
, inp: !FILEptr1 (m)
) :<!wrt> sizeLte n = "mac#%"
fun
fread0_exn
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
(
buf: &bytes(nbf) >> _, isz: size_t isz, n: size_t n, inp: FILEref
) :<!exnwrt> sizeLte n = "ext#%"
symintr fread
symintr fread_exn
overload fread with fread0
overload fread with fread1
overload fread_exn with fread0_exn
fun
fwrite0
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
(
buf: &RD(bytes(nbf))
, isz: size_t isz, n: size_t n
, out: FILEref
) :<!wrt> sizeLte (n) = "mac#%"
fun
fwrite1
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
{m:fm}
(
pfm: fmlte(m, w())
| buf: &RD(bytes(nbf))
, isz: size_t isz, n: size_t n
, out: !FILEptr1 (m)
) :<!wrt> sizeLte (n) = "mac#%"
fun
fwrite0_exn
{isz:pos}
{nbf:int}
{n:int | n*isz <= nbf}
(
buf: &RD(bytes(nbf))
, isz: size_t isz, n: size_t n
, out: FILEref
) :<!exnwrt> sizeLte (n) = "ext#%"
symintr fwrite
symintr fwrite_exn
overload fwrite with fwrite0
overload fwrite with fwrite1
overload fwrite_exn with fwrite0_exn
fun
fseek0
(
filr: FILEref, offset: lint, whence: whence
) :<!wrt> int = "mac#%"
fun
fseek1
(
filp: !FILEptr1, offset: lint, whence: whence
) :<!wrt> int = "mac#%"
fun
fseek0_exn
(
filr: FILEref, offset: lint, whence: whence
) :<!exnwrt> void = "ext#%"
symintr fseek
symintr fseek_exn
overload fseek with fseek0
overload fseek with fseek1
overload fseek_exn with fseek0_exn
fun
fsetpos0
(filp: FILEref, pos: &RD(fpos_t)):<!wrt> int = "mac#%"
fun
fsetpos1
(filp: !FILEptr1, pos: &RD(fpos_t)):<!wrt> int = "mac#%"
fun
fsetpos0_exn
(filp: FILEref, pos: &RD(fpos_t)):<!exnwrt> void = "ext#%"
symintr fsetpos
symintr fsetpos_exn
overload fsetpos with fsetpos0
overload fsetpos with fsetpos1
overload fsetpos_exn with fsetpos0_exn
fun
ftell0
(filr: FILEref):<!wrt> lint = "mac#%"
fun
ftell1
(filp: !FILEptr1):<!wrt> lint = "mac#%"
fun
ftell0_exn
(filr: FILEref):<!exnwrt> lint = "ext#%"
symintr ftell
symintr ftell_exn
overload ftell with ftell0
overload ftell with ftell1
overload ftell_exn with ftell0_exn
fun
perror
(msg: NSH(string)):<!wrt> void = "mac#%"
abstype
pmode_type(m:fm) = string
typedef
pmode(m:fm) = pmode_type(m)
absview
popen_view(l:addr)
viewdef
popen_v(l:addr) = popen_view(l)
praxi
popen_v_free_null (pf: popen_v (null)): void
fun
popen{m:fm}
(
cmd: NSH(string), mode: pmode (m)
) : [l:addr] (popen_v (l) | FILEptr (l, m))
fun
popen_exn{m:fm}
(
cmd: NSH(string), mode: pmode (m)
) : FILEref = "ext#%"
fun
pclose0_exn (filr: FILEref): int = "ext#%"
fun
pclose1_exn
{l:agz}{m:fm}
(pf: popen_v l | filr: FILEptr (l, m)): int= "ext#%"
fun
remove
(inp: NSH(string)):<!wrt> int = "mac#%"
fun
remove_exn
(inp: NSH(string)):<!exnwrt> void = "ext#%"
fun rename
(
oldpath: NSH(string), newpath: NSH(string)
) :<!wrt> int = "mac#%"
fun rename_exn
(
oldpath: NSH(string), newpath: NSH(string)
) :<!exnwrt> void = "ext#%"
fun
rewind0
(fil: FILEref):<!wrt> void = "mac#%"
fun
rewind1
(fil: !FILEptr1):<!wrt> void = "mac#%"
symintr rewind
overload rewind with rewind0
overload rewind with rewind1
fun
tmpfile() :<!wrt> FILEptr0 (rw()) = "mac#%"
fun
tmpfile_exn() :<!exnwrt> FILEptr1 (rw()) = "ext#%"
fun
tmpfile_ref_exn() :<!exnwrt> FILEref = "ext#%"
fun
ungetc0
(c: char, f: FILEref):<!wrt> int = "mac#%"
fun
ungetc1
{l:agz}{m:fm}
(
pfm: fmlte (m, rw()) | c: char, f: !FILEptr (l, m)
) :<!wrt> [i:int | i <= UCHAR_MAX] int (i) = "mac#%"
fun
ungetc0_exn
(c: char, f: FILEref) :<!exnwrt> void = "ext#%"
symintr ungetc
symintr ungetc_exn
overload ungetc with ungetc0
overload ungetc with ungetc1
overload ungetc_exn with ungetc0_exn
stacst
BUFSIZ : int
praxi BUFSIZ_gtez (): [BUFSIZ >= 0] void
macdef BUFSIZ = $extval(int(BUFSIZ), "BUFSIZ")
abst@ype bufmode_t = int
macdef _IOFBF = $extval(bufmode_t, "_IOFBF")
macdef _IOLBF = $extval(bufmode_t, "_IOLBF")
macdef _IONBF = $extval(bufmode_t, "_IONBF")
fun
setbuf0_null
(f: FILEref): void = "mac#%"
fun
setbuf1_null
(f: !FILEptr1): void = "mac#%"
symintr setbuf_null
overload setbuf_null with setbuf0_null
overload setbuf_null with setbuf1_null
fun
setbuffer0
{n1,n2:nat | n2 <= n1}{l:addr}
(
pf_buf: !b0ytes(n1)@l
| filr: FILEref, p_buf: ptr(l), n2: size_t(n2)
) : void = "mac#%"
fun
setbuffer1
{ n1
, n2: nat
| n2 <= n1
}{lbf:addr}
(
pf_buf: !b0ytes(n1)@lbf
| filp: !FILEptr1, p_buf: ptr(lbf), n2: size_t(n2)
) : void = "mac#%"
symintr setbuffer
overload setbuffer with setbuffer0
overload setbuffer with setbuffer1
fun
setlinebuf0
(f: FILEref): void = "mac#%"
fun
setlinebuf1
(f: !FILEptr1): void = "mac#%"
symintr setlinebuf
overload setlinebuf with setlinebuf0
overload setlinebuf with setlinebuf1
fun
setvbuf0_null
(f: FILEref, mode: bufmode_t): int = "mac#%"
fun
setvbuf1_null
(f: !FILEptr1, mode: bufmode_t): int = "mac#%"
symintr setvbuf_null
overload setvbuf_null with setvbuf0_null
overload setvbuf_null with setvbuf1_null
fun
setvbuf0
{ n1
, n2:nat
| n2 <= n1
}{lbf:addr}
(
pf: !b0ytes(n1)@lbf
| filr: FILEref, mode: bufmode_t, n2: size_t(n2)
) : int = "mac#%"
fun
setvbuf1
{ n1
, n2 : nat
| n2 <= n1
}{lbf:addr}
(
pf: !b0ytes(n1) @ lbf
| filp: !FILEptr1, mode: bufmode_t, n2: size_t(n2)
) : int = "mac#%"
symintr setvbuf
overload setvbuf with setvbuf0
overload setvbuf with setvbuf1
%{#
//
#include \
"libats/libc/CATS/stdlib.cats"
//
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_EXTERN_PREFIX "atslib_libats_libc_"
vtypedef
RD(a:vt0p) = a
#define NSH(x) x
#define SHR(x) x
staload
STDDEF =
"libats/libc/SATS/stddef.sats"
typedef wchar_t = $STDDEF.wchar_t
macdef EXIT_FAILURE = $extval(int, "EXIT_FAILURE")
macdef EXIT_SUCCESS = $extval(int, "EXIT_SUCCESS")
abst@ype div_t = $extype"div_t"
abst@ype ldiv_t = $extype"ldiv_t"
abst@ype lldiv_t = $extype"lldiv_t"
fun _Exit (int): void = "mac#%"
fun atexit
(f: () -> void): int = "mac#%"
fun abort(): void = "mac#%"
fun abs(int):<> int = "mac#%"
fun labs(lint):<> lint = "mac#%"
fun llabs(lint):<> llint = "mac#%"
fun div(int, int):<> div_t
fun ldiv(lint, lint):<> ldiv_t
fun lldiv(llint, llint):<> lldiv_t
fun a64l(x: NSH(string)):<> lint = "mac#%"
fun l64a
{i:nat}
(
x: lint i
) :<!refwrt> [l:agz] vttakeout0(strptr(l)) = "mac#%"
fun atoi(x: NSH(string)):<> int = "mac#%"
fun atol(x: NSH(string)):<> lint = "mac#%"
fun atoll(x: NSH(string)):<> llint = "mac#%"
fun atof(x: NSH(string)):<> double = "mac#%"
fun strtol0
(nptr: string, base: intBtwe(2, 36)):<!wrt> lint = "mac#%"
fun strtol1
(nptr: string, endptr: &ptr? >> _, base: intBtwe(2, 36)):<!wrt> lint = "mac#%"
fun strtol_unsafe
(nptr: string, endptr: ptr, base: int):<!wrt> lint = "mac#%"
symintr strtol
overload strtol with strtol0
overload strtol with strtol1
fun strtoll0
(nptr: string, base: intBtwe(2, 36)):<!wrt> llint
fun strtoll1
(nptr: string, endptr: &ptr? >> _, base: intBtwe(2, 36)):<!wrt> llint
fun strtoll_unsafe
(nptr: string, endptr: ptr, base: int):<!wrt> llint
symintr strtoll
overload strtoll with strtoll0
overload strtoll with strtoll1
fun strtoul0
(nptr: string, base: intBtwe(2, 36)):<!wrt> ulint
fun strtoul1
(nptr: string, endptr: &ptr? >> _, base: intBtwe(2, 36)):<!wrt> ulint
fun strtoul_unsafe
(nptr: string, endptr: ptr, base: int):<!wrt> ulint
symintr strtoul
overload strtoul with strtoul0
overload strtoul with strtoul1
fun strtoull0
(nptr: string, base: intBtwe(2, 36)):<!wrt> ullint
fun strtoull1
(nptr: string, endptr: &ptr? >> _, base: intBtwe(2, 36)):<!wrt> ullint
fun strtoull_unsafe
(nptr: string, endptr: ptr, base: int):<!wrt> ullint
symintr strtoull
overload strtoull with strtoull0
overload strtoull with strtoull1
fun
strtof0
(nptr: string):<!wrt> float = "mac#%"
fun
strtof1
(nptr: string, endptr: &ptr? >> _):<!wrt> float = "mac#%"
fun strtof_unsafe
(nptr: string, endptr: ptr):<!wrt> float = "mac#%"
symintr strtof
overload strtof with strtof0
overload strtof with strtof1
fun
strtod0
(nptr: string):<!wrt> double = "mac#%"
fun
strtod1
(nptr: string, endptr: &ptr? >> _):<!wrt> double = "mac#%"
fun
strtod_unsafe
(nptr: string, endptr: ptr):<!wrt> double = "mac#%"
symintr strtod
overload strtod with strtod0
overload strtod with strtod1
fun
strtold0
(nptr: string):<!wrt> ldouble = "mac#%"
fun
strtold1
(nptr: string, endptr: &ptr? >> _):<!wrt> ldouble = "mac#%"
fun
strtold_unsafe
(nptr: string, endptr: ptr):<!wrt> ldouble = "mac#%"
symintr strtold
overload strtold with strtold0
overload strtold with strtold1
fun getenv
(
name: NSH(string)
) :<!ref> [l:addr] vttakeout0(strptr(l)) = "mac#%"
fun{} getenv_gc(name: NSH(string)):<!refwrt> Strptr0
fun putenv
(nameval: SHR(string)):<!refwrt> int = "mac#%"
fun setenv
(
name: NSH(string), value: NSH(string), overwrite: int
) :<!refwrt> int = "mac#%"
fun unsetenv
(name: NSH(string)):<!refwrt> int = "mac#%"
fun clearenv ():<!refwrt> int = "mac#%"
fun rand ():<!refwrt> int = "mac#%"
fun srand (seed: uint):<!refwrt> void = "mac#%"
fun rand_r (seed: &uint >> _):<> int = "mac#%"
fun random():<!refwrt> lint = "mac#%"
fun srandom(seed: uint):<!refwrt> void = "mac#%"
fun
initstate_unsafe
(
seed: uint, state: cPtr1(char), n: sizeGte(8)
) : cPtr0(char) = "mac#%"
fun setstate_unsafe
(state: cPtr1(char)):<!ref> cPtr0(char) = "mac#%"
fun drand48 ():<!ref> double = "mac#%"
fun erand48
(xsubi: &(@[usint][3])):<!ref> double = "mac#%"
fun lrand48 ():<!ref> lint = "mac#%"
fun nrand48
(xsubi: &(@[usint][3])):<!ref> lint = "mac#%"
fun mrand48 ():<!ref> lint = "mac#%"
fun jrand48
(xsubi: &(@[usint][3])):<!ref> lint = "mac#%"
fun srand48 (seedval: lint):<!ref> void = "mac#%"
fun seed48 (seed16v: &(@[usint][3])): Ptr1 = "mac#%"
fun lcong48 (param: &(@[usint][7])):<!ref> void = "mac#%"
fun bsearch
{a:vt0p}{n:int}
(
key: &RD(a)
, arr: &RD(@[INV(a)][n])
, asz: size_t (n), tsz: sizeof_t (a)
, cmp: cmpref (a)
) :<> Ptr0 = "mac#%"
fun qsort
{a:vt0p}{n:int}
(
A: &(@[INV(a)][n]), asz: size_t (n), tsz: sizeof_t (a), cmp: cmpref (a)
) :<!wrt> void = "mac#%"
fun
mblen_unsafe
(s: cPtr0(char), n: size_t):<!refwrt> int = "mac#%"
fun
wctomb_unsafe
(s: cPtr0(char), wc: wchar_t):<!refwrt> int = "mac#%"
fun
wcstombs_unsafe
(
dest: cPtr0(char), src: cPtr1(wchar_t), n: size_t
) :<!refwrt> ssize_t = "mac#%"
fun setkey_unsafe (key: cPtr1(char)):<!ref> void = "mac#%"
fun
mkstemp
{n:int | n >= 6}
(template: !strnptr(n)): int = "mac#%"
fun
mkostemp
{n:int | n >= 6}
(template: !strnptr(n), flags: int): int = "mac#%"
fun grantpt (fd: int): int = "mac#%"
dataview
malloc_libc_v
(addr, int) =
| {n:int}
malloc_libc_v_fail
(null, n)
| {l:agz}{n:int}
malloc_libc_v_succ
(l, n) of (b0ytes(n) @ l, mfree_libc_v(l))
fun
malloc_libc
{n:int}
(
bsz: size_t n
) :<!wrt>
[
l:addr
] (
malloc_libc_v(l, n) | ptr(l)
) = "mac#%"
fun
malloc_libc_exn
{n:int}
(
bsz: size_t(n)
) :<!wrt>
[
l:addr | l > null
] (
b0ytes(n)@l, mfree_libc_v(l) | ptr(l)
) = "mac#%"
fun mfree_libc
{l:addr}{n:int}
(
b0ytes(n)@l, mfree_libc_v(l) | ptr(l)
) :<!wrt> void = "mac#%"
fun system(command: NSH(string)): int = "mac#%"
%{#
#include \
"libats/libc/CATS/string.cats"
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_EXTERN_PREFIX "atslib_libats_libc_"
vtypedef
RD(a:vt0p) = a
#define NSH (x) x
#define SHR (x) x
fun strcmp (x1: string, x2: string):<> int = "mac#%"
fun strncmp (x1: string, x2: string, n: size_t):<> int = "mac#%"
fun strcoll (x1: string, x2: string):<> int = "mac#%"
fun strspn (x1: string, x2: string):<> size_t = "mac#%"
fun strcspn (x1: string, x2: string):<> size_t = "mac#%"
fun strlen
{n:int} (x: string n):<> size_t (n) = "mac#%"
fun strnlen {m,n:int}
(x: string n, max: size_t m):<> size_t (min(m,n)) = "mac#%"
fun strcat
{l:addr}{m:int}{n1,n2:int | n1+n2 < m}
(
!strbuf_v (l, m, n1) >> strbuf_v (l, m, n1+n2) | ptr (l), string (n2)
) :<!wrt> ptr (l) = "mac#%"
fun strcat_unsafe
{l:addr} (x1: ptr (l), x2: string):<!wrt> ptr (l) = "mac#%"
fun strncat_unsafe
{l:addr} (x1: ptr (l), x2: string, n: size_t):<!wrt> ptr (l) = "mac#%"
fun strcpy
{l:addr}{m:int}{n:int | n < m}
(
!b0ytes(m) @ l >> strbuf_v (l, m, n) | ptr (l), string (n)
) :<!wrt> ptr (l) = "mac#%"
fun strcpy_unsafe
{l:addr} (dst: ptr (l), src: string):<!wrt> ptr (l) = "mac#%"
fun strncpy_unsafe
{l:addr} (dst: ptr (l), src: string, n: size_t):<!wrt> ptr (l) = "mac#%"
absview strdup_view (l:addr)
viewdef strdup_v (l:addr) = strdup_view (l)
fun strdup
(
str: string
) :<!wrt> [l:addr] (strdup_v (l) | strptr (l)) = "mac#%"
fun strndup
(
str: string
) :<!wrt> [l:addr] (strdup_v (l) | strptr (l)) = "mac#%"
fun strdup_free
{l:addr} (pf: strdup_v (l) | x: strptr l):<!wrt> void = "mac#%"
absview strdupa_view (l:addr)
viewdef strdupa_v (l:addr) = strdupa_view (l)
fun strdupa
(
str: string
) :<!wrt> [l:addr] (strdupa_v (l) | strptr (l)) = "mac#%"
fun strndupa
(
str: string
) :<!wrt> [l:addr] (strdupa_v (l) | strptr (l)) = "mac#%"
fun strdupa_free
{l:addr} (pf: strdupa_v (l) | x: strptr l):<!wrt> void = "mac#%"
fun strfry {l:agz} (x: !strptr (l) >> _):<!wrt> ptr (l) = "mac#%"
fun memcpy
{l:addr}
{n1,n2:int}
{n:int | n <= n1; n <= n2}
(
pf: !b0ytes(n1) @ l >> bytes(n1) @ l
| dst: ptr (l), src: &RD(@[byte][n2]), n: size_t (n)
) :<!wrt> ptr (l) = "mac#%"
fun memcpy_unsafe{l:addr}
(dst: ptr (l), src: ptr, n: size_t):<!wrt> ptr (l) = "mac#%"
fun memset_unsafe{l:addr}
(dst: ptr (l), c: int, n: size_t): ptr (l) = "mac#%"
fun memmove_unsafe{l:addr}
(dst: ptr (l), src: ptr, n: size_t):<!wrt> ptr (l) = "mac#%"
fun memccpy_unsafe{l:addr}
(dst: ptr (l), src: ptr, c: int, n: size_t):<!wrt> Ptr0 = "mac#%"
fun mempcpy
{l:addr}
{n1,n2:int}
{n:int | n <= n1; n <= n2}
(
pf: !b0ytes(n1) @ l >> bytes(n1) @ l
| dst: ptr (l), src: &RD(@[byte][n2]), n: size_t (n)
) :<!wrt> ptr (l+n) = "mac#%"
fun mempcpy_unsafe{l:addr}{n:int}
(dst: ptr (l), src: ptr, n: size_t (n)):<!wrt> ptr (l+n) = "mac#%"
fun strerror
(errnum: int):<!ref> [l:agz] vttakeout0 (strptr l) = "mac#%"
fun strerror_r{n:int}
(errnum: int, buf: &bytes(n), n: size_t (n)):<> int = "mac#%"
fun strerror_r_gc (errnum: int):<> Strptr1 = "ext#%"
%{#
#include \
"libats/libc/CATS/unistd.cats"
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define ATS_EXTERN_PREFIX "atslib_libats_libc_"
#define SHR(x) x
#define NSH(x) x
typedef interr = int
staload
TYPES =
"libats/libc/SATS/sys/types.sats"
typedef off_t = $TYPES.off_t
typedef pid_t = $TYPES.pid_t
typedef uid_t = $TYPES.uid_t
typedef gid_t = $TYPES.gid_t
stadef fildes_v = $TYPES.fildes_v
vtypedef
fildes (i:int) = $TYPES.fildes (i)
vtypedef Fildes = $TYPES.Fildes
vtypedef Fildes0 = $TYPES.Fildes0
macdef STDIN_FILENO = $extval(int, "STDIN_FILENO")
macdef STDOUT_FILENO = $extval(int, "STDOUT_FILENO")
macdef STDERR_FILENO = $extval(int, "STDERR_FILENO")
symintr close
symintr close_exn
fun close0 (fd: int): interr = "mac#%"
dataview
close_v (fd:int, int) =
| close_v_succ (fd, 0) of ()
| {i:int | i < 0} close_v_fail (fd, i) of fildes_v (fd)
fun close1{fd:nat}
(fd: fildes (fd)): [i:int] (close_v (fd, i) | int i) = "mac#%"
overload close with close0
overload close with close1
fun close0_exn (fd: int): void = "ext#%"
fun close1_exn (fd: Fildes0):<!exn> void = "ext#%"
overload close_exn with close0_exn
overload close_exn with close1_exn
fun dup (fildes: int): int = "mac#%"
fun dup_fildes (fd: !Fildes0): Fildes = "mac#%"
fun dup2
(fildes: int, fildes2: int): int = "mac#%"
fun dup2_fildes{fd2:nat}
(fd: !Fildes0, fd2: int (fd2)): Fildes = "mac#%"
fun dup3
(fildes: int, fildes2: int, flags: int): int = "mac#%"
fun
execv
{n:pos}{l:addr}
(
pf: !parray_v (string, l, n) | path: NSH(string), argv: ptr l
) : intLt(0) = "mac#atslib_libats_libc_execv"
fun
execv_unsafe
(path: NSH(string), argv: ptr): intLt(0) = "mac#atslib_libats_libc_execv"
fun
execvp
{n:pos}{l:addr}
(
pf: !parray_v (string, l, n) | fname: NSH(string), argv: ptr l
) : intLt(0) = "mac#atslib_libats_libc_execvp"
fun
execvp_unsafe
(fname: NSH(string), argv: ptr): intLt(0) = "mac#atslib_libats_libc_execvp"
fun
execve
{n1,n2:pos}
{l1,l2:addr}
(
pf1: !parray_v(string, l1, n1)
, pf2: !parray_v(string, l2, n2)
| fname: NSH(string), argv: ptr(l1), envp: ptr(l2)
) : intLt(0) = "mac#atslib_libats_libc_execve"
fun
execve_unsafe
(
fname: NSH(string), argv: ptr, envp: ptr
) : intLt(0) = "mac#atslib_libats_libc_execve"
fun
encrypt
(
block: &(@[char][64]), edflag: int
) :<!ref> void = "mac#%"
fun fork (): pid_t = "mac#%"
dataview
getcwd_v
(
m:int, l:addr, addr
) =
| {l>null}{n:nat}
getcwd_v_succ(m, l, l) of strbuf_v(l, m, n)
| getcwd_v_fail(m, l, null) of b0ytes(m) @ (l)
fun getcwd
{m:nat} {l:addr}
(
pf: !b0ytes(m)@l >> getcwd_v(m, l, l1) | p: ptr(l), m: size_t(m)
) : #[l1:addr] ptr (l1) = "mac#%"
fun getcwd_gc (): Strptr0 = "ext#%"
fun getpid (): pid_t = "mac#%"
fun getppid (): pid_t = "mac#%"
fun getuid(): uid_t = "mac#%"
fun setuid(uid: uid_t): int = "mac#%"
fun geteuid(): uid_t = "mac#%"
fun seteuid(uid: uid_t): int = "mac#%"
fun getgid(): gid_t = "mac#%"
fun setgid(gid: gid_t): int = "mac#%"
fun getegid(): gid_t = "mac#%"
fun setegid(gid: gid_t): int = "mac#%"
fun setreuid(ruid: uid_t, euid: uid_t): int = "mac#%"
fun setregid(rgid: gid_t, egid: gid_t): int = "mac#%"
fun setresuid(ruid: uid_t, euid: uid_t, suid: uid_t): int = "mac#%"
fun setresgid(rgid: gid_t, egid: gid_t, sgid: gid_t): int = "mac#%"
fun setfsuid(fsuid: uid_t): int = "mac#%"
fun setfsgid(fsgid: gid_t): int = "mac#%"
fun getlogin(): vStrptr0 = "mac#%"
fun getlogin_r
{n:int | n >= 2}
(buf: &bytes(n), size_t(n)): int = "mac#%"
fun getlogin_r_gc(): Strptr0 = "ext#%"
fun pause (): int = "mac#%"
fun read_err
{sz,n:nat | n <= sz}
(
fd: !Fildes0
, buf: &b0ytes(sz) >> bytes(sz), ntotal: size_t(n)
) : ssizeBtw(~1, n+1) = "mac#%"
fun write_err
{sz,n:nat | n <= sz}
(
fd: !Fildes0, buf: &RD(bytes(sz)), ntotal: size_t(n)
) : ssizeBtw(~1, n+1) = "mac#%"
fun pread{n:int}
(
fd: !Fildes0, buf: &(@[byte][n])>>_, n: size_t (n), ofs: off_t
) : ssize_t = "mac#%"
fun pwrite{n:int}
(
fd: !Fildes0, buf: &RD(array(byte, n)), n: size_t (n), ofs: off_t
) : ssize_t = "mac#%"
absview
alarm_v(n: int)
praxi
alarm_v_elim (pfrem: alarm_v(0)): void
fun
alarm_set{i:int}
(t: uint(i)): (alarm_v(i) | uInt) = "mac#%"
fun
alarm_cancel{i:int}
(pf: alarm_v(i) | ): uInt = "mac#%"
fun sleep_int
{i:nat} (t: int i): [j:nat | j <= i] int j = "mac#%"
fun sleep_uint
{i:int} (t: uint i): [j:nat | j <= i] uint j = "mac#%"
symintr sleep
overload sleep with sleep_int
overload sleep with sleep_uint
fun usleep_int
{i:nat | i <= 1000000} (n: int i): intLte(0) = "mac#%"
fun usleep_uint
{i:int | i <= 1000000} (n: uint i): intLte(0) = "mac#%"
symintr usleep
overload usleep with usleep_int
overload usleep with usleep_uint
fun rmdir (path: NSH(string)): int = "mac#%"
fun rmdir_exn (path: NSH(string)): void = "ext#%"
fun link
(
old: NSH(string)
, new: NSH(string)
) :<!ref> intLte(0) = "mac#%"
fun link_exn
(old: NSH(string), new: NSH(string)):<!ref> void = "ext#%"
fun symlink
(
old: NSH(string)
, new: NSH(string)
) :<!ref> intLte(0) = "mac#%"
fun symlink_exn
(old: NSH(string), new: NSH(string)):<!ref> void = "ext#%"
fun unlink (path: NSH(string)):<!ref> intLte(0) = "mac#%"
fun unlink_exn (path: NSH(string)):<!exnref> void = "ext#%"
fun readlink{n:int}
(
path: NSH(string), buf: &(@[byte][n]) >> _, n: size_t (n)
) : ssizeLte(n) = "mac#%"
fun readlink_gc (path: NSH(string)): Strptr0 = "ext#%"
fun sync (): void = "mac#%"
fun fsync (fd: !Fildes0): int = "mac#%"
fun fdatasync (fd: !Fildes0): int = "mac#%"
fun truncate
(path: NSH(string), ofs: off_t): int = "mac#%"
fun ftruncate (fd: !Fildes0, ofs: off_t): int = "mac#%"
#include "./unistd_sysconf.sats"
#include "./unistd_pathconf.sats"
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_DYNLOADFLAG 0
#define
ATS_EXTERN_PREFIX
"atslib_libats_libc_"
%{^
#include "share/H/pats_atslib.h"
%}
staload "libats/libc/SATS/stdio.sats"
%{$
//
extern
atstype_ptr
atslib_libats_libc_fopen_exn
(
atstype_string path
, atstype_string mode
) {
FILE *filp ;
filp = fopen ((char*)path, (char*)mode) ;
if (!filp) ATSLIBfailexit("fopen") ; // HX: failure
return filp ;
} /* end of [atslib_libats_libc_fopen_exn] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_fclose_exn
(atstype_ptr filp) {
int err ;
err = fclose ((FILE*)filp) ;
if (0 > err) ATSLIBfailexit("fclose") ;
return ;
} /* end of [atslib_libats_libc_fclose_exn] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_fflush_exn
(
atstype_ptr filp
) {
int err = fflush((FILE*)filp) ;
if (0 > err) ATSLIBfailexit("fflush") ;
return ;
} /* end of [atslib_libats_libc_fflush_exn] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_fputc_exn
(
atstype_int c, atstype_ptr filp
) {
int err ;
err = fputc(c, (FILE*)filp) ;
if (0 > err) {
ATSLIBfailexit("fputc") ; // abnormal exit
} // end of [if]
return ;
} /* end of [atslib_libats_libc_fputc_exn] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_fgets_exn
(
atstype_ptr buf0
, atstype_int bsz0
, atstype_ptr filp
) {
char *buf, *pres ;
buf = (char*)buf0 ;
pres = fgets(buf, (int)bsz0, (FILE*)filp) ;
if (!pres)
{
if (feof((FILE*)filp))
{
buf[0] = '\000' ; // EOF is reached
} else {
ATSLIBfailexit("fgets") ; // abnormal exit
} // end of [if]
} // end of [if]
return ;
} /* end of [atslib_libats_libc_fgets_exn] */
//
%}
%{$
//
extern
atstype_ptr
atslib_libats_libc_fgets_gc
(
atstype_int bsz0
, atstype_ptr filp0
)
{
int bsz = bsz0 ;
FILE *filp = (FILE*)filp0 ;
int ofs = 0, ofs2 ;
char *buf, *buf2, *pres ;
buf = atspre_malloc_gc(bsz) ;
while (1) {
buf2 = buf+ofs ;
pres = fgets(buf2, bsz-ofs, filp) ;
if (!pres)
{
if (feof(filp))
{
*buf2 = '\000' ; return buf ;
} else {
atspre_mfree_gc(buf) ; return (char*)0 ;
} // end of [if]
}
ofs2 = strlen(buf2) ;
if (ofs2==0) return buf ;
ofs += ofs2 ; // HX: ofs > 0
if (buf[ofs-1]=='\n') return buf ;
bsz *= 2 ; buf2 = buf ;
buf = atspre_malloc_gc(bsz) ;
memcpy(buf, buf2, ofs) ;
atspre_mfree_gc(buf2) ;
} // end of [while]
return buf ; // HX: deadcode
} /* end of [atslib_libats_libc_fgets_gc] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_fputs_exn
(
atstype_string str, atstype_ptr filp
) {
int err ;
err = fputs((char*)str, (FILE*)filp) ;
if (0 > err) {
ATSLIBfailexit("fputs") ; // abnormal exit
} // end of [if]
return ;
} /* end of [atslib_libats_libc_fputs_exn] */
//
%}
%{$
//
extern
atsvoid_t0ype
atslib_libats_libc_puts_exn
(
atstype_string str
) {
int err ;
err = puts((char*)str) ;
if (0 > err) {
ATSLIBfailexit("puts") ; // abnormal exit
} // end of [if]
return ;
} /* end of [atslib_libats_libc_puts_exn] */
//
%}
%{$
//
extern
atstype_ptr
atslib_libats_libc_popen_exn
(
atstype_string cmd
, atstype_string type
) {
FILE *filp ;
filp = popen((char*)cmd, (char*)type) ;
if (!filp) {
ATSLIBfailexit("popen") ; // abnormal exit
} // end of [if]
return filp ;
} /* end of [atslib_libats_libc_popen_exn] */
//
%}
%{$
//
extern
atstype_int
atslib_libats_libc_pclose_exn
(
atstype_ptr filp
) {
int res ;
res = pclose((FILE*)filp) ;
if (0 > res) {
ATSLIBfailexit("pclose") ; // abnormal exit
} // end of [if]
return res ;
} /* end of [atslib_libats_libc_pclose_exn] */
//
%}
%{$
//
extern
atstype_ptr
atslib_libats_libc_tmpfile_exn
(
// argumentless
) {
FILE *filp = tmpfile() ;
if (!filp) ATSLIBfailexit("tmpfile") ;
return (filp) ;
} /* end of [atslib_libats_libc_tmpfile_exn] */
//
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_DYNLOADFLAG 0
#define
ATS_EXTERN_PREFIX
"atslib_libats_libc_"
%{^
//
#include "share/H/pats_atslib.h"
//
%}
staload "libats/libc/SATS/stdlib.sats"
implement
{}
getenv_gc
(name) = str2 where
{
val
fpfstr = getenv(name)
val str2 = strptr0_copy(fpfstr.1)
prval () = fpfstr.0(fpfstr.1)
}
%{$
//
extern
atstype_ptr
atslib_libats_libc_malloc_libc_exn
(atstype_size bsz)
{
void *p0 ;
p0 = atslib_libats_libc_malloc_libc(bsz) ;
if (!p0) {
fprintf(stderr, "exit(ATSLIB): [malloc] failed\n") ; exit(1) ;
} // end of [if]
return p0 ;
} /* end of [atslib_libats_libc_malloc_libc_exn] */
//
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_DYNLOADFLAG 0
#define
ATS_EXTERN_PREFIX
"atslib_libats_libc_"
staload
"libats/libc/SATS/string.sats"
%{$
extern
atstype_ptr
atslib_libats_libc_strerror_r_gc
(
atstype_int errnum
) {
char *p_err ;
int bsz ;
int myerr, myeno ;
//
// HX: [64] is chosen nearly randomly
//
bsz = 64 ;
p_err = (char*)0 ;
//
while (1)
{
p_err = atspre_malloc_gc(bsz) ;
myerr = atslib_libats_libc_strerror_r(errnum, p_err, bsz) ; myeno = errno ;
if (!myerr) return p_err ;
if (myeno != ERANGE) break ;
atspre_mfree_gc(p_err) ; bsz = 2 * bsz ;
}
//
return p_err ;
//
} /* end of [atslib_libats_libc_strerror_r_gc] */
%}
#define
ATS_PACKNAME "ATSLIB.libats.libc"
#define
ATS_DYNLOADFLAG 0
#define
ATS_EXTERN_PREFIX "atslib_libats_libc_"
%{^
#include"share/H/pats_atslib.h"
%}
staload "libats/libc/SATS/errno.sats"
staload "libats/libc/SATS/fcntl.sats"
staload "libats/libc/SATS/unistd.sats"
%{$
extern
atsvoid_t0ype
atslib_libats_libc_close_exn
(
atstype_int fd
) {
int err ;
err = atslib_libats_libc_close(fd) ;
if (0 > err) ATSLIBfailexit("close") ;
return ;
} /* end of [atslib_libats_libc_close_exn] */
%}
%{$
extern
atstype_int
atslib_libats_libc_dup2_fildes
(
atstype_int fd, atstype_int fd2
) {
int flags ;
//
flags = fcntl(fd, F_GETFD) ;
//
if (flags >= 0) {
errno = EINVAL ; return -1 ; // [fd2] in use
} /* end of [if] */
//
return atslib_libats_libc_dup2(fd, fd2) ;
//
} /* end of [atslib_libats_libc_dup2_fildes] */
%}
%{$
extern
atstype_strptr
atslib_libats_libc_getcwd_gc (
) {
char *p_cwd ;
int bsz ;
int myeno ;
char *p2_cwd ;
//
// HX: [64] is chosen nearly randomly
//
bsz = 64 ;
p_cwd = (char*)0 ;
//
while (1)
{
p_cwd = atspre_malloc_gc(bsz) ;
p2_cwd = atslib_libats_libc_getcwd(p_cwd, bsz) ; myeno = errno ;
if (p2_cwd != 0) return p_cwd ; else atspre_mfree_gc(p_cwd) ;
if (myeno != ERANGE) break ;
bsz = 2 * bsz ;
}
//
return (char*)0 ;
//
} /* end of [atslib_libats_libc_getcwd_gc] */
%}
%{$
extern
atstype_strptr
atslib_libats_libc_getlogin_r_gc (
) {
char *p_uid ;
int bsz ;
int err, myeno ;
//
// HX: [16] is chosen nearly randomly
//
bsz = 16 ;
p_uid = (char*)0 ;
//
while (1)
{
p_uid = atspre_malloc_gc(bsz) ;
err = atslib_libats_libc_getlogin_r(p_uid, bsz) ; myeno = errno ;
if (err==0) return p_uid ; else atspre_mfree_gc(p_uid) ;
if (myeno != ERANGE) break ;
bsz = 2 * bsz ;
}
//
return (char*)0 ;
//
} /* end of [atslib_libats_libc_getlogin_r_gc] */
%}
%{$
extern
atsvoid_t0ype
atslib_libats_libc_rmdir_exn
(
atstype_string path
) {
int err ;
err = atslib_libats_libc_rmdir(path) ;
if (0 > err) ATSLIBfailexit("rmdir") ;
return ;
} /* end of [atslib_libats_libc_rmdir_exn] */
%}
%{$
extern
atsvoid_t0ype
atslib_libats_libc_link_exn
(
atstype_string old, atstype_string new
) {
int err ;
err = atslib_libats_libc_link(old, new) ;
if (0 > err) ATSLIBfailexit("link") ;
return ;
} /* end of [atslib_libats_libc_link_exn] */
%}
%{$
extern
atsvoid_t0ype
atslib_libats_libc_unlink_exn
(
atstype_string path
) {
int err ;
err = atslib_libats_libc_unlink(path) ;
if (0 > err) ATSLIBfailexit("unlink") ;
return ;
} /* end of [atslib_libats_libc_unlink_exn] */
%}
%{$
extern
atsvoid_t0ype
atslib_libats_libc_symlink_exn
(
atstype_string old, atstype_string new
) {
int err ;
err = atslib_libats_libc_symlink(old, new) ;
if (0 > err) ATSLIBfailexit("symlink") ;
return ;
} /* end of [atslib_libats_libc_symlink_exn] */
%}
%{$
extern
atstype_strptr
atslib_libats_libc_readlink_gc
(
atstype_string path
) {
char *bfp ;
//
// HX: [64] is chosen nearly randomly
//
int bsz = 64 ;
ssize_t bsz2 ;
bfp = (char*)0 ;
//
while (1)
{
bfp = atspre_malloc_gc(bsz) ;
bsz2 = atslib_libats_libc_readlink(path, bfp, bsz) ;
/*
fprintf(stderr, "atslib_libats_libc_readlink_gc: bsz2 = %li\n", bsz2) ;
*/
if (bsz2 < 0) {
atspre_mfree_gc(bfp) ; break ;
}
if (bsz2 < bsz) {
bfp[bsz2] = '\000' ; return bfp ;
}
atspre_mfree_gc(bfp) ; bsz *= 2 ;
}
//
return (char*)0 ; // HX: deadcode
//
} /* end of [atslib_libats_libc_readlink_gc] */
%}