%{#
#include "libc/CATS/stdio.cats"
%}
staload TYPES = "libc/sys/SATS/types.sats"
typedef whence_t = $TYPES.whence_t
macdef SEEK_SET = $TYPES.SEEK_SET
macdef SEEK_CUR = $TYPES.SEEK_CUR
macdef SEEK_END = $TYPES.SEEK_END
sortdef fm = file_mode
typedef bytes (n:int) = @[byte][n]
typedef b0ytes (n:int) = @[byte?][n]
viewdef FILE_v (m:fm, l:addr) = FILE m @ l
viewdef FILEopt_v (m:fm, l:addr) = option_v (FILE m @ l, l > null)
praxi stdin_isnot_null : [stdin_addr > null] void
praxi stdout_isnot_null : [stdout_addr > null] void
praxi stderr_isnot_null : [stderr_addr > null] void
macdef EOF = $extval (int, "EOF")
symintr clearerr
fun clearerr0 (f: FILEref):<> void = "atslib_clearerr"
overload clearerr with clearerr0
fun clearerr1 {m:fm} (f: &FILE m):<> void = "atslib_clearerr"
overload clearerr with clearerr1
symintr fclose_err
fun fclose0_err
(r: FILEref):<> int = "atslib_fclose_err"
overload fclose_err with fclose0_err
fun fclose1_err
{m:fm} {l:addr} (
pf: !FILE_v (m, l) >> option_v (FILE_v (m, l), i < 0) | p: ptr l
) :<> #[i:int | i <= 0] int i
= "atslib_fclose_err"
overload fclose_err with fclose1_err
symintr fclose_exn
fun fclose0_exn
(r: FILEref):<!exn> void = "atslib_fclose_exn"
overload fclose_exn with fclose0_exn
fun fclose1_exn
{m:fm} {l:addr} (pf: FILE m @ l | p: ptr l):<!exn> void
= "atslib_fclose_exn"
overload fclose_exn with fclose1_exn
fun fclose1_loop {m:fm} {l:addr} (pf: FILE m @ l | p: ptr l):<> int
fun fclose_stdin ():<!exnref> void = "atslib_fclose_stdin"
fun fclose_stdout ():<!exnref> void = "atslib_fclose_stdout"
fun fclose_stderr ():<!exnref> void = "atslib_fclose_stderr"
symintr feof
fun feof0 (f: FILEref):<> int = "atslib_feof"
overload feof with feof0
fun feof1 {m:fm} (f: &FILE m):<> int = "atslib_feof"
overload feof with feof1
symintr ferror
fun ferror0 (f: FILEref):<> int = "atslib_ferror"
overload ferror with ferror0
fun ferror1 {m:fm} (f: &FILE m):<> int = "atslib_ferror"
overload ferror with ferror1
symintr fflush_err
fun fflush0_err (f: FILEref):<> int = "atslib_fflush_err"
overload fflush_err with fflush0_err
fun fflush1_err {m:fm}
(pf: file_mode_lte (m, w) | f: &FILE m):<> [i:int | i <= 0] int i
= "atslib_fflush_err"
overload fflush_err with fflush1_err
symintr fflush_exn
fun fflush0_exn (f: FILEref):<!exn> void = "atslib_fflush_exn"
overload fflush_exn with fflush0_exn
fun fflush1_exn {m:fm}
(pf: file_mode_lte (m, w) | f: &FILE m):<!exn> void
= "atslib_fflush_exn"
overload fflush_exn with fflush1_exn
fun fflush_stdout ():<!exnref> void = "atslib_fflush_stdout"
symintr fgetc_err
fun fgetc0_err (f: FILEref):<> int = "atslib_fgetc_err"
overload fgetc_err with fgetc0_err
fun fgetc1_err {m:fm} (pf: file_mode_lte (m, r) | f: &FILE m):<> [i:int | i <= UCHAR_MAX] int i
= "atslib_fgetc_err"
overload fgetc_err with fgetc1_err
abst@ype
fpos_t = $extype "ats_fpos_type"
dataview fgetpos_v (addr, int) =
| {l:addr} fgetpos_v_succ (l, 0) of fpos_t @ l
| {l:addr} {i:int | i < 0} fgetpos_v_fail (l, i) of fpos_t? @ l
fun fgetpos {m:fm} {l_pos:addr}
(pf: fpos_t? @ l_pos | f: &FILE m, p: ptr l_pos)
:<> [i:int | i <= 0] (fgetpos_v (l_pos, i) | int i)
= "atslib_fgetpos"
dataview
fgets_v (sz:int, addr, addr) =
| {l_buf:addr}
fgets_v_fail (sz, l_buf, null) of b0ytes (sz) @ l_buf
| {n:nat | n < sz} {l_buf:addr | l_buf > null}
fgets_v_succ (sz, l_buf, l_buf) of strbuf (sz, n) @ l_buf
fun fgets_err
{sz,n:int | 0 < n; n <= sz}
{m:fm} {l_buf:addr} (
pf_mod: file_mode_lte (m, r)
, pf_buf: b0ytes (sz) @ l_buf
| p: ptr l_buf, n: int n, f: &FILE m
) :<> [l:addr] (fgets_v (sz, l_buf, l) | ptr l)
= "atslib_fgets_err"
fun fgets_exn
{sz,n0:int | 0 < n0; n0 <= sz}
{m:fm} {l_buf:addr} (
pf_mod: file_mode_lte (m, r),
pf_buf: !b0ytes (sz) @ l_buf >>
[n:nat | n < n0] strbuf (sz, n) @ l_buf
| p: ptr l_buf, n0: int n0, f: &FILE m
) :<!exn> void = "atslib_fgets_exn"
symintr fileno
fun fileno0 (f: FILEref):<> int = "atslib_fileno"
overload fileno with fileno0
fun fileno1 {m:fm} (f: &FILE m):<> int = "atslib_fileno"
overload fileno with fileno1
fun fopen_err {m:fm}
(path: string, m: file_mode m):<!ref> [l:addr] (FILEopt_v (m, l) | ptr l)
= "atslib_fopen_err"
fun fopen_exn {m:fm}
(path: string, m: file_mode m):<!exnref> [l:addr] (FILE m @ l | ptr l)
= "atslib_fopen_exn"
fun fopen_ref_exn {m:fm}
(path: string, m: file_mode m):<!exnref> FILEref
= "atslib_fopen_exn"
symintr fputc_err
fun fputc0_err
(c: char, f: FILEref):<> int = "atslib_fputc_err"
overload fputc_err with fputc0_err
fun fputc1_err {m:fm}
(pf: file_mode_lte (m, w) | c: char, f: &FILE m)
:<> [i:int | i <= UCHAR_MAX] int i
= "atslib_fputc_err"
overload fputc_err with fputc1_err
symintr fputc_exn
fun fputc0_exn
(c: char, f: FILEref):<!exn> void = "atslib_fputc_exn"
overload fputc_exn with fputc0_exn
fun fputc1_exn {m:fm}
(pf: file_mode_lte (m, w) | c: char, f: &FILE m):<!exn> void
= "atslib_fputc_exn"
overload fputc_exn with fputc1_exn
symintr fputs_err
fun fputs0_err
(str: string, fil: FILEref):<> int = "atslib_fputs_err"
overload fputs_err with fputs0_err
fun fputs1_err {m:fm}
(pf: file_mode_lte (m, w) | str: string, f: &FILE m):<> int
= "atslib_fputs_err"
overload fputs_err with fputs1_err
symintr fputs_exn
fun fputs0_exn
(str: string, fil: FILEref):<!exn> void = "atslib_fputs_exn"
overload fputs_exn with fputs0_exn
fun fputs1_exn {m:fm}
(pf: file_mode_lte (m, w) | str: string, f: &FILE m):<!exn> void
= "atslib_fputs_exn"
overload fputs_exn with fputs1_exn
fun fread
{sz:pos} {n_buf:int}
{n,nsz:nat | nsz <= n_buf} {m:fm} (
pf_mod: file_mode_lte (m, r)
, pf_mul: MUL (n, sz, nsz)
| buf: &bytes (n_buf)
, sz: size_t sz, n: size_t n
, f: &FILE m
) :<> sizeLte n = "atslib_fread"
fun fread_byte
{n_buf:int} {n:nat | n <= n_buf} {m:fm} (
pf_mod: file_mode_lte (m, r) | buf: &bytes (n_buf), n: size_t n, f: &FILE m
) :<> sizeLte n = "atslib_fread_byte"
fun fread_byte_exn
{n_buf:int} {n:nat | n <= n_buf} {m:fm} (
pf_mod: file_mode_lte (m, r) | buf: &bytes (n_buf), n: size_t n, f: &FILE m
) :<!exn> void = "atslib_fread_byte_exn"
symintr freopen_err
fun freopen0_err {m_new:fm}
(path: string, m_new: file_mode m_new, f: FILEref):<!ref> void
= "atslib_freopen_err"
overload freopen_err with freopen0_err
fun freopen1_err {m_old,m_new:fm} {l_file:addr}
(pf: FILE m_old @ l_file | s: string, m: file_mode m_new, p: ptr l_file)
:<!ref> [l:addr | l == null || l == l_file] (FILEopt_v (m_new, l) | ptr l)
= "atslib_freopen_err"
overload freopen_err with freopen1_err
symintr freopen_exn
fun freopen0_exn {m_new:fm}
(path: string, m_new: file_mode m_new, f: FILEref):<!exnref> void
= "atslib_freopen_exn"
overload freopen_exn with freopen0_exn
fun freopen1_exn {m_old,m_new:fm} {l_file:addr}
(pf: FILE m_old @ l_file | path: string, m: file_mode m_new, p: ptr l_file)
:<!exnref> (FILE m_new @ l_file | void)
= "atslib_freopen_exn"
overload freopen_exn with freopen1_exn
fun freopen_stdin {m:fm}
(s: string):<!exnref> void = "atslib_freopen_stdin"
fun freopen_stdout {m:fm}
(s: string):<!exnref> void = "atslib_freopen_stdout"
fun freopen_stderr {m:fm}
(s: string):<!exnref> void = "atslib_freopen_stderr"
symintr fseek_err
fun fseek0_err
(f: FILEref, offset: lint, whence: whence_t):<> int = "atslib_fseek_err"
overload fseek_err with fseek0_err
fun fseek1_err {m:fm}
(f: &FILE m, offset: lint, whence: whence_t):<> int = "atslib_fseek_err"
overload fseek_err with fseek1_err
symintr fseek_exn
fun fseek0_exn
(f: FILEref, offset: lint, whence: whence_t):<!exn> void = "atslib_fseek_exn"
overload fseek_exn with fseek0_exn
fun fseek1_exn {m:fm}
(f: &FILE m, offset: lint, whence: whence_t):<!exn> void = "atslib_fseek_exn"
overload fseek_exn with fseek1_exn
fun fsetpos {m:fm} (f: &FILE m, pos: &fpos_t): int = "atslib_fsetpos"
symintr ftell_err
fun ftell0_err (f: FILEref):<> lint = "atslib_ftell_err"
overload ftell_err with ftell0_err
fun ftell1_err {m:fm} (f: &FILE m):<> lint = "atslib_ftell_err"
overload ftell_err with ftell1_err
symintr ftell_exn
fun ftell0_exn (f: FILEref):<!exn> lint = "atslib_ftell_exn"
overload ftell_exn with ftell0_exn
fun ftell1_exn {m:fm} (f: &FILE m):<!exn> lint = "atslib_ftell_exn"
overload ftell_exn with ftell1_exn
fun fwrite {sz:pos} {bsz:int} {n,nsz:nat | nsz <= bsz} {m:fm} (
pf_mod: file_mode_lte (m, w), pf_mul: MUL (n, sz, nsz)
| buf: &bytes (bsz), sz: size_t sz, n: size_t n, fil: &FILE m
) :<> natLte n
= "atslib_fwrite"
fun fwrite_byte {bsz:int} {n:nat | n <= bsz} {m:fm} (
pf_mod: file_mode_lte (m, w) | buf: &bytes (bsz), n: size_t n, fil: &FILE m
) :<> sizeLte n
= "atslib_fwrite_byte"
fun fwrite_byte_exn
{bsz:int} {n:nat | n <= bsz} {m:fm} (
pf_mod: file_mode_lte (m, w) | buf: &bytes (bsz), n: size_t n, fil: &FILE m
) :<!exn> void
= "atslib_fwrite_byte_exn"
fun perror (msg: string):<> void = "atslib_perror"
macdef getc = fgetc_err
macdef putc = fputc_err
fun getchar ():<> int = "atslib_getchar"
fun getchar1 ():<> [i:int | i <= UCHAR_MAX] int i
= "atslib_getchar"
fun putchar (c: char):<> int = "atslib_putchar"
fun putchar1 (c: char):<> [i:int | i <= UCHAR_MAX] int i
= "atslib_putchar"
fun puts_err (s: string):<> int = "atslib_puts_err"
fun puts_exn (s: string):<!exn> void = "atslib_puts_exn"
fun remove_err (s: string):<!ref> int = "atslib_remove_err"
fun remove_exn (s: string):<!exnref> void = "atslib_remove_exn"
fun rename_err (oldpath: string, newpath: string):<!ref> int
= "atslib_rename_err"
fun rename_exn (oldpath: string, newpath: string):<!exnref> void
= "atslib_rename_exn"
symintr rewind
fun rewind0 {m:fm} (fil: FILEref):<> void = "atslib_rewind"
overload rewind with rewind0
fun rewind1 {m:fm} (fil: &FILE m):<> void = "atslib_rewind"
overload rewind with rewind1
fun tmpfile_err
() :<!ref> [l:addr] (FILEopt_v (rw, l) | ptr l) = "atslib_tmpfile_err"
fun tmpfile_exn
() :<!exnref> [l:addr] (FILE_v (rw, l) | ptr l) = "atslib_tmpfile_exn"
fun tmpfile_ref_exn ():<!exnref> FILEref = "atslib_tmpfile_exn"
symintr ungetc_err
fun ungetc0_err
(c: char, f: FILEref):<> int = "atslib_ungetc_err"
overload ungetc_err with ungetc0_err
fun ungetc1_err {m:fm}
(c: char, f: &FILE m):<> [i:int | i <= UCHAR_MAX] int i
= "atslib_ungetc_err"
overload ungetc_err with ungetc1_err
symintr ungetc_exn
fun ungetc0_exn (c: char, f: FILEref):<!exn> void
= "atslib_ungetc_exn"
overload ungetc_exn with ungetc0_exn
fun ungetc1_exn {m:fm} (c: char, f: &FILE m):<!exn> void
= "atslib_ungetc_exn"
overload ungetc_exn with ungetc1_exn
sta 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")
symintr setbuf_null
fun setbuf0_null (f: FILEref): void = "atslib_setbuf_null"
overload setbuf_null with setbuf0_null
fun setbuf1_null {m:fm} (f: &FILE m): void = "atslib_setbuf_null"
overload setbuf_null with setbuf1_null
symintr setbuffer
fun setbuffer0 {n1,n2:nat | n2 <= n1} {l:addr}
(pf_buf: !b0ytes n1 @ l | f: FILEref, p_buf: ptr l, n2: size_t n2): void
= "#atslib_setbuffer"
overload setbuffer with setbuffer0
fun setbuffer1 {m:fm} {n1,n2:nat | n2 <= n1} {l:addr}
(pf_buf: !b0ytes n1 @ l | f: &FILE m, p_buf: ptr l, n2: size_t n2): void
= "#atslib_setbuffer"
overload setbuffer with setbuffer1
symintr setlinebuf
fun setlinebuf0 (f: FILEref): void = "#atslib_setlinebuf"
overload setlinebuf with setlinebuf0
fun setlinebuf1 {m:fm} (f: &FILE m): void = "#atslib_setlinebuf"
overload setlinebuf with setlinebuf1
symintr setvbuf_null
fun setvbuf0_null
(f: FILEref, mode: bufmode_t): int = "atslib_setvbuf_null"
overload setvbuf_null with setvbuf0_null
fun setvbuf1_null {m:fm}
(f: &FILE m, mode: bufmode_t): int = "atslib_setvbuf_null"
overload setvbuf_null with setvbuf1_null
symintr setvbuf
fun setvbuf0 {n1,n2:nat | n2 <= n1} {l:addr}
(pf_buf: !b0ytes(n1) @ l | fil: FILEref, mode: bufmode_t, n2: size_t n2): int
= "#ats_setvbuf"
overload setvbuf with setvbuf0
fun setvbuf1 {m:fm} {n1,n2:nat | n2 <= n1} {l:addr}
(pf_buf: !b0ytes(n1) @ l | fil: &FILE m, mode: bufmode_t, n2: size_t n2): int
= "#ats_setvbuf"
overload setvbuf with setvbuf1