├── lib └── .keep ├── .gitignore ├── sys └── Linux │ ├── x86_64 │ ├── prototypes.h.in │ ├── syscalls.in │ ├── ctypes.h.in │ └── syscall.s │ └── generic │ ├── prototypes.h.in │ ├── ctypes.h.in │ └── types.h.in ├── AUTHORS ├── inc └── tertium │ ├── std.h │ └── cpu.h.awk ├── src ├── tai │ ├── private.h │ ├── u64.c │ ├── approx.c │ ├── less.c │ ├── pack.c │ ├── add.c │ ├── sub.c │ ├── unpack.c │ ├── fromtime.c │ ├── now.c │ ├── leapadd.c │ └── leapsub.c ├── std │ ├── argv0.c │ ├── errno.c │ ├── private.h │ ├── argmain.c │ ├── free.c │ ├── sysconf.c │ ├── alloc.c │ ├── realloc.c │ ├── ptrlist.c │ ├── calloc.c │ ├── setalloc.c │ ├── atexit.c │ ├── strtovl.c │ ├── werrstr.c │ ├── noopt.c │ ├── getenv.c │ ├── bsearch.c │ ├── vptrlist.c │ ├── nbsearch.c │ ├── exit.c │ ├── errstr.c │ └── putfile.c ├── arr │ ├── bytes.c │ ├── data.c │ ├── total.c │ ├── avail.c │ ├── len.c │ ├── init.c │ ├── tofrom.c │ ├── fmt.c │ ├── cat.c │ ├── ready.c │ ├── trunc.c │ ├── vfmt.c │ ├── get.c │ └── idxcat.c ├── nix │ ├── fork.c │ ├── umask.c │ ├── chdir.c │ ├── rmdir.c │ ├── unlink.c │ ├── pipe.c │ ├── getcwd.c │ ├── uname.c │ ├── lstat.c │ ├── mkdir.c │ ├── mktemp.c │ ├── rename.c │ ├── stat.c │ ├── fdopen2.c │ ├── fstat.c │ ├── pipe2.c │ ├── fdopen3.c │ ├── link.c │ ├── mktemp3.c │ ├── seek.c │ ├── symlink.c │ ├── getumask.c │ ├── fdclose.c │ ├── mmap.c │ ├── munmap.c │ ├── gettime.c │ ├── monotonetime.c │ ├── fdchdir.c │ ├── read.c │ ├── chmod.c │ ├── fdwrite.c │ ├── mktemp4.c │ ├── fdmove.c │ ├── fdchmod.c │ ├── mktemp5.c │ ├── fdfmt.c │ ├── chown.c │ ├── fdset.c │ ├── lchown.c │ ├── fdunset.c │ ├── deepsleep.c │ ├── fdchown.c │ ├── waitpid.c │ ├── fdcopy.c │ ├── readlink.c │ ├── allrw.c │ ├── rmpath.c │ ├── syscall.c │ ├── fdvfmt.c │ ├── fdputfile.c │ ├── mklntemp.c │ └── iopause.c ├── cdb │ ├── datalen.c │ ├── datapos.c │ ├── findstart.c │ ├── find.c │ ├── free.c │ ├── mkaddbegin.c │ ├── mkstart.c │ ├── read.c │ ├── init.c │ ├── mkadd.c │ └── mkaddend.c ├── hsh │ ├── octets.c │ ├── str.c │ ├── rol32.c │ ├── rol64.c │ ├── ror32.c │ ├── ror64.c │ ├── initk.c │ ├── update.c │ └── putfile.c ├── ioq │ ├── fileno.c │ ├── peek.c │ ├── seek.c │ ├── getln.c │ ├── put.c │ ├── stdin.c │ ├── stderr.c │ ├── stdout.c │ ├── init.c │ ├── fmt.c │ ├── flush.c │ ├── feed.c │ ├── vfmt.c │ ├── putfile.c │ ├── get.c │ ├── nput.c │ ├── tofrom.c │ └── getdelim.c ├── rand │ ├── setseed.c │ ├── genseed.c │ ├── u32.c │ ├── name.c │ ├── u32inc.c │ ├── nameinc.c │ └── datainc.c ├── taia │ ├── tai.c │ ├── approx.c │ ├── frac.c │ ├── u64.c │ ├── now.c │ ├── pack.c │ ├── fromtime.c │ ├── unpack.c │ ├── less.c │ ├── half.c │ ├── sub.c │ └── add.c ├── utf8 │ ├── utflen.c │ ├── chartorune.c │ ├── mtab.c │ ├── fullrune.c │ ├── isxdigit.c │ ├── isalnum.c │ ├── isgraph.c │ ├── ispunct.c │ ├── runenlen.c │ ├── checkrune.c │ ├── utfnlen.c │ ├── utfrune.c │ ├── isblank.c │ ├── private.h │ ├── utfrrune.c │ ├── isprint.c │ ├── runelen.c │ ├── runecmp.c │ ├── runetochar.c │ ├── istitle.c │ └── isspace.c ├── cal │ ├── datenorm.c │ ├── timetai.c │ ├── timeutc.c │ └── datemjd.c ├── dyn │ ├── free.c │ ├── tofrom.c │ ├── shrink.c │ ├── fmt.c │ ├── alloc.c │ ├── cat.c │ ├── vfmt.c │ ├── idxcat.c │ └── ready.c ├── exc │ ├── run.c │ ├── split.c │ ├── wait.c │ ├── setenv.c │ └── vsplit.c ├── str │ ├── trim.c │ ├── cpy.c │ ├── len.c │ ├── fmtcnt.c │ ├── fmt.c │ ├── chr.c │ ├── casechr.c │ ├── dup.c │ ├── rchr.c │ ├── caserchr.c │ ├── cmp.c │ ├── cspn.c │ ├── ltrim.c │ ├── spn.c │ ├── rtrim.c │ ├── str.c │ ├── casecmp.c │ ├── casestr.c │ ├── vfmtcnt.c │ └── vfmt.c ├── adt │ ├── lfree.c │ ├── lpop.c │ ├── ltpop.c │ ├── lpush.c │ ├── kvget.c │ ├── lswap.c │ ├── ltpush.c │ ├── lrot.c │ ├── kv.h │ ├── lnew.c │ ├── kvtraverse.c │ └── kvfree.c ├── uint │ ├── 16pack.c │ ├── 16bigpack.c │ ├── 16unpack.c │ ├── 16bigunpack.c │ ├── 32pack.c │ ├── 32bigpack.c │ ├── 32unpack.c │ ├── 32bigunpack.c │ ├── 64pack.c │ ├── 64bigpack.c │ ├── 64unpack.c │ └── 64bigunpack.c ├── dir │ ├── private.h │ ├── set.c │ ├── close.c │ ├── list.c │ └── children.c ├── err │ ├── vdie.c │ ├── vdiex.c │ ├── die.c │ ├── warn.c │ ├── diex.c │ ├── warnx.c │ ├── vwarnx.c │ └── vwarn.c ├── fmt │ ├── put.c │ ├── init.c │ ├── print.c │ ├── private.h │ ├── vprint.c │ └── install.c ├── mem │ ├── chr.c │ ├── rchr.c │ ├── equal.c │ ├── cmp.c │ ├── cpy.c │ ├── mem.c │ ├── set.c │ └── ccpy.c └── gen │ ├── basename.c │ └── dirname.c └── man ├── c_tai_now.3 ├── c_taia_now.3 ├── c_tai_u64.3 ├── c_tai_fromtime.3 ├── c_ioq_flush.3 ├── c_taia_fromtime.3 ├── c_taia_u64.3 ├── c_ioq_seek.3 ├── c_hsh_initk.3 ├── c_rand_genseed.3 ├── c_tai_unpack.3 ├── c_taia_half.3 ├── c_ioq_peek.3 ├── c_rand_setseed.3 ├── c_tai_pack.3 ├── c_taia_unpack.3 ├── c_std_errstr.3 ├── c_taia_pack.3 ├── c_tai_add.3 ├── c_std_sort.3 ├── c_ioq_fileno.3 ├── c_tai_sub.3 ├── c_taia_add.3 ├── c_std_free.3 ├── c_dir_close.3 ├── c_str_len.3 ├── c_taia_sub.3 ├── c_hsh_octets.3 ├── c_nix_deepsleep.3 ├── c_adt_lfree.3 ├── c_fmt_put.3 ├── c_tai_approx.3 ├── c_utf8_checkrune.3 ├── c_rand_u32.3 ├── c_tai_less.3 ├── c_hsh_str.3 ├── c_taia_less.3 ├── c_adt_kvfree.3 ├── c_rand_data.3 ├── c_std_getenv.3 ├── c_utf8_utflen.3 ├── c_fmt_nput.3 ├── c_ioq_init.3 ├── c_hsh_rol32.3 ├── c_hsh_rol64.3 ├── c_hsh_ror32.3 ├── c_hsh_ror64.3 ├── c_ioq_feed.3 ├── c_utf8_utfrune.3 ├── c_taia_approx.3 ├── c_utf8_utfrrune.3 ├── c_utf8_runelen.3 ├── c_arr_init.3 ├── c_dir_list.3 ├── c_utf8_runetochar.3 ├── c_adt_kvdel.3 ├── c_fmt_print.3 ├── c_utf8_fullrune.3 ├── c_utf8_utfnlen.3 ├── c_cal_timetai.3 ├── c_fmt_vprint.3 ├── c_cal_datefrommjd.3 ├── c_dyn_shrink.3 ├── c_fmt_init.3 ├── c_dir_children.3 ├── c_cal_timeutc.3 ├── c_taia_frac.3 ├── c_rand_u32inc.3 ├── c_utf8_runenlen.3 ├── c_cdb_free.3 ├── c_rand_name.3 ├── c_nix_allrw.3 ├── c_cdb_findstart.3 ├── c_dyn_free.3 ├── c_std_atexit.3 ├── c_utf8_islower.3 ├── c_utf8_isupper.3 ├── c_arr_tofrom.3 ├── c_exc_setenv.3 ├── c_utf8_istitle.3 ├── c_utf8_isdigit.3 ├── c_ioq_putfile.3 ├── c_str_rtrim.3 ├── c_arr_data.3 ├── c_ioq_put.3 ├── c_uint_16pack.3 ├── c_uint_32pack.3 ├── c_uint_64pack.3 ├── c_nix_rmpath.3 ├── c_ioq_getln.3 ├── c_mem_set.3 ├── c_str_ltrim.3 ├── c_uint_16bigpack.3 ├── c_uint_32bigpack.3 ├── c_uint_64bigpack.3 ├── c_gen_dirname.3 ├── c_std_strerror.3 ├── c_str_trim.3 ├── c_adt_lpop.3 ├── c_cal_datemjd.3 ├── c_utf8_isspace.3 ├── c_adt_ltpop.3 ├── c_std_exit.3 ├── c_gen_basename.3 ├── c_utf8_isblank.3 ├── c_ioq_nput.3 ├── c_uint_16unpack.3 ├── c_uint_32unpack.3 ├── c_uint_64unpack.3 ├── c_mem_cpy.3 ├── c_uint_16bigunpack.3 ├── c_uint_32bigunpack.3 ├── c_uint_64bigunpack.3 ├── c_arr_bytes.3 ├── c_hsh_putfile.3 ├── c_ioq_get.3 ├── c_ioq_putfd.3 ├── c_nix_mktemp.3 ├── c_utf8_isxdigit.3 ├── c_arr_total.3 ├── c_ioq_getdelim.3 ├── c_mem_chr.3 ├── c_arr_avail.3 ├── c_dyn_tofrom.3 ├── c_std_bsearch.3 ├── c_mem_rchr.3 └── c_dir_set.3 /lib/.keep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | -------------------------------------------------------------------------------- /sys/Linux/x86_64/prototypes.h.in: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /sys/Linux/x86_64/syscalls.in: -------------------------------------------------------------------------------- 1 | # DUMMY FILE 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Eduardo Francisco 2 | -------------------------------------------------------------------------------- /sys/Linux/generic/prototypes.h.in: -------------------------------------------------------------------------------- 1 | long _tertium_syscall(long, ...); 2 | -------------------------------------------------------------------------------- /inc/tertium/std.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | -------------------------------------------------------------------------------- /src/tai/private.h: -------------------------------------------------------------------------------- 1 | u64 *_tertium_tai_leaptab; 2 | int _tertium_tai_leaptabsize; 3 | -------------------------------------------------------------------------------- /src/std/argv0.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char *argv0; 5 | -------------------------------------------------------------------------------- /src/std/errno.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_error errno; 5 | -------------------------------------------------------------------------------- /src/std/private.h: -------------------------------------------------------------------------------- 1 | extern void *pubrealloc(void *, usize, usize); 2 | extern ctype_allocfn _tertium_allocator; 3 | -------------------------------------------------------------------------------- /src/std/argmain.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_arg arg; 5 | ctype_arg *argmain = &arg; 6 | -------------------------------------------------------------------------------- /src/arr/bytes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_arr_bytes(ctype_arr *p) 6 | { 7 | return p->n; 8 | } 9 | -------------------------------------------------------------------------------- /src/arr/data.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_arr_data(ctype_arr *p) 6 | { 7 | return p->p; 8 | } 9 | -------------------------------------------------------------------------------- /src/arr/total.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_arr_total(ctype_arr *p) 6 | { 7 | return p->a; 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/u64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_u64(ctype_tai *t, u64 u) 6 | { 7 | t->x = u; 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/fork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_id 5 | c_nix_fork(void) 6 | { 7 | return c_sys_fork(); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/umask.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint 5 | c_nix_umask(uint m) 6 | { 7 | return c_sys_umask(m); 8 | } 9 | -------------------------------------------------------------------------------- /src/arr/avail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_arr_avail(ctype_arr *p) 6 | { 7 | return (p->a - p->n); 8 | } 9 | -------------------------------------------------------------------------------- /src/cdb/datalen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_cdb_datalen(ctype_cdb *p) 6 | { 7 | return p->dlen; 8 | } 9 | -------------------------------------------------------------------------------- /src/cdb/datapos.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_cdb_datapos(ctype_cdb *p) 6 | { 7 | return p->dpos; 8 | } 9 | -------------------------------------------------------------------------------- /src/cdb/findstart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_cdb_findstart(ctype_cdb *p) 6 | { 7 | p->loop = 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/hsh/octets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_hsh_octets(ctype_hst *p) 6 | { 7 | return p->len >> 3; 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/fileno.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_fd 5 | c_ioq_fileno(ctype_ioq *p) 6 | { 7 | return p->fd; 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/chdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_chdir(char *s) 6 | { 7 | return c_sys_chdir(s); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/rmdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_rmdir(char *s) 6 | { 7 | return c_sys_rmdir(s); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/unlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_unlink(char *s) 6 | { 7 | return c_sys_unlink(s); 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/approx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double 5 | c_tai_approx(ctype_tai *t) 6 | { 7 | return (double)t->x; 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/peek.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_ioq_peek(ctype_ioq *p) 6 | { 7 | return (p->arr.p + p->arr.a); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/pipe.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_pipe(ctype_fd *fds) 6 | { 7 | return c_sys_pipe(fds); 8 | } 9 | -------------------------------------------------------------------------------- /src/rand/setseed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_rand_setseed(ctype_rst *p, u64 seed) 6 | { 7 | p->state = seed; 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/less.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_tai_less(ctype_tai *t, ctype_tai *u) 6 | { 7 | return t->x < u->x; 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_pack(char *s, ctype_tai *t) 6 | { 7 | c_uint_64bigpack(s, t->x); 8 | } 9 | -------------------------------------------------------------------------------- /src/taia/tai.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_tai(ctype_taia *taia, ctype_tai *t) 6 | { 7 | *t = taia->sec; 8 | } 9 | -------------------------------------------------------------------------------- /src/utf8/utflen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_utf8_utflen(char *s) 6 | { 7 | return c_utf8_utfnlen(s, -1); 8 | } 9 | -------------------------------------------------------------------------------- /src/arr/len.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_arr_len(ctype_arr *p, usize n) 6 | { 7 | return (n ? (p->n / n) : 0); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/getcwd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_nix_getcwd(char *s, usize n) 6 | { 7 | return c_sys_getcwd(s, n); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/uname.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_uname(ctype_utsname *p) 6 | { 7 | return c_sys_uname(p); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/lstat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_lstat(ctype_stat *p, char *s) 6 | { 7 | return c_sys_lstat(s, p); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/mkdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_mkdir(char *s, uint mode) 6 | { 7 | return c_sys_mkdir(s, mode); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/mktemp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_fd 5 | c_nix_mktemp(char *s, usize n) 6 | { 7 | return c_nix_mktemp3(s, n, 0); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/rename.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_rename(char *d, char *s) 6 | { 7 | return c_sys_rename(s, d); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/stat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_stat(ctype_stat *p, char *s) 6 | { 7 | return c_sys_stat(s, p); 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_add(ctype_tai *t, ctype_tai *u, ctype_tai *v) 6 | { 7 | t->x = u->x + v->x; 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/sub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_sub(ctype_tai *t, ctype_tai *u, ctype_tai *v) 6 | { 7 | t->x = u->x - v->x; 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/unpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_unpack(ctype_tai *t, char *s) 6 | { 7 | t->x = c_uint_64bigunpack(s); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/fdopen2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_fd 5 | c_nix_fdopen2(char *s, uint opts) 6 | { 7 | return c_sys_open(s, opts, 0); 8 | } 9 | -------------------------------------------------------------------------------- /src/cal/datenorm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_cal_datenorm(ctype_caldate *p) 6 | { 7 | c_cal_datefrommjd(p, c_cal_datemjd(p)); 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/seek.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_ioq_seek(ctype_ioq *p, usize n) 6 | { 7 | p->arr.a += n; 8 | p->arr.n -= n; 9 | } 10 | -------------------------------------------------------------------------------- /src/nix/fstat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdstat(ctype_stat *p, ctype_fd fd) 6 | { 7 | return c_sys_fstat(fd, p); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/pipe2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_pipe2(ctype_fd *fds, uint opts) 6 | { 7 | return c_sys_pipe2(fds, opts); 8 | } 9 | -------------------------------------------------------------------------------- /src/taia/approx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double 5 | c_taia_approx(ctype_taia *t) 6 | { 7 | return c_tai_approx(&t->sec) + c_taia_frac(t); 8 | } 9 | -------------------------------------------------------------------------------- /src/dyn/free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_dyn_free(ctype_arr *p) 6 | { 7 | p->a = 0; 8 | p->n = 0; 9 | c_std_free(p->p); 10 | } 11 | -------------------------------------------------------------------------------- /src/exc/run.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_exc_run(char *path, char **argv) 6 | { 7 | return c_exc_runenv(path, argv, environ); 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/getln.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_ioq_getln(ctype_arr *b, ctype_ioq *p) 6 | { 7 | return c_ioq_getdelim(b, p, "\n"); 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/put.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_ioq_put(ctype_ioq *p, char *s) 6 | { 7 | return c_ioq_nput(p, s, c_str_len(s, -1)); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/fdopen3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_fd 5 | c_nix_fdopen3(char *s, uint opts, uint mode) 6 | { 7 | return c_sys_open(s, opts, mode); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/link.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_link(char *newpath, char *oldpath) 6 | { 7 | return c_sys_link(oldpath, newpath); 8 | } 9 | -------------------------------------------------------------------------------- /src/taia/frac.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | double 5 | c_taia_frac(ctype_taia *t) 6 | { 7 | return (t->atto * 0.000000001 + t->nano) * 0.000000001; 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/mktemp3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_fd 5 | c_nix_mktemp3(char *s, usize n, uint opts) 6 | { 7 | return c_nix_mktemp4(s, n, opts, 0); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/seek.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_seek(ctype_fd fd, ctype_fssize off, int w) 6 | { 7 | return c_sys_lseek(fd, off, w); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/symlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_symlink(char *path, char *target) 6 | { 7 | return c_sys_symlink(target, path); 8 | } 9 | -------------------------------------------------------------------------------- /src/ioq/stdin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar buf[C_IOQ_BSIZ]; 5 | static ctype_ioq ioq = c_ioq_INIT(0, buf, &c_nix_fdread); 6 | ctype_ioq *ioq0 = &ioq; 7 | -------------------------------------------------------------------------------- /src/rand/genseed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_rand_genseed(ctype_rst *p) 6 | { 7 | c_rand_data((void *)(uintptr)&p->state, sizeof(p->state)); 8 | } 9 | -------------------------------------------------------------------------------- /src/str/trim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_trim(char *str, usize n, char *t) 6 | { 7 | return c_str_ltrim(c_str_rtrim(str, n, t), n, t); 8 | } 9 | -------------------------------------------------------------------------------- /src/tai/fromtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_fromtime(ctype_tai *t, ctype_time *tm) 6 | { 7 | t->x = 4611686018427387914ULL + (u64)tm->sec; 8 | } 9 | -------------------------------------------------------------------------------- /src/taia/u64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_u64(ctype_taia *t, u64 u) 6 | { 7 | t->sec.x = u; 8 | t->nano = 0; 9 | t->atto = 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/utf8/chartorune.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_utf8_chartorune(ctype_rune *p, char *s) 6 | { 7 | return c_utf8_charntorune(p, s, C_UTF8_MAX); 8 | } 9 | -------------------------------------------------------------------------------- /src/adt/lfree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_adt_lfree(ctype_node *np, void (*freeobj)(void *)) 6 | { 7 | freeobj(np->p); 8 | c_std_free(np); 9 | } 10 | -------------------------------------------------------------------------------- /src/ioq/stderr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar buf[C_IOQ_ERRSIZ]; 5 | static ctype_ioq ioq = c_ioq_INIT(2, buf, &c_nix_fdwrite); 6 | ctype_ioq *ioq2 = &ioq; 7 | -------------------------------------------------------------------------------- /src/ioq/stdout.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar buf[C_IOQ_BSIZ]; 5 | static ctype_ioq ioq = c_ioq_INIT(1, buf, &c_nix_fdwrite); 6 | ctype_ioq *ioq1 = &ioq; 7 | -------------------------------------------------------------------------------- /src/str/cpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_cpy(char *dest, usize n, char *src) 6 | { 7 | return c_mem_cpy(dest, src, c_str_len(src, n - 1) + 1); 8 | } 9 | -------------------------------------------------------------------------------- /src/uint/16pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_16pack(char *s, u16 u) 6 | { 7 | s[0] = u & 255; 8 | s[1] = u >> 8; 9 | return s; 10 | } 11 | -------------------------------------------------------------------------------- /src/arr/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_arr_init(ctype_arr *p, char *s, usize n) 6 | { 7 | p->a = n; 8 | p->n = 0; 9 | p->p = (uchar *)s; 10 | } 11 | -------------------------------------------------------------------------------- /src/nix/getumask.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | uint 5 | c_nix_getumask(void) 6 | { 7 | uint mode; 8 | c_nix_umask(mode = c_nix_umask(0)); 9 | return mode; 10 | } 11 | -------------------------------------------------------------------------------- /src/std/free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | void 7 | c_std_free_(void *p) 8 | { 9 | _tertium_allocator(p, 0, sizeof(uchar)); 10 | } 11 | -------------------------------------------------------------------------------- /src/std/sysconf.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* XXX */ 5 | long 6 | c_std_sysconf(int v) 7 | { 8 | (void)v; 9 | errno = C_ERR_EINVAL; 10 | return -1; 11 | } 12 | -------------------------------------------------------------------------------- /src/tai/now.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_tai_now(ctype_tai *t) 6 | { 7 | ctype_time tm; 8 | c_nix_gettime(&tm); 9 | c_tai_fromtime(t, &tm); 10 | } 11 | -------------------------------------------------------------------------------- /src/uint/16bigpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_16bigpack(char *s, u16 u) 6 | { 7 | s[1] = u & 255; 8 | s[0] = u >> 8; 9 | return s; 10 | } 11 | -------------------------------------------------------------------------------- /src/utf8/mtab.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar tab[] = { 5 | 0x00, 0x3F, 0x1F, 6 | 0x0F, 0x07, 0x03, 7 | }; 8 | 9 | uchar *_tertium_utf8_mtab = tab; 10 | -------------------------------------------------------------------------------- /src/taia/now.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_now(ctype_taia *t) 6 | { 7 | ctype_time tm; 8 | c_nix_gettime(&tm); 9 | c_taia_fromtime(t, &tm); 10 | } 11 | -------------------------------------------------------------------------------- /src/utf8/fullrune.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_utf8_fullrune(char *s, usize n) 6 | { 7 | ctype_rune r; 8 | return c_utf8_charntorune(&r, s, n) > 0; 9 | } 10 | -------------------------------------------------------------------------------- /src/dir/private.h: -------------------------------------------------------------------------------- 1 | #define BFAIL ((void *)-1) 2 | 3 | int _tertium_dir_info(ctype_dir *, ctype_dent *); 4 | ctype_node *_tertium_dir_newfile(char *, char *, uint); 5 | ctype_node *_tertium_dir_builddir(ctype_dir *); 6 | -------------------------------------------------------------------------------- /src/err/vdie.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_err_vdie(ctype_status eval, char *fmt, va_list args) 6 | { 7 | c_err_vwarn(fmt, args); 8 | c_std_exit(eval); 9 | } 10 | -------------------------------------------------------------------------------- /src/err/vdiex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_err_vdiex(ctype_status eval, char *fmt, va_list args) 6 | { 7 | c_err_vwarnx(fmt, args); 8 | c_std_exit(eval); 9 | } 10 | -------------------------------------------------------------------------------- /src/std/alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | void * 7 | c_std_alloc(usize m, usize n) 8 | { 9 | return _tertium_allocator(nil, m, n); 10 | } 11 | -------------------------------------------------------------------------------- /src/cdb/find.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_find(ctype_cdb *p, char *k, usize n) 6 | { 7 | c_cdb_findstart(p); 8 | return c_cdb_findnext(p, k, n); 9 | } 10 | -------------------------------------------------------------------------------- /src/dir/set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_dir_set(ctype_dir *p, ctype_dent *ep, int instr) 6 | { 7 | (void)p; 8 | ep->instr = instr; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/nix/fdclose.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_nix_fdclose(ctype_fd fd) 6 | { 7 | int sverr; 8 | 9 | sverr = errno; 10 | c_sys_close(fd); 11 | errno = sverr; 12 | } 13 | -------------------------------------------------------------------------------- /src/utf8/isxdigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* , , Nd */ 5 | int 6 | c_utf8_isxdigit(ctype_rune r) 7 | { 8 | return c_utf8_isdigit(r) || ((r | 32) - 'a' < 6); 9 | } 10 | -------------------------------------------------------------------------------- /src/arr/tofrom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_arr_tofrom(ctype_arr *dest, ctype_arr *s) 6 | { 7 | return c_arr_cat(dest, c_arr_data(s), c_arr_bytes(s), sizeof(uchar)); 8 | } 9 | -------------------------------------------------------------------------------- /src/dyn/tofrom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_dyn_tofrom(ctype_arr *dest, ctype_arr *s) 6 | { 7 | return c_dyn_cat(dest, c_arr_data(s), c_arr_bytes(s), sizeof(uchar)); 8 | } 9 | -------------------------------------------------------------------------------- /src/std/realloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | void * 7 | c_std_realloc(void *p, usize m, usize n) 8 | { 9 | return _tertium_allocator(p, m, n); 10 | } 11 | -------------------------------------------------------------------------------- /src/utf8/isalnum.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* Ll, Lm, Lo, Lt, Lu, Nd */ 5 | int 6 | c_utf8_isalnum(ctype_rune r) 7 | { 8 | return c_utf8_isalpha(r) || c_utf8_isdigit(r); 9 | } 10 | -------------------------------------------------------------------------------- /src/utf8/isgraph.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* !(Cc, Cf, Co, Zl, Zp, Zs) */ 5 | int 6 | c_utf8_isgraph(ctype_rune r) 7 | { 8 | return !c_utf8_isspace(r) && c_utf8_isprint(r); 9 | } 10 | -------------------------------------------------------------------------------- /src/nix/mmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_nix_mmap(void *p, usize n, int prot, uint opts, ctype_fd fd, ctype_fssize off) 6 | { 7 | return c_sys_mmap(p, n, prot, opts, fd, off); 8 | } 9 | -------------------------------------------------------------------------------- /src/nix/munmap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_nix_munmap(void *p, usize n) 6 | { 7 | int sverr; 8 | 9 | sverr = errno; 10 | c_sys_munmap(p, n); 11 | errno = sverr; 12 | } 13 | -------------------------------------------------------------------------------- /src/uint/16unpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u16 5 | c_uint_16unpack(char *s) 6 | { 7 | u16 r; 8 | 9 | r = (uchar)s[1]; 10 | r <<= 8; 11 | r += (uchar)s[0]; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /src/str/len.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_str_len(char *s, usize n) 6 | { 7 | char *p; 8 | 9 | if (!(p = c_mem_chr(s, n, 0))) 10 | return n; 11 | 12 | return p - s; 13 | } 14 | -------------------------------------------------------------------------------- /src/uint/16bigunpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u16 5 | c_uint_16bigunpack(char *s) 6 | { 7 | u16 r; 8 | 9 | r = (uchar)s[0]; 10 | r <<= 8; 11 | r += (uchar)s[1]; 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /src/cdb/free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_cdb_free(ctype_cdb *p) 6 | { 7 | if (p->map) 8 | c_nix_munmap(p->map, p->size); 9 | c_mem_set(p, sizeof(*p), 0); 10 | p->fd = -1; 11 | } 12 | -------------------------------------------------------------------------------- /src/err/die.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_err_die(ctype_status eval, char *fmt, ...) 6 | { 7 | va_list ap; 8 | va_start(ap, fmt); 9 | c_err_vdie(eval, fmt, ap); 10 | va_end(ap); 11 | } 12 | -------------------------------------------------------------------------------- /src/err/warn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_err_warn(char *fmt, ...) 6 | { 7 | va_list ap; 8 | 9 | va_start(ap, fmt); 10 | c_err_vwarn(fmt, ap); 11 | va_end(ap); 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /src/nix/gettime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_nix_gettime(ctype_time *t) 6 | { 7 | int sverr; 8 | sverr = errno; 9 | c_sys_clockgettime(C_NIX_CLOCKREAL, t); 10 | errno = sverr; 11 | } 12 | -------------------------------------------------------------------------------- /src/err/diex.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_err_diex(ctype_status eval, char *fmt, ...) 6 | { 7 | va_list ap; 8 | va_start(ap, fmt); 9 | c_err_vdiex(eval, fmt, ap); 10 | va_end(ap); 11 | } 12 | -------------------------------------------------------------------------------- /src/err/warnx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_err_warnx(char *fmt, ...) 6 | { 7 | va_list ap; 8 | 9 | va_start(ap, fmt); 10 | c_err_vwarnx(fmt, ap); 11 | va_end(ap); 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /src/ioq/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_ioq_init(ctype_ioq *p, ctype_fd fd, char *buf, usize n, ctype_iofn f) 6 | { 7 | c_arr_init(&p->arr, buf, n); 8 | p->op = f; 9 | p->fd = fd; 10 | } 11 | -------------------------------------------------------------------------------- /src/dir/close.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_dir_close(ctype_dir *p) 6 | { 7 | while (p->cur) c_adt_lfree(c_adt_lpop(&p->cur), c_std_free_); 8 | c_dyn_free(&p->hist); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/fmt/put.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_fmt_put(ctype_fmt *p, char *s) 6 | { 7 | usize len; 8 | len = 0; 9 | if (s) len = c_str_len(s, -1); 10 | return c_fmt_nput(p, s, len); 11 | } 12 | -------------------------------------------------------------------------------- /src/hsh/str.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_hsh_str(char *buf, ctype_hmd *p, char *data, usize n) 6 | { 7 | ctype_hst h; 8 | p->init(&h); 9 | p->update(&h, data, n); 10 | p->end(&h, buf); 11 | } 12 | -------------------------------------------------------------------------------- /src/nix/monotonetime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_nix_monotonetime(ctype_time *t) 6 | { 7 | int sverr; 8 | sverr = errno; 9 | c_sys_clockgettime(C_NIX_CLOCKMONO, t); 10 | errno = sverr; 11 | } 12 | -------------------------------------------------------------------------------- /src/taia/pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_pack(char *s, ctype_taia *t) 6 | { 7 | c_tai_pack(s, &t->sec); 8 | c_uint_32bigpack(s + 8, t->nano); 9 | c_uint_32bigpack(s + 12, t->atto); 10 | } 11 | -------------------------------------------------------------------------------- /src/utf8/ispunct.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* !(Cc, Cf, Co, Ll, Lm, Lo, Lt, Lu, Nd, Zl, Zp, Zs) */ 5 | int 6 | c_utf8_ispunct(ctype_rune r) 7 | { 8 | return c_utf8_isgraph(r) && !c_utf8_isalnum(r); 9 | } 10 | -------------------------------------------------------------------------------- /src/hsh/rol32.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_hsh_rol32(u32 n, int k) 6 | { 7 | uint mask; 8 | mask = C_LIM_CHARBIT * sizeof(n) - 1; 9 | k &= mask; 10 | return ((n << k) | (n >> (-k & mask))); 11 | } 12 | -------------------------------------------------------------------------------- /src/hsh/rol64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u64 5 | c_hsh_rol64(u64 n, int k) 6 | { 7 | uint mask; 8 | mask = C_LIM_CHARBIT * sizeof(n) - 1; 9 | k &= mask; 10 | return ((n << k) | (n >> (-k & mask))); 11 | } 12 | -------------------------------------------------------------------------------- /src/hsh/ror32.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_hsh_ror32(u32 n, int k) 6 | { 7 | uint mask; 8 | mask = C_LIM_CHARBIT * sizeof(n) - 1; 9 | k &= mask; 10 | return ((n >> k) | (n << (-k & mask))); 11 | } 12 | -------------------------------------------------------------------------------- /src/hsh/ror64.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u64 5 | c_hsh_ror64(u64 n, int k) 6 | { 7 | uint mask; 8 | mask = C_LIM_CHARBIT * sizeof(n) - 1; 9 | k &= mask; 10 | return ((n >> k) | (n << (-k & mask))); 11 | } 12 | -------------------------------------------------------------------------------- /src/taia/fromtime.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_fromtime(ctype_taia *t, ctype_time *tm) 6 | { 7 | t->sec.x = 4611686018427387914ULL + (u64)tm->sec; 8 | t->nano = tm->nsec; 9 | t->atto = 0; 10 | } 11 | -------------------------------------------------------------------------------- /src/dyn/shrink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_dyn_shrink(ctype_arr *p, usize n) 6 | { 7 | if (p->a > p->n) { 8 | p->p = c_std_realloc(p->p, p->n + n, sizeof(uchar)); 9 | p->a = p->n + 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/std/ptrlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_std_ptrlist_(char *s, ...) 6 | { 7 | va_list ap; 8 | void *p; 9 | va_start(ap, s); 10 | p = c_std_vptrlist(s, ap); 11 | va_end(ap); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /src/str/fmtcnt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_str_fmtcnt(char *fmt, ...) 6 | { 7 | va_list ap; 8 | usize r; 9 | va_start(ap, fmt); 10 | r = c_str_vfmtcnt(fmt, ap); 11 | va_end(ap); 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /src/utf8/runenlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_utf8_runenlen(ctype_rune *p, usize len) 6 | { 7 | usize n; 8 | 9 | n = 0; 10 | while (len--) 11 | n += c_utf8_runelen(*p++); 12 | 13 | return n; 14 | } 15 | -------------------------------------------------------------------------------- /sys/Linux/generic/ctypes.h.in: -------------------------------------------------------------------------------- 1 | typedef unsigned short ushort; 2 | typedef unsigned char uchar; 3 | typedef unsigned long ulong; 4 | typedef unsigned int uint; 5 | typedef long long vlong; 6 | typedef unsigned long long uvlong; 7 | typedef __builtin_va_list va_list; 8 | -------------------------------------------------------------------------------- /src/exc/split.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_exc_split_(char *prog, ...) 6 | { 7 | va_list ap; 8 | void *p; 9 | va_start(ap, prog); 10 | p = c_exc_vsplit(prog, ap); 11 | va_end(ap); 12 | return p; 13 | } 14 | -------------------------------------------------------------------------------- /src/str/fmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_str_fmt(char **sp, char *fmt, ...) 6 | { 7 | va_list ap; 8 | size r; 9 | va_start(ap, fmt); 10 | r = c_str_vfmt(sp, fmt, ap); 11 | va_end(ap); 12 | return r; 13 | } 14 | -------------------------------------------------------------------------------- /src/taia/unpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_unpack(ctype_taia *t, char *s) 6 | { 7 | c_tai_unpack(&t->sec, s); 8 | t->nano = c_uint_32bigunpack(s + 8); 9 | t->atto = c_uint_32bigunpack(s + 12); 10 | } 11 | -------------------------------------------------------------------------------- /src/arr/fmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_arr_fmt(ctype_arr *p, char *fmt, ...) 6 | { 7 | va_list ap; 8 | size n; 9 | va_start(ap, fmt); 10 | n = c_arr_vfmt(p, fmt, ap); 11 | va_end(ap); 12 | return n; 13 | } 14 | -------------------------------------------------------------------------------- /src/uint/32pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_32pack(char *s, u32 u) 6 | { 7 | s[0] = u & 255; 8 | u >>= 8; 9 | s[1] = u & 255; 10 | u >>= 8; 11 | s[2] = u & 255; 12 | s[3] = u >> 8; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /src/dyn/fmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_dyn_fmt(ctype_arr *p, char *fmt, ...) 6 | { 7 | va_list ap; 8 | size n; 9 | 10 | va_start(ap, fmt); 11 | n = c_dyn_vfmt(p, fmt, ap); 12 | va_end(ap); 13 | return n; 14 | } 15 | -------------------------------------------------------------------------------- /src/ioq/fmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_ioq_fmt(ctype_ioq *p, char *fmt, ...) 6 | { 7 | va_list ap; 8 | size n; 9 | 10 | va_start(ap, fmt); 11 | n = c_ioq_vfmt(p, fmt, ap); 12 | va_end(ap); 13 | return n; 14 | } 15 | -------------------------------------------------------------------------------- /src/mem/chr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_mem_chr(void *v, usize n, int c) 6 | { 7 | uchar *s; 8 | 9 | s = v; 10 | for (; n; --n) { 11 | if (*s == c) 12 | return s; 13 | ++s; 14 | } 15 | return nil; 16 | } 17 | -------------------------------------------------------------------------------- /src/std/calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | void * 7 | c_std_calloc(usize m, usize n) 8 | { 9 | void *p; 10 | if ((p = _tertium_allocator(nil, m, n))) c_mem_set(p, m * n, 0); 11 | return p; 12 | } 13 | -------------------------------------------------------------------------------- /src/std/setalloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | ctype_allocfn _tertium_allocator = pubrealloc; 7 | 8 | void 9 | c_std_setalloc(ctype_allocfn f) 10 | { 11 | _tertium_allocator = f ? f : pubrealloc; 12 | } 13 | -------------------------------------------------------------------------------- /src/nix/fdchdir.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdchdir(ctype_fd fd) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_fchdir(fd); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/uint/32bigpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_32bigpack(char *s, u32 u) 6 | { 7 | s[3] = u & 255; 8 | u >>= 8; 9 | s[2] = u & 255; 10 | u >>= 8; 11 | s[1] = u & 255; 12 | s[0] = u >> 8; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /src/fmt/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_fmt_init(ctype_fmt *p, void *farg, ctype_fmtopfn func) 6 | { 7 | p->func = func; 8 | p->farg = farg; 9 | p->nfmt = 0; 10 | p->flags = 0; 11 | p->width = 0; 12 | p->prec = 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/nix/read.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_nix_fdread(ctype_fd fd, void *p, usize n) 6 | { 7 | size r; 8 | 9 | do { 10 | r = c_sys_read(fd, p, n); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/hsh/initk.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_hsh_initk(ctype_hst *p, void *k, usize n) 6 | { 7 | if (n > sizeof(p->buf)) n = sizeof(p->buf); /* XXX */ 8 | c_mem_cpy(p->buf, k, n); 9 | c_mem_set(p->buf + n, sizeof(p->buf) - n, 0); 10 | } 11 | -------------------------------------------------------------------------------- /src/nix/chmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_chmod(char *s, uint mode) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_chmod(s, mode); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/nix/fdwrite.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_nix_fdwrite(ctype_fd fd, void *p, usize n) 6 | { 7 | size r; 8 | 9 | do { 10 | r = c_sys_write(fd, p, n); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/nix/mktemp4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MODE(x) ((x) & C_NIX_OTMPDIR ? 0700 : 0600) 5 | 6 | ctype_fd 7 | c_nix_mktemp4(char *s, usize n, uint opts, uint fdopts) 8 | { 9 | return c_nix_mktemp5(s, n, opts, fdopts, MODE(opts)); 10 | } 11 | -------------------------------------------------------------------------------- /src/fmt/print.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_fmt_print(ctype_fmt *p, char *fmt, ...) 6 | { 7 | ctype_status r; 8 | va_list ap; 9 | 10 | va_start(ap, fmt); 11 | r = c_fmt_vprint(p, fmt, ap); 12 | va_end(ap); 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/mem/rchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_mem_rchr(void *v, usize n, int c) 6 | { 7 | uchar *s; 8 | 9 | s = (uchar *)v + (n - 1); 10 | for (; n; --n) { 11 | if (*s == c) 12 | return s; 13 | --s; 14 | } 15 | return nil; 16 | } 17 | -------------------------------------------------------------------------------- /src/nix/fdmove.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdmove(ctype_fd to, ctype_fd from) 6 | { 7 | if (to == from) 8 | return 0; 9 | if (c_nix_fdcopy(to, from) < 0) 10 | return -1; 11 | c_nix_fdclose(from); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/str/chr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_chr(char *v, usize n, int c) 6 | { 7 | uchar *s; 8 | 9 | s = (uchar *)v; 10 | for (; n && *s; --n) { 11 | if (*s == c) 12 | return (char *)s; 13 | ++s; 14 | } 15 | return nil; 16 | } 17 | -------------------------------------------------------------------------------- /src/taia/less.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_taia_less(ctype_taia *t, ctype_taia *u) 6 | { 7 | if (t->sec.x != u->sec.x) return t->sec.x < u->sec.x; 8 | if (t->nano != u->nano) return t->nano < u->nano; 9 | return t->atto < u->atto; 10 | } 11 | -------------------------------------------------------------------------------- /src/fmt/private.h: -------------------------------------------------------------------------------- 1 | #define VFMTLEN 20 2 | 3 | struct fmtverb { 4 | ctype_rune c; 5 | ctype_status (*f)(ctype_fmt *); 6 | }; 7 | 8 | extern ctype_arr _tertium_fmt_fmts; 9 | extern struct fmtverb _tertium_fmt_vfmts[]; 10 | extern ctype_status _tertium_fmt_trycat(ctype_fmt *, char *, usize); 11 | -------------------------------------------------------------------------------- /src/mem/equal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_mem_equal(void *v1, usize n, void *v2) 6 | { 7 | uint r; 8 | uchar *s1, *s2; 9 | 10 | r = 0; 11 | s1 = v1; 12 | s2 = v2; 13 | for (; n; --n) 14 | r |= *s1++ ^ *s2++; 15 | 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /src/nix/fdchmod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdchmod(ctype_fd fd, uint mode) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_fchmod(fd, mode); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/nix/mktemp5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ROPTS (C_NIX_OREAD|C_NIX_OEXCL) 5 | 6 | ctype_fd 7 | c_nix_mktemp5(char *s, usize n, uint opts, uint fdopts, uint fdmode) 8 | { 9 | return c_nix_mktemp6(s, n, opts, fdopts, fdmode, c_rand_name); 10 | } 11 | -------------------------------------------------------------------------------- /src/nix/fdfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdfmt(ctype_fd fd, char *fmt, ...) 6 | { 7 | va_list ap; 8 | ctype_status status; 9 | va_start(ap, fmt); 10 | status = c_nix_fdvfmt(fd, fmt, ap); 11 | va_end(ap); 12 | return status; 13 | } 14 | -------------------------------------------------------------------------------- /src/nix/chown.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_chown(char *s, ctype_id uid, ctype_id gid) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_chown(s, uid, gid); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/nix/fdset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdset(ctype_fd fd, uint flags) 6 | { 7 | uint opts; 8 | 9 | if ((opts = c_sys_fcntl(fd, C_NIX_FGETFD)) == (uint)-1) 10 | return -1; 11 | return c_sys_fcntl(fd, C_NIX_FSETFD, opts | flags); 12 | } 13 | -------------------------------------------------------------------------------- /src/nix/lchown.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_lchown(char *s, ctype_id uid, ctype_id gid) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_lchown(s, uid, gid); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/str/casechr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_casechr(char *v, usize n, int c) 6 | { 7 | uchar *s; 8 | 9 | s = (uchar *)v; 10 | for (; n && *s; --n) { 11 | if ((*s | 32) == c) 12 | return (char *)s; 13 | ++s; 14 | } 15 | return nil; 16 | } 17 | -------------------------------------------------------------------------------- /src/uint/32unpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_uint_32unpack(char *s) 6 | { 7 | u32 r; 8 | 9 | r = (uchar)s[3]; 10 | r <<= 8; 11 | r += (uchar)s[2]; 12 | r <<= 8; 13 | r += (uchar)s[1]; 14 | r <<= 8; 15 | r += (uchar)s[0]; 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /src/err/vwarnx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_err_vwarnx(char *fmt, va_list args) 6 | { 7 | c_ioq_fmt(ioq2, "%s: ", c_std_getprogname()); 8 | if (fmt) 9 | c_ioq_vfmt(ioq2, fmt, args); 10 | c_ioq_put(ioq2, "\n"); 11 | c_ioq_flush(ioq2); 12 | return 1; 13 | } 14 | -------------------------------------------------------------------------------- /src/nix/fdunset.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdunset(ctype_fd fd, uint flags) 6 | { 7 | uint opts; 8 | 9 | if ((opts = c_sys_fcntl(fd, C_NIX_FGETFD)) == (uint)-1) 10 | return -1; 11 | return c_sys_fcntl(fd, C_NIX_FSETFD, opts & ~flags); 12 | } 13 | -------------------------------------------------------------------------------- /src/str/dup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_dup(char *s, usize n) 6 | { 7 | char *p; 8 | 9 | n = c_str_len(s, n); 10 | if (!(p = c_std_alloc(n+1, sizeof(uchar)))) 11 | return nil; 12 | 13 | c_mem_cpy(p, s, n); 14 | p[n] = 0; 15 | return p; 16 | } 17 | -------------------------------------------------------------------------------- /src/str/rchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_rchr(char *v, usize n, int c) 6 | { 7 | uchar *p, *s; 8 | 9 | p = nil; 10 | s = (uchar *)v; 11 | for (; n && *s; --n) { 12 | if (*s == c) 13 | p = s; 14 | ++s; 15 | } 16 | return (char *)p; 17 | } 18 | -------------------------------------------------------------------------------- /src/uint/32bigunpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_uint_32bigunpack(char *s) 6 | { 7 | u32 r; 8 | 9 | r = (uchar)s[0]; 10 | r <<= 8; 11 | r += (uchar)s[1]; 12 | r <<= 8; 13 | r += (uchar)s[2]; 14 | r <<= 8; 15 | r += (uchar)s[3]; 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /src/nix/deepsleep.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_nix_deepsleep(ctype_taia *deadline, ctype_taia *stamp) 6 | { 7 | ctype_iopause x; 8 | 9 | while (c_taia_less(stamp, deadline)) { 10 | c_nix_iopause(&x, 0, deadline, stamp); 11 | c_taia_now(stamp); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/nix/fdchown.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdchown(ctype_fd fd, ctype_id uid, ctype_id gid) 6 | { 7 | ctype_status r; 8 | 9 | do { 10 | r = c_sys_fchown(fd, uid, gid); 11 | } while ((r < 0) && errno == C_ERR_EINTR); 12 | 13 | return r; 14 | } 15 | -------------------------------------------------------------------------------- /src/ioq/flush.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_ioq_flush(ctype_ioq *p) 6 | { 7 | size r; 8 | 9 | if ((r = c_nix_allrw(p->op, p->fd, p->arr.p, p->arr.n)) < 0) 10 | return -1; 11 | 12 | c_arr_trunc(&p->arr, p->arr.n - r, sizeof(uchar)); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/adt/lpop.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_node * 5 | c_adt_lpop(ctype_node **sp) 6 | { 7 | ctype_node *o; 8 | 9 | if (!*sp) return nil; 10 | 11 | o = *sp; 12 | if ((*sp = o->prev)) (*sp)->next = o->next; 13 | 14 | o->prev = nil; 15 | o->next = o; 16 | return o; 17 | } 18 | -------------------------------------------------------------------------------- /src/cdb/mkaddbegin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_mkaddbegin(ctype_cdbmk *p, usize klen, usize dlen) 6 | { 7 | char buf[8]; 8 | c_uint_32pack(buf, klen); 9 | c_uint_32pack(buf + 4, dlen); 10 | if (c_ioq_nput(&p->ioq, buf, 8) < 0) return -1; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /src/rand/u32.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_rand_u32(u32 n) 6 | { 7 | u32 min, x; 8 | 9 | if (n < 2) 10 | return 0; 11 | 12 | min = -n % n; 13 | for (;;) { 14 | c_rand_data((void *)(uintptr)&x, sizeof(x)); 15 | if (x >= min) break; 16 | } 17 | return x % n; 18 | } 19 | -------------------------------------------------------------------------------- /src/std/atexit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_node *_tertium_atexit; 5 | 6 | ctype_status 7 | c_std_atexit(void (*func)(void)) 8 | { 9 | ctype_node *p; 10 | if (!(p = c_adt_lnew((void *)(uintptr)func, 0))) return -1; 11 | c_adt_lpush(&_tertium_atexit, p); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/dyn/alloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_dyn_alloc(ctype_arr *p, usize m, usize n) 6 | { 7 | usize t; 8 | 9 | if (c_dyn_ready(p, m, n) < 0) 10 | return nil; 11 | 12 | m *= n; 13 | if ((t = m + n) > c_arr_bytes(p)) 14 | p->n = t; 15 | 16 | return p->p + m; 17 | } 18 | -------------------------------------------------------------------------------- /src/std/strtovl.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | vlong 5 | c_std_strtovl(char *p, int b, vlong l, vlong h, char **e, int *r) 6 | { 7 | vlong x; 8 | if ((x = c_std_strtouvl(p, b, 0, h, e, r)) < l) { 9 | x = l; 10 | if (r) *r = -1; 11 | errno = C_ERR_ERANGE; 12 | } 13 | return x; 14 | } 15 | -------------------------------------------------------------------------------- /src/adt/ltpop.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_node * 5 | c_adt_ltpop(ctype_node **sp) 6 | { 7 | ctype_node *n; 8 | 9 | if (!*sp) return nil; 10 | n = (*sp)->next; 11 | (*sp)->next = n->next; 12 | 13 | n->next->prev = nil; 14 | n->prev = nil; 15 | n->next = n; 16 | return n; 17 | } 18 | -------------------------------------------------------------------------------- /src/fmt/vprint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_fmt_vprint(ctype_fmt *p, char *fmt, va_list ap) 6 | { 7 | ctype_fmt f; 8 | size r; 9 | c_fmt_init(&f, p->farg, p->func); 10 | va_copy(f.args, ap); 11 | r = c_fmt_fmt(&f, fmt); 12 | va_end(f.args); 13 | return -(r < 0); 14 | } 15 | -------------------------------------------------------------------------------- /src/nix/waitpid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_id 5 | c_nix_waitpid(ctype_id pid, ctype_status *status, uint opts) 6 | { 7 | ctype_id id; 8 | 9 | do { 10 | id = c_sys_waitpid(pid, status, opts); 11 | } while ((id == (ctype_id)-1) && errno == C_ERR_EINTR); 12 | 13 | return id; 14 | } 15 | -------------------------------------------------------------------------------- /src/str/caserchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_caserchr(char *v, usize n, int c) 6 | { 7 | uchar *s, *p; 8 | 9 | p = nil; 10 | s = (uchar *)v + (n - 1); 11 | for (; n && *s; --n) { 12 | if ((*s | 32) == c) 13 | p = s; 14 | --s; 15 | } 16 | return (char *)p; 17 | } 18 | -------------------------------------------------------------------------------- /src/mem/cmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_mem_cmp(void *v1, usize n, void *v2) 6 | { 7 | uchar *s1, *s2; 8 | int diff; 9 | 10 | s1 = v1; 11 | s2 = v2; 12 | for (; n; --n) { 13 | if ((diff = *s1 - *s2)) 14 | return diff; 15 | ++s1; 16 | ++s2; 17 | } 18 | return 0; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/nix/fdcopy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_fdcopy(ctype_fd to, ctype_fd from) 6 | { 7 | ctype_status r; 8 | 9 | if (to == from) 10 | return 0; 11 | 12 | do { 13 | r = c_sys_dup2(from, to); 14 | } while ((r < 0) && errno == C_ERR_EINTR); 15 | 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /src/rand/name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar tab[] = \ 5 | "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; 6 | 7 | char * 8 | c_rand_name(char *s, usize n) 9 | { 10 | s[--n] = 0; 11 | c_rand_data(s, n); 12 | while (n--) s[n] = tab[s[n] & 63]; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /src/str/cmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_str_cmp(char *l, usize n, char *r) 6 | { 7 | uchar *a, *b; 8 | int diff; 9 | 10 | a = (uchar *)l; 11 | b = (uchar *)r; 12 | for (; n; ++a, ++b, --n) { 13 | if ((diff = *a - *b)) return diff; 14 | if (!*a) break; 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /src/taia/half.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_half(ctype_taia *t, ctype_taia *u) 6 | { 7 | t->atto = u->atto >> 1; 8 | 9 | if (u->nano & 1) t->atto += 500000000UL; 10 | t->nano = u->nano >> 1; 11 | 12 | if (u->sec.x & 1) t->nano += 500000000UL; 13 | t->sec.x = u->sec.x >> 1; 14 | } 15 | -------------------------------------------------------------------------------- /src/arr/cat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_arr_cat(ctype_arr *p, void *v, usize m, usize n) 6 | { 7 | if (!m) return 0; 8 | if (c_arr_ready(p, m, n) < 0) return -1; 9 | m *= n; 10 | c_mem_cpy(p->p + p->n, v, m); 11 | p->n += m; 12 | c_mem_set(p->p + p->n, n, 0); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/dyn/cat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_dyn_cat(ctype_arr *p, void *v, usize m, usize n) 6 | { 7 | if (!m) return 0; 8 | if (c_dyn_ready(p, m, n) < 0) return -1; 9 | m *= n; 10 | c_mem_cpy(p->p + p->n, v, m); 11 | p->n += m; 12 | c_mem_set(p->p + p->n, n, 0); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/rand/u32inc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u32 5 | c_rand_u32inc(ctype_rst *p, u32 n) 6 | { 7 | u32 min, x; 8 | 9 | if (n < 2) 10 | return 0; 11 | 12 | min = -n % n; 13 | for (;;) { 14 | c_rand_datainc(p, (void *)(uintptr)&x, sizeof(x)); 15 | if (x >= min) break; 16 | } 17 | return x % n; 18 | } 19 | -------------------------------------------------------------------------------- /src/nix/readlink.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_nix_readlink(char *buf, usize n, char *s) 6 | { 7 | size r; 8 | 9 | if ((r = c_sys_readlink(s, buf, n)) < 0) 10 | return -1; 11 | if ((usize)r == n) { 12 | errno = C_ERR_ENAMETOOLONG; 13 | return -1; 14 | } 15 | buf[r] = 0; 16 | return r; 17 | } 18 | -------------------------------------------------------------------------------- /src/str/cspn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_str_cspn(char *v, usize n, char *reject) 6 | { 7 | uchar *s, *p; 8 | 9 | s = (uchar *)v; 10 | for (; n && *s; --n) { 11 | for (p = (uchar *)reject; *p && *s != *p; ++p) ; 12 | if (*p) 13 | break; 14 | ++s; 15 | } 16 | return s - (uchar *)v; 17 | } 18 | -------------------------------------------------------------------------------- /src/str/ltrim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_ltrim(char *str, usize n, char *t) 6 | { 7 | usize tlen; 8 | uchar *s; 9 | tlen = c_str_len(t, -1); 10 | s = (uchar *)str; 11 | for (; n && *s; --n, ++s) { 12 | if (!c_mem_chr(t, tlen, *s)) break; 13 | *s = 0; 14 | } 15 | return (char *)s; 16 | } 17 | -------------------------------------------------------------------------------- /src/str/spn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_str_spn(char *v, usize n, char *accept) 6 | { 7 | uchar *s, *p; 8 | 9 | s = (uchar *)v; 10 | for (; n && *s; --n) { 11 | for (p = (uchar *)accept; *p && *s != *p; ++p) ; 12 | if (!*p) 13 | break; 14 | ++s; 15 | } 16 | return s - (uchar *)v; 17 | } 18 | -------------------------------------------------------------------------------- /src/utf8/checkrune.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_utf8_checkrune(ctype_rune r) 6 | { 7 | if (r > C_UTF8_RUNEMAX || 8 | (r & 0xFFFE) == 0xFFFE || 9 | (r >= 0xD800 && r <= 0xDFFF) || 10 | (r >= 0xFDD0 && r <= 0xFDEF) || 11 | (r > 0x10FFFF)) 12 | return -1; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /src/utf8/utfnlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | usize 5 | c_utf8_utfnlen(char *s, usize n) 6 | { 7 | ctype_rune rune; 8 | usize len; 9 | int r; 10 | len = 0; 11 | while (*s) { 12 | if ((r = c_utf8_charntorune(&rune, s, n)) <= 0) break; 13 | s += r; 14 | n -= r; 15 | ++len; 16 | } 17 | return len; 18 | } 19 | -------------------------------------------------------------------------------- /src/err/vwarn.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_err_vwarn(char *fmt, va_list args) 6 | { 7 | c_ioq_fmt(ioq2, "%s: ", c_std_getprogname()); 8 | if (fmt) { 9 | c_ioq_vfmt(ioq2, fmt, args); 10 | c_ioq_put(ioq2, ": "); 11 | } 12 | c_ioq_fmt(ioq2, "%r\n", errno); 13 | c_ioq_flush(ioq2); 14 | return 1; 15 | } 16 | -------------------------------------------------------------------------------- /src/rand/nameinc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uchar tab[] = \ 5 | "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; 6 | 7 | char * 8 | c_rand_nameinc(ctype_rst *p, char *s, usize n) 9 | { 10 | s[--n] = 0; 11 | c_rand_datainc(p, s, n); 12 | while (n--) s[n] = tab[s[n] & 63]; 13 | return s; 14 | } 15 | -------------------------------------------------------------------------------- /src/std/werrstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_std_werrstr(char *fmt, ...) 6 | { 7 | ctype_arr arr; 8 | va_list ap; 9 | char buf[C_IOQ_ERRSIZ]; 10 | 11 | c_arr_init(&arr, buf, sizeof(buf)); 12 | va_start(ap, fmt); 13 | c_arr_vfmt(&arr, fmt, ap); 14 | va_end(ap); 15 | c_std_errstr(buf, sizeof(buf)); 16 | } 17 | -------------------------------------------------------------------------------- /src/adt/lpush.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_adt_lpush(ctype_node **sp, ctype_node *p) 6 | { 7 | ctype_node *head; 8 | 9 | if (!p) 10 | return -1; 11 | 12 | head = p->next; 13 | if ((head->prev = *sp)) { 14 | p->next = (*sp)->next; 15 | (*sp)->next = head; 16 | } 17 | *sp = p; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /src/arr/ready.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_arr_ready(ctype_arr *p, usize m, usize n) 6 | { 7 | if (C_STD_OVERFLOWM(usize, m, n)) { 8 | errno = C_ERR_EOVERFLOW; 9 | return -1; 10 | } 11 | if ((m = (m * n) + n) > c_arr_avail(p)) { 12 | errno = C_ERR_ENOMEM; 13 | return -1; 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/arr/trunc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_arr_trunc(ctype_arr *p, usize m, usize n) 6 | { 7 | if (C_STD_OVERFLOWM(usize, m, n)) { 8 | errno = C_ERR_EOVERFLOW; 9 | return -1; 10 | } 11 | 12 | if (c_arr_bytes(p) <= (m *= n)) return 0; 13 | p->n = m; 14 | if (p->p) p->p[p->n] = 0; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /src/str/rtrim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_rtrim(char *str, usize n, char *t) 6 | { 7 | usize len, tlen; 8 | 9 | len = c_str_len(str, n) - 1; 10 | tlen = c_str_len(t, -1); 11 | for (; len; --len) { 12 | if (!c_mem_chr(t, tlen, str[len])) 13 | break; 14 | str[len] = 0; 15 | } 16 | return str; 17 | } 18 | -------------------------------------------------------------------------------- /sys/Linux/x86_64/ctypes.h.in: -------------------------------------------------------------------------------- 1 | typedef long long intptr; 2 | typedef unsigned long long uintptr; 3 | typedef unsigned long usize; 4 | typedef long size; 5 | typedef unsigned char u8; 6 | typedef unsigned short u16; 7 | typedef unsigned u32; 8 | typedef unsigned long long u64; 9 | typedef char i8; 10 | typedef short i16; 11 | typedef int i32; 12 | typedef long long i64; 13 | -------------------------------------------------------------------------------- /src/adt/kvget.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "kv.h" 5 | 6 | void * 7 | c_adt_kvget(ctype_kvtree *t, char *k) 8 | { 9 | ctype_kvent *p; 10 | usize len; 11 | if (!t->root) return nil; 12 | len = c_str_len(k, -1); 13 | p = walk(t->root, (void *)k, len); 14 | if (c_mem_cmp(k, len+1, p->k)) return nil; 15 | return p->v; 16 | } 17 | -------------------------------------------------------------------------------- /src/nix/allrw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_nix_allrw(ctype_iofn op, ctype_fd fd, void *p, usize n) 6 | { 7 | size r; 8 | uchar *s; 9 | 10 | s = p; 11 | while (n) { 12 | if ((r = op(fd, p, n)) < 0) 13 | return r; 14 | if (!r) 15 | break; 16 | s += r; 17 | n -= r; 18 | } 19 | return s - (uchar *)p; 20 | } 21 | -------------------------------------------------------------------------------- /src/std/noopt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_std_noopt(ctype_arg *p, char *s) 6 | { 7 | if (s && s[0] == '-') { 8 | if (s[1] == '-' && s[2] == '\0') { 9 | ++p->idx; 10 | return 0; 11 | } else if (s[1] == '\0') { 12 | return 0; 13 | } else { 14 | return (p->opt = s[1]); 15 | } 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/cal/timetai.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_cal_timetai(ctype_tai *t, ctype_caltime *p) 6 | { 7 | long day, s; 8 | day = c_cal_datemjd(&p->date); 9 | s = ((p->hour * 60 + p->minute) - p->offset) * 60 + p->second; 10 | t->x = day * 86400ULL + 4611686014920671114ULL + (vlong)s; 11 | c_tai_leapadd(t, p->second == 60); 12 | } 13 | -------------------------------------------------------------------------------- /src/utf8/utfrune.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_utf8_utfrune(char *s, ctype_rune r) 6 | { 7 | ctype_rune rune; 8 | int n; 9 | 10 | if (r < 0x80) 11 | return c_str_chr(s, -1, r); 12 | 13 | while (*s) { 14 | n = c_utf8_chartorune(&rune, s); 15 | if (rune == r) 16 | return s; 17 | s += n; 18 | } 19 | return nil; 20 | } 21 | -------------------------------------------------------------------------------- /src/mem/cpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_mem_cpy(void *d, void *s, usize n) 6 | { 7 | uchar *a, *b; 8 | 9 | if (s == d) return d; 10 | a = d; 11 | b = s; 12 | 13 | if (s > d) { 14 | for (; n; --n) *a++ = *b++; 15 | } else { 16 | a += n - 1; 17 | b += n - 1; 18 | for (; n; --n) *a-- = *b--; 19 | } 20 | return d; 21 | } 22 | -------------------------------------------------------------------------------- /src/mem/mem.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_mem_mem(void *h, usize hl, void *n, usize nl) 6 | { 7 | uchar *p; 8 | 9 | if (nl > hl) 10 | return nil; 11 | 12 | while ((p = c_mem_chr(h, hl, *(uchar *)n))) { 13 | if (!c_mem_cmp(p, nl, n)) 14 | break; 15 | hl -= (p - (uchar *)h) + 1; 16 | h = p + 1; 17 | } 18 | return p; 19 | } 20 | -------------------------------------------------------------------------------- /sys/Linux/x86_64/syscall.s: -------------------------------------------------------------------------------- 1 | .global _tertium_syscall 2 | .type _tertium_syscall,@function 3 | _tertium_syscall: 4 | movq %rdi,%rax 5 | movq %rsi,%rdi 6 | movq %rdx,%rsi 7 | movq %rcx,%rdx 8 | movq %r8,%r10 9 | movq %r9,%r8 10 | movq 8(%rsp),%r9 11 | syscall 12 | cmpq $-4095,%rax 13 | jbe .L1 14 | negq %rax 15 | movq %rax,errno(%rip) 16 | movq $-1,%rax 17 | .L1: 18 | retq 19 | -------------------------------------------------------------------------------- /src/adt/lswap.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_adt_lswap(ctype_node **sp) 6 | { 7 | ctype_node *a, *b, *c; 8 | 9 | a = *sp; 10 | if (!(b = a->prev)) return -1; 11 | c = b->prev; 12 | 13 | b->prev = a; 14 | b->next = a->next; 15 | a->next = b; 16 | a->prev = c; 17 | 18 | if (c) c->next = a; 19 | *sp = b; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/cdb/mkstart.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_mkstart(ctype_cdbmk *p, ctype_fd fd) 6 | { 7 | p->fd = fd; 8 | p->off = 2048; 9 | c_mem_set(&p->hplist, sizeof(p->hplist), 0); 10 | c_ioq_init(&p->ioq, fd, p->buf, sizeof(p->buf), c_nix_fdwrite); 11 | if (c_nix_seek(fd, p->off, C_NIX_SEEKSET) < 0) return -1; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /src/utf8/isblank.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | static ctype_rune tab[] = { 7 | 0x0009, 8 | 0x0020, 9 | 0x00A0, 10 | 0x1680, 11 | 0x202F, 12 | 0x205F, 13 | 0x3000, 14 | }; 15 | 16 | /* , , Zs */ 17 | int 18 | c_utf8_isblank(ctype_rune r) 19 | { 20 | if (UTF8_SEARCH(&r, tab)) return 1; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /man/c_tai_now.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_NOW 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_now 6 | .Nd get current time 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_now "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_now 17 | function stores the current time into the TAI64 label 18 | .Fa t . 19 | -------------------------------------------------------------------------------- /src/adt/ltpush.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_adt_ltpush(ctype_node **sp, ctype_node *p) 6 | { 7 | ctype_node *head; 8 | 9 | if (!p) 10 | return -1; 11 | 12 | if (*sp) { 13 | head = p->next; 14 | p->next = (*sp)->next; 15 | p->next->prev = p; 16 | (*sp)->next = head; 17 | } else { 18 | *sp = p; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/std/getenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_std_getenv(char *s) 6 | { 7 | usize n; 8 | int i; 9 | 10 | if (!s || !environ) 11 | return nil; 12 | 13 | n = c_str_len(s, -1); 14 | for (i = 0; environ[i]; ++i) { 15 | if (!(c_mem_cmp(environ[i], n, s)) && (environ[i][n] == '=')) 16 | return environ[i] + n + 1; 17 | } 18 | return nil; 19 | } 20 | -------------------------------------------------------------------------------- /src/str/str.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_str(char *h, usize n, char *s) 6 | { 7 | usize len; 8 | char *p; 9 | 10 | len = c_str_len(s, -1); 11 | if (len > n) 12 | return nil; 13 | 14 | while ((p = c_str_chr(h, n, *s))) { 15 | if (!c_str_cmp(p, len, s)) 16 | break; 17 | n -= (p - h) + 1; 18 | h = p + 1; 19 | } 20 | return p; 21 | } 22 | -------------------------------------------------------------------------------- /man/c_taia_now.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_NOW 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_now 6 | .Nd get current time 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_now "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_now 17 | function stores the current time into the TAI64NA label 18 | .Fa t . 19 | -------------------------------------------------------------------------------- /src/gen/basename.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_gen_basename(char *s) 6 | { 7 | usize n; 8 | char *p; 9 | 10 | if (!s) return nil; 11 | if (!*s) return "."; 12 | 13 | n = c_str_len(s, -1); 14 | if (!--n) return s; 15 | 16 | for (; s[n] == '/'; --n) ; 17 | s[n + 1] = 0; 18 | 19 | if (!(p = c_mem_rchr(s, n, '/'))) return s; 20 | return ++p; 21 | } 22 | -------------------------------------------------------------------------------- /src/ioq/feed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_ioq_feed(ctype_ioq *p) 6 | { 7 | size r; 8 | 9 | if (p->arr.n) 10 | return p->arr.n; 11 | 12 | if ((r = (p->op)(p->fd, p->arr.p, p->arr.a)) <= 0) 13 | return r; 14 | 15 | p->arr.n = r; 16 | p->arr.a -= r; 17 | if (p->arr.a) 18 | c_mem_cpy(p->arr.p + p->arr.a, p->arr.p, r); 19 | 20 | return r; 21 | } 22 | -------------------------------------------------------------------------------- /src/str/casecmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_str_casecmp(char *v1, usize n, char *v2) 6 | { 7 | uchar *s1, *s2; 8 | int diff; 9 | 10 | s1 = (uchar *)v1; 11 | s2 = (uchar *)v2; 12 | for (; n; --n) { 13 | if ((diff = (*s1 | 32) - (*s2 | 32))) 14 | return diff; 15 | if (!*s1) 16 | return 0; 17 | ++s1; 18 | ++s2; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/tai/leapadd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | void 7 | c_tai_leapadd(ctype_tai *p, int h) 8 | { 9 | u64 u; 10 | int i; 11 | 12 | u = p->x; 13 | for (i = 0; i < _tertium_tai_leaptabsize; ++i) { 14 | if (u < _tertium_tai_leaptab[i]) 15 | break; 16 | if (!h || (u > _tertium_tai_leaptab[i])) 17 | ++u; 18 | } 19 | p->x = u; 20 | } 21 | -------------------------------------------------------------------------------- /src/uint/64pack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_64pack(char *s, u64 u) 6 | { 7 | s[0] = u & 255; 8 | u >>= 8; 9 | s[1] = u & 255; 10 | u >>= 8; 11 | s[2] = u & 255; 12 | u >>= 8; 13 | s[3] = u & 255; 14 | u >>= 8; 15 | s[4] = u & 255; 16 | u >>= 8; 17 | s[5] = u & 255; 18 | u >>= 8; 19 | s[6] = u & 255; 20 | s[7] = u >> 8; 21 | return s; 22 | } 23 | -------------------------------------------------------------------------------- /src/utf8/private.h: -------------------------------------------------------------------------------- 1 | #define UTF8_RANGESEARCH(a, b) \ 2 | c_std_bsearch((a), (b), (C_STD_NELEM((b))>>1), \ 3 | (sizeof(*(b))<<1), &_tertium_utf8_rangecmp) 4 | 5 | #define UTF8_SEARCH(a, b) \ 6 | c_std_bsearch((a), (b), C_STD_NELEM((b)), sizeof(*(b)), _tertium_utf8_cmp) 7 | 8 | int _tertium_utf8_rangecmp(void *, void *); 9 | int _tertium_utf8_cmp(void *, void *); 10 | 11 | extern uchar *_tertium_utf8_mtab; 12 | -------------------------------------------------------------------------------- /src/utf8/utfrrune.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_utf8_utfrrune(char *s, ctype_rune r) 6 | { 7 | ctype_rune rune; 8 | int n; 9 | char *p; 10 | 11 | if (r < 0x80) 12 | return c_str_rchr(s, -1, r); 13 | 14 | p = nil; 15 | while (*s) { 16 | n = c_utf8_chartorune(&rune, s); 17 | if (rune == r) 18 | p = s; 19 | s += n; 20 | } 21 | return p; 22 | } 23 | -------------------------------------------------------------------------------- /src/uint/64bigpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_uint_64bigpack(char *s, u64 u) 6 | { 7 | s[7] = u & 255; 8 | u >>= 8; 9 | s[6] = u & 255; 10 | u >>= 8; 11 | s[5] = u & 255; 12 | u >>= 8; 13 | s[4] = u & 255; 14 | u >>= 8; 15 | s[3] = u & 255; 16 | u >>= 8; 17 | s[2] = u & 255; 18 | u >>= 8; 19 | s[1] = u & 255; 20 | s[0] = u >> 8; 21 | return s; 22 | } 23 | -------------------------------------------------------------------------------- /src/str/casestr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char * 5 | c_str_casestr(char *h, usize n, char *s) 6 | { 7 | usize len; 8 | char *p; 9 | 10 | len = c_str_len(s, -1); 11 | if (len > n) 12 | return nil; 13 | 14 | while ((p = c_str_casechr(h, n, *s))) { 15 | if (!c_str_casecmp(p, len, s)) 16 | break; 17 | n -= (p - h) + 1; 18 | h = p + 1; 19 | } 20 | return p; 21 | } 22 | -------------------------------------------------------------------------------- /src/std/bsearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_std_bsearch(void *k, void *buf, usize m, usize n, ctype_cmpfn f) 6 | { 7 | int r; 8 | uchar *p, *s; 9 | s = (uchar *)buf; 10 | while (m) { 11 | p = s + (m >> 1) * n; 12 | if (!(r = f(k, p))) { 13 | return p; 14 | } else if (r > 0) { 15 | s = p + n; 16 | --m; 17 | } 18 | m >>= 1; 19 | } 20 | return nil; 21 | } 22 | -------------------------------------------------------------------------------- /src/adt/lrot.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_adt_lrot(ctype_node **sp) 6 | { 7 | ctype_node *a, *b, *c, *d; 8 | 9 | a = *sp; 10 | if (!(b = a->prev)) return 1; 11 | if (!(c = b->prev)) return 1; 12 | d = c->prev; 13 | 14 | c->next = a->next; 15 | a->next = c; 16 | b->prev = c->prev; 17 | c->prev = a; 18 | 19 | if (d) d->next = b; 20 | *sp = c; 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /src/ioq/vfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | put(ctype_fmt *p, char *s, usize n) 6 | { 7 | return c_ioq_nput(p->farg, s, n); 8 | } 9 | 10 | size 11 | c_ioq_vfmt(ctype_ioq *p, char *fmt, va_list args) 12 | { 13 | ctype_fmt f; 14 | size r; 15 | c_fmt_init(&f, p, put); 16 | va_copy(f.args, args); 17 | r = c_fmt_fmt(&f, fmt); 18 | va_end(f.args); 19 | return r; 20 | } 21 | -------------------------------------------------------------------------------- /src/mem/set.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static void * 5 | copy(void *v, usize n, int c) 6 | { 7 | volatile uchar *s; 8 | s = v; 9 | for (; n; --n) *s++ = c; 10 | return v; 11 | } 12 | 13 | /* Try to avoid compiler optimization */ 14 | static void *(* volatile set)(void *, usize, int) = copy; 15 | 16 | void * 17 | c_mem_set(void *v, usize n, int c) 18 | { 19 | return set(v, n, c); 20 | } 21 | -------------------------------------------------------------------------------- /man/c_tai_u64.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_U64 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_u64 6 | .Nd set TAI64 label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_u64 "ctype_tai *t" "u64 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_u64 17 | function sets the TAI64 label 18 | .Fa t 19 | to 20 | .Fa u . 21 | .Sh SEE ALSO 22 | .Xr c_tai_now 3 23 | -------------------------------------------------------------------------------- /src/adt/kv.h: -------------------------------------------------------------------------------- 1 | struct node { 2 | void *child[2]; 3 | u32 byte; 4 | u8 otherbits; 5 | }; 6 | 7 | static inline void * 8 | walk(uchar *p, uchar *s, usize n) 9 | { 10 | struct node *q; 11 | int direction; 12 | uchar c; 13 | while ((uintptr)p & 1) { 14 | q = (void *)(p - 1); 15 | c = (n > q->byte) ? s[q->byte] : 0; 16 | direction = (1 + (q->otherbits | c)) >> 8; 17 | p = q->child[direction]; 18 | } 19 | return p; 20 | } 21 | -------------------------------------------------------------------------------- /man/c_tai_fromtime.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_FROMTIME 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_fromtime 6 | .Nd convert time to TAI64 label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_fromtime "ctype_tai *t" "ctype_time *tm" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the time 18 | .Fa tm 19 | to TAI64 label 20 | .Fa t . 21 | -------------------------------------------------------------------------------- /src/nix/rmpath.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_rmpath(char *dir) 6 | { 7 | char *s; 8 | char buf[C_LIM_PATHMAX]; 9 | 10 | c_str_cpy(buf, sizeof(buf), dir); 11 | c_str_rtrim(buf, sizeof(buf), "/"); 12 | for (;;) { 13 | if (c_nix_rmdir(buf) < 0) 14 | return -1; 15 | if (!(s = c_str_rchr(buf, sizeof(buf), '/'))) 16 | break; 17 | *s = 0; 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /src/str/vfmtcnt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | put(ctype_fmt *p, char *s, usize n) 6 | { 7 | (void)p; 8 | (void)s; 9 | (void)n; 10 | return 0; 11 | } 12 | 13 | usize 14 | c_str_vfmtcnt(char *fmt, va_list ap) 15 | { 16 | ctype_fmt f; 17 | size r; 18 | c_fmt_init(&f, nil, put); 19 | va_copy(f.args, ap); 20 | r = c_fmt_fmt(&f, fmt); 21 | va_end(f.args); 22 | return r; 23 | } 24 | -------------------------------------------------------------------------------- /src/utf8/isprint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | static ctype_rune rangetab[] = { 7 | 0x00E000, 0x00F8FF, 8 | 0x0F0000, 0x0FFFFD, 9 | 0x100000, 0x10FFFD, 10 | }; 11 | 12 | /* !(Cc, Cf, Co, Zl, Zp) */ 13 | int 14 | c_utf8_isprint(ctype_rune r) 15 | { 16 | if (c_utf8_iscntrl(r)) 17 | return 0; 18 | if (UTF8_RANGESEARCH(&r, rangetab)) 19 | return 0; 20 | return 1; 21 | } 22 | -------------------------------------------------------------------------------- /src/utf8/runelen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int 5 | c_utf8_runelen(ctype_rune r) 6 | { 7 | if (c_utf8_checkrune(r) < 0) 8 | return 0; 9 | else if (r <= 0x00007F) 10 | return 1; 11 | else if (r <= 0x0007FF) 12 | return 2; 13 | else if (r <= 0x00FFFF) 14 | return 3; 15 | else if (r <= 0x1FFFFF) 16 | return 4; 17 | else if (r <= 0x3FFFFF) 18 | return 5; 19 | else 20 | return 6; 21 | } 22 | -------------------------------------------------------------------------------- /man/c_ioq_flush.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_FLUSH 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_flush 6 | .Nd flush queue 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_flush "ctype_ioq *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_flush 17 | function flushes the output queue 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | .Rv -std 21 | .Sh SEE ALSO 22 | .Xr c_ioq_feed 3 23 | -------------------------------------------------------------------------------- /man/c_taia_fromtime.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_FROMTIME 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_fromtime 6 | .Nd convert time to TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_fromtime "ctype_tai *t" "ctype_time *tm" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the time 18 | .Fa tm 19 | to TAI64NA label 20 | .Fa t . 21 | -------------------------------------------------------------------------------- /man/c_taia_u64.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_U64 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_u64 6 | .Nd set TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_u64 "ctype_tai *t" "u64 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_u64 17 | function sets the TAI64NA label 18 | .Fa t 19 | to 20 | .Fa u . 21 | .Sh SEE ALSO 22 | .Xr c_taia_now 3 23 | -------------------------------------------------------------------------------- /src/arr/vfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | put(ctype_fmt *p, char *s, usize n) 6 | { 7 | return c_arr_cat(p->farg, s, n, sizeof(uchar)); 8 | } 9 | 10 | size 11 | c_arr_vfmt(ctype_arr *p, char *fmt, va_list args) 12 | { 13 | ctype_fmt f; 14 | size r; 15 | c_fmt_init(&f, p, put); 16 | va_copy(f.args, args); 17 | r = c_fmt_fmt(&f, fmt); 18 | va_end(f.args); 19 | return r; 20 | } 21 | -------------------------------------------------------------------------------- /src/dyn/vfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | put(ctype_fmt *p, char *s, usize n) 6 | { 7 | return c_dyn_cat(p->farg, s, n, sizeof(uchar)); 8 | } 9 | 10 | size 11 | c_dyn_vfmt(ctype_arr *p, char *fmt, va_list args) 12 | { 13 | ctype_fmt f; 14 | size r; 15 | c_fmt_init(&f, p, put); 16 | va_copy(f.args, args); 17 | r = c_fmt_fmt(&f, fmt); 18 | va_end(f.args); 19 | return r; 20 | } 21 | -------------------------------------------------------------------------------- /src/nix/syscall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ARGS(a) \ 5 | a[0], a[1], a[2], a[3], \ 6 | a[4], a[5], a[6], a[7] 7 | 8 | vlong 9 | c_nix_syscall_(vlong num, ...) 10 | { 11 | va_list ap; 12 | int i; 13 | void *args[8]; 14 | 15 | va_start(ap, num); 16 | for (i = 0; i < 8; ++i) 17 | args[i] = va_arg(ap, uintptr *); 18 | va_end(ap); 19 | return _tertium_syscall(num, ARGS(args)); 20 | } 21 | -------------------------------------------------------------------------------- /src/utf8/runecmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static int 5 | rangecmp(ctype_rune k, ctype_rune *p) 6 | { 7 | return (k >= p[0] && k <= p[1]) ? 0 : k - p[0]; 8 | } 9 | 10 | int 11 | _tertium_utf8_rangecmp(void *va, void *vb) 12 | { 13 | return rangecmp(*(ctype_rune *)va, vb); 14 | } 15 | 16 | int 17 | _tertium_utf8_cmp(void *va, void *vb) 18 | { 19 | return *(ctype_rune *)va - *(ctype_rune *)vb; 20 | } 21 | -------------------------------------------------------------------------------- /src/mem/ccpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_mem_ccpy(void *d, void *s, usize n, int c) 6 | { 7 | uchar *s1, *s2; 8 | 9 | s1 = d; 10 | s2 = s; 11 | if (s > d) { 12 | for (; n; --n) 13 | if ((*s1++ = *s2++) == c) 14 | return s1; 15 | } else { 16 | s1 += n - 1; 17 | s2 += n - 1; 18 | for (; n; --n) 19 | if ((*s1-- = *s2--) == c) 20 | return s1; 21 | } 22 | return nil; 23 | } 24 | -------------------------------------------------------------------------------- /src/std/vptrlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_std_vptrlist(char *s, va_list ap) 6 | { 7 | va_list tmp; 8 | usize i, n; 9 | char **av; 10 | 11 | va_copy(tmp, ap); 12 | for (n = 1; va_arg(tmp, char *); ++n) ; 13 | va_end(tmp); 14 | 15 | if (!(av = c_std_alloc(n + 1, sizeof(char *)))) return nil; 16 | av[0] = s; 17 | for (i = 1; i <= n; ++i) av[i] = va_arg(ap, char *); 18 | return av; 19 | } 20 | -------------------------------------------------------------------------------- /src/taia/sub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_sub(ctype_taia *t, ctype_taia *u, ctype_taia *v) 6 | { 7 | t->sec.x = u->sec.x - v->sec.x; 8 | t->nano = u->nano - v->nano; 9 | t->atto = u->atto - v->atto; 10 | 11 | if (t->atto > u->atto) { 12 | t->atto += 1000000000UL; 13 | t->nano--; 14 | } 15 | 16 | if (t->nano > u->nano) { 17 | t->nano += 1000000000UL; 18 | t->sec.x--; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/arr/get.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_arr_get(ctype_arr *p, usize m, usize n) 6 | { 7 | usize t; 8 | 9 | if (C_STD_OVERFLOWM(usize, m, n)) { 10 | errno = C_ERR_EOVERFLOW; 11 | return nil; 12 | } 13 | m *= n; 14 | if ((t = m + n) > c_arr_total(p)) { 15 | errno = C_ERR_ENOMEM; 16 | return nil; 17 | } 18 | 19 | if (t > c_arr_bytes(p)) 20 | p->n = t; 21 | 22 | return (p->p + m); 23 | } 24 | -------------------------------------------------------------------------------- /src/taia/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_taia_add(ctype_taia *t, ctype_taia *u, ctype_taia *v) 6 | { 7 | t->sec.x = u->sec.x + v->sec.x; 8 | t->nano = u->nano + v->nano; 9 | t->atto = u->atto + v->atto; 10 | 11 | if (t->atto > 999999999UL) { 12 | t->atto -= 1000000000UL; 13 | t->nano++; 14 | } 15 | 16 | if (t->nano > 999999999UL) { 17 | t->nano -= 1000000000UL; 18 | t->sec.x++; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/uint/64unpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u64 5 | c_uint_64unpack(char *s) 6 | { 7 | u64 r; 8 | 9 | r = (uchar)s[7]; 10 | r <<= 8; 11 | r += (uchar)s[6]; 12 | r <<= 8; 13 | r += (uchar)s[5]; 14 | r <<= 8; 15 | r += (uchar)s[4]; 16 | r <<= 8; 17 | r += (uchar)s[3]; 18 | r <<= 8; 19 | r += (uchar)s[2]; 20 | r <<= 8; 21 | r += (uchar)s[1]; 22 | r <<= 8; 23 | r += (uchar)s[0]; 24 | return r; 25 | } 26 | -------------------------------------------------------------------------------- /man/c_ioq_seek.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_SEEK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_seek 6 | .Nd seek queue 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_ioq_seek "ctype_ioq *p" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_seek 17 | function advances the read/write position in the I/O queue 18 | .Fa p 19 | by 20 | .Fa n 21 | bytes. 22 | .Sh SEE ALSO 23 | .Xr c_ioq_peek 3 24 | -------------------------------------------------------------------------------- /src/uint/64bigunpack.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | u64 5 | c_uint_64bigunpack(char *s) 6 | { 7 | u64 r; 8 | 9 | r = (uchar)s[0]; 10 | r <<= 8; 11 | r += (uchar)s[1]; 12 | r <<= 8; 13 | r += (uchar)s[2]; 14 | r <<= 8; 15 | r += (uchar)s[3]; 16 | r <<= 8; 17 | r += (uchar)s[4]; 18 | r <<= 8; 19 | r += (uchar)s[5]; 20 | r <<= 8; 21 | r += (uchar)s[6]; 22 | r <<= 8; 23 | r += (uchar)s[7]; 24 | return r; 25 | } 26 | -------------------------------------------------------------------------------- /src/adt/lnew.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_node * 5 | c_adt_lnew(void *v, usize n) 6 | { 7 | ctype_node *p; 8 | 9 | if (!(p = c_std_alloc(1, sizeof(*p)))) return nil; 10 | p->next = p; 11 | p->prev = nil; 12 | 13 | if (n) { 14 | if (!(p->p = c_std_alloc(n, sizeof(uchar)))) { 15 | c_std_free(p); 16 | return nil; 17 | } 18 | c_mem_cpy(p->p, v, n); 19 | } else { 20 | p->p = v; 21 | } 22 | return p; 23 | } 24 | -------------------------------------------------------------------------------- /src/nix/fdvfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | put(ctype_fmt *p, char *s, usize n) 6 | { 7 | return c_nix_allrw(&c_nix_fdwrite, *(ctype_fd *)p->farg, s, n); 8 | } 9 | 10 | ctype_status 11 | c_nix_fdvfmt(ctype_fd fd, char *fmt, va_list ap) 12 | { 13 | ctype_fmt f; 14 | size r; 15 | c_fmt_init(&f, &fd, put); 16 | va_copy(f.args, ap); 17 | r = c_fmt_fmt(&f, fmt); 18 | va_end(ap); 19 | return -(r < 0); 20 | } 21 | -------------------------------------------------------------------------------- /src/str/vfmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_str_vfmt(char **sp, char *fmt, va_list ap) 6 | { 7 | ctype_arr arr; 8 | size len; 9 | char *buf; 10 | va_list tmp; 11 | 12 | va_copy(tmp, ap); 13 | len = c_str_vfmtcnt(fmt, tmp) + 1; 14 | va_end(tmp); 15 | 16 | if (!(buf = c_std_alloc(len, sizeof(uchar)))) return (*sp = nil, -1); 17 | *sp = buf; 18 | c_arr_init(&arr, buf, len); 19 | return c_arr_vfmt(&arr, fmt, ap); 20 | } 21 | -------------------------------------------------------------------------------- /src/ioq/putfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | event(void *data, char *s, usize n) 6 | { 7 | ctype_ioq *p; 8 | p = data; 9 | return -(c_ioq_nput(p, s, n) < 0); 10 | } 11 | 12 | ctype_status 13 | c_ioq_putfd(ctype_ioq *p, ctype_fd fd, usize n) 14 | { 15 | return c_std_putfd(p, fd, n, &event); 16 | } 17 | 18 | ctype_status 19 | c_ioq_putfile(ctype_ioq *p, char *s) 20 | { 21 | return c_std_putfile(p, s, &event); 22 | } 23 | -------------------------------------------------------------------------------- /src/tai/leapsub.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | int 7 | c_tai_leapsub(ctype_tai *p) 8 | { 9 | u64 u; 10 | int i, s; 11 | 12 | u = p->x; 13 | s = 0; 14 | for (i = 0; i < _tertium_tai_leaptabsize; ++i) { 15 | if (u < _tertium_tai_leaptab[i]) 16 | break; 17 | ++s; 18 | if (u == _tertium_tai_leaptab[i]) { 19 | p->x = u - s; 20 | return 1; 21 | } 22 | } 23 | p->x = u - s; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/utf8/runetochar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern uchar *__utf8_mtab; 5 | 6 | int 7 | c_utf8_runetochar(char *s, ctype_rune r) 8 | { 9 | int i, n; 10 | 11 | switch ((n = c_utf8_runelen(r))) { 12 | case 0: 13 | return 0; 14 | case 1: 15 | s[0] = r; 16 | return 1; 17 | } 18 | 19 | for (i = n; i > 1; --i) { 20 | s[i - 1] = 0x80 | (r & 0x3F); 21 | r >>= 6; 22 | } 23 | s[0] = ~__utf8_mtab[n] | r; 24 | return n; 25 | } 26 | -------------------------------------------------------------------------------- /man/c_hsh_initk.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_INITK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_initk 6 | .Nd initialize keyed hash 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_hsh_initk "ctype_hst *p" "void *k" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_initk 17 | function initializes the hash structure 18 | .Fa p 19 | with the key 20 | .Fa k 21 | of 22 | .Fa n 23 | bytes in size. 24 | .Sh SEE ALSO 25 | .Xr 26 | -------------------------------------------------------------------------------- /man/c_rand_genseed.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_GENSEED 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_genseed 6 | .Nd set state structure seed 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_rand_genseed "ctype_rst *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_genseed 17 | function sets the seed from the state structure 18 | .Fa p 19 | to a random seed. 20 | .Sh SEE ALSO 21 | .Xr c_rand_setseed 3 22 | -------------------------------------------------------------------------------- /man/c_tai_unpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_UNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_unpack 6 | .Nd convert from external TAI64 format 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_unpack "ctype_tai *t" "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the external TAI64 format in 18 | .Fa s 19 | to TAI64 label 20 | .Fa t . 21 | .Sh SEE ALSO 22 | .Xr c_tai_pack 3 23 | -------------------------------------------------------------------------------- /man/c_taia_half.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_HALF 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_half 6 | .Nd halve TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_half "ctype_taia *t" "ctype_taia *u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_half 17 | function divides the TAI64NA label 18 | .Fa u 19 | by 2, rounding down to a multiple of 10^\-18, and stores the result into 20 | .Fa t . 21 | -------------------------------------------------------------------------------- /src/exc/wait.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_exc_wait(ctype_id id, ctype_status *status) 6 | { 7 | ctype_status child, r; 8 | r = c_nix_waitpid(id, &child, 0); 9 | if (r <= 0) return -1; 10 | if (_TERTIUM_SYS_WIFEXITED(child)) { 11 | *status = _TERTIUM_SYS_WEXITSTATUS(child); 12 | return 1; 13 | } 14 | if (_TERTIUM_SYS_WIFSIGNALED(child)) { 15 | *status = _TERTIUM_SYS_WTERMSIG(child); 16 | return 2; 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /man/c_ioq_peek.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_PEEK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_peek 6 | .Nd peek queue 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_ioq_peek "ctype_ioq *p" 14 | .Sh RETURN VALUES 15 | The 16 | .Fn c_ioq_peek 17 | function returns a pointer to first byte of data from the given queue. 18 | .Sh SEE ALSO 19 | .Xr c_ioq_get 3 , 20 | .Xr c_ioq_getdelim 3 , 21 | .Xr c_ioq_getln 3 , 22 | .Xr c_ioq_seek 3 23 | -------------------------------------------------------------------------------- /man/c_rand_setseed.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_SETSEED 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_setseed 6 | .Nd set state structure seed 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_rand_setseed "ctype_rst *p" "u64 seed" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_setseed 17 | function sets the seed from the state structure 18 | .Fa p 19 | to 20 | .Fa seed . 21 | .Sh SEE ALSO 22 | .Xr c_rand_genseed 3 23 | -------------------------------------------------------------------------------- /man/c_tai_pack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_PACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_pack 6 | .Nd convert to external TAI64 format 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_pack "char *s" "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_pack 17 | function converts the TAI64 label from 18 | .Fa t 19 | to external TAI64 format in 20 | .Fa s . 21 | .Sh SEE ALSO 22 | .Xr c_tai_unpack 3 23 | -------------------------------------------------------------------------------- /man/c_taia_unpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_UNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_unpack 6 | .Nd convert from external TAI64NA format 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_unpack "ctype_tai *t" "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the external TAI64NA format in 18 | .Fa s 19 | to TAI64NA label 20 | .Fa t . 21 | .Sh SEE ALSO 22 | .Xr c_taia_pack 3 23 | -------------------------------------------------------------------------------- /src/std/nbsearch.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_std_nbsearch(void *k, void *buf, usize m, usize n, ctype_cmpfn f) 6 | { 7 | int r; 8 | uchar *p, *s; 9 | 10 | r = 0; 11 | p = s = (uchar *)buf; 12 | while (m) { 13 | p = s + (m >> 1) * n; 14 | if (!(r = f(k, p))) { 15 | return p; 16 | } else if (r > 0) { 17 | s = p + n; 18 | --m; 19 | } 20 | m >>= 1; 21 | } 22 | if (r > 0) return p; 23 | return (p == buf) ? p : p - n; 24 | } 25 | -------------------------------------------------------------------------------- /inc/tertium/cpu.h.awk: -------------------------------------------------------------------------------- 1 | # SYSCALL NUMBER - TYPE - NAME - ARGS 2 | BEGIN { 3 | } 4 | 5 | # implicit 6 | /^[A-Za-z_].*\(.*\)$/ { 7 | out=$2" c_sys_"$3 8 | $1=$2=$3="" 9 | if ($4 == "()") $4="(void)" 10 | sub(/^[ \t]+/, "") 11 | print out""$0";" 12 | } 13 | 14 | # explicit 15 | /^[A-Za-z_].*\(.*\) / { 16 | out=$2" c_sys_"$3 17 | $1=$2=$3="" 18 | sub(/^[ \t]+/, "") 19 | sub(/ \{$/, "") 20 | gsub(/ [A-Za-z]+,/, ",") 21 | gsub(/ [A-Za-z]+)/, ")") 22 | print out""$0";" 23 | } 24 | 25 | END { 26 | } 27 | -------------------------------------------------------------------------------- /man/c_std_errstr.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_ERRSTR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_errstr 6 | .Nd error string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_std_errstr "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_errstr 17 | function swaps the buffer content of 18 | .Fa s 19 | of 20 | .Fa n 21 | bytes in size, with a error buffer. 22 | .Sh SEE ALSO 23 | .Xr c_std_sterror 3 , 24 | .Xr c_std_werrstr 3 25 | -------------------------------------------------------------------------------- /man/c_taia_pack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_PACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_pack 6 | .Nd convert to external TAI64NA format 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_pack "char *s" "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_pack 17 | function converts the TAI64NA label from 18 | .Fa t 19 | to external TAI64NA format in 20 | .Fa s . 21 | .Sh SEE ALSO 22 | .Xr c_taia_unpack 3 23 | -------------------------------------------------------------------------------- /man/c_tai_add.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_ADD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_add 6 | .Nd sum TAI64 label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_add "ctype_tai *t" "ctype_tai *u" "ctype_tai *v" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_add 17 | function calculates the sum from the TAI64 label 18 | .Fa u 19 | and 20 | .Fa v 21 | storing the result to 22 | .Fa t . 23 | .Sh SEE ALSO 24 | .Xr c_tai_sub 3 25 | -------------------------------------------------------------------------------- /src/cdb/read.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_read(ctype_cdb *p, char *s, usize n, ctype_fssize off) 6 | { 7 | if (p->map) { 8 | if ((off > p->size) || (p->size - off < (ctype_fssize)n)) { 9 | errno = C_ERR_EPROTO; 10 | return -1; 11 | } 12 | c_mem_cpy(s, p->map + off, n); 13 | return 0; 14 | } 15 | if (c_nix_seek(p->fd, off, C_NIX_SEEKSET) < 0) return -1; 16 | if (c_nix_allrw(&c_nix_fdread, p->fd, s, n) < 0) return -1; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/ioq/get.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_ioq_get(char *b, usize n, ctype_ioq *p) 6 | { 7 | usize len, min; 8 | size r; 9 | 10 | len = n; 11 | while (len) { 12 | if ((r = c_ioq_feed(p)) < 0) 13 | return -1; 14 | if (!r) 15 | break; 16 | 17 | min = C_STD_MIN((usize)r, len); 18 | c_mem_cpy(b, p->arr.p + p->arr.a, min); 19 | p->arr.n -= min; 20 | p->arr.a += min; 21 | len -= min; 22 | b += min; 23 | } 24 | return len ? n - len : n; 25 | } 26 | -------------------------------------------------------------------------------- /src/nix/fdputfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static ctype_status 5 | event(void *data, char *s, usize n) 6 | { 7 | ctype_fd *fd; 8 | fd = data; 9 | return -(c_nix_allrw(c_nix_fdwrite, *fd, s, n) < 0); 10 | } 11 | 12 | ctype_status 13 | c_nix_fdputfd(ctype_fd dest, ctype_fd src, usize n) 14 | { 15 | return c_std_putfd(&dest, src, n, &event); 16 | } 17 | 18 | ctype_status 19 | c_nix_fdputfile(ctype_fd fd, char *s) 20 | { 21 | return c_std_putfile(&fd, s, &event); 22 | } 23 | -------------------------------------------------------------------------------- /src/std/exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern ctype_node *_tertium_atexit; 5 | 6 | static void 7 | execfunc(void *p) 8 | { 9 | void (*func)(void); 10 | *(void **)(&func) = p; 11 | func(); 12 | } 13 | 14 | void 15 | c_std_exit(ctype_status status) 16 | { 17 | ctype_node *p; 18 | while ((p = c_adt_lpop(&_tertium_atexit))) { 19 | execfunc(p->p); 20 | c_adt_lfree(p, c_std_free_); 21 | } 22 | c_ioq_flush(ioq1); 23 | c_ioq_flush(ioq2); 24 | c_sys_exit(status); 25 | } 26 | -------------------------------------------------------------------------------- /man/c_std_sort.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_SORT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_sort 6 | .Nd sort array of objects 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_std_sort "void *v" "usize m" "usize n" "ctype_cmpfn f" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_sort 17 | function stably sorts an array of 18 | .Fa m 19 | objects, each 20 | .Fa n 21 | bytes in size, 22 | in ascending order according to the comparison function 23 | .Fa f . 24 | -------------------------------------------------------------------------------- /man/c_ioq_fileno.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_FILENO 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_fileno 6 | .Nd retrieve queue file descriptor 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_fd 13 | .Fn c_ioq_fileno "ctype_ioq *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_fileno 17 | function retrieves the file descriptor associated with the queue 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_ioq_fileno 22 | function returns the retrieved file descriptor. 23 | -------------------------------------------------------------------------------- /man/c_tai_sub.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_SUB 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_sub 6 | .Nd subtract TAI64 label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_tai_sub "ctype_tai *t" "ctype_tai *u" "ctype_tai *v" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_sub 17 | function calculates the difference from the TAI64 label 18 | .Fa u 19 | and 20 | .Fa v 21 | storing the result to 22 | .Fa t . 23 | .Sh SEE ALSO 24 | .Xr c_tai_add 3 25 | -------------------------------------------------------------------------------- /man/c_taia_add.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_ADD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_add 6 | .Nd sum TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_add "ctype_taia *t" "ctype_taia *u" "ctype_taia *v" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_add 17 | function calculates the sum from the TAI64NA label 18 | .Fa u 19 | and 20 | .Fa v 21 | storing the result to 22 | .Fa t . 23 | .Sh SEE ALSO 24 | .Xr c_taia_sub 3 25 | -------------------------------------------------------------------------------- /man/c_std_free.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_FREE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_free 6 | .Nd free memory region 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Fd #define c_std_free(a) a = c_std_free_((a)) 13 | .Ft void * 14 | .Fn c_std_free_ "void *p" 15 | .Sh DESCRIPTION 16 | The 17 | .Fn c_std_free 18 | function free the memory region 19 | .Fa p . 20 | .Sh SEE ALSO 21 | .Xr c_std_alloc 3 , 22 | .Xr c_std_calloc 3 , 23 | .Xr c_std_realloc 3 , 24 | .Xr c_std_setalloc 3 25 | -------------------------------------------------------------------------------- /src/gen/dirname.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define STRCPY(a, b) c_mem_cpy((a), (b), sizeof((b))) 5 | 6 | char * 7 | c_gen_dirname(char *s) 8 | { 9 | usize n; 10 | 11 | if (!s) return nil; 12 | if (!*s) return STRCPY(s, "."); 13 | 14 | n = c_str_len(s, -1) - 1; 15 | for (; s[n] == '/'; --n) if (!n) return STRCPY(s, "/"); 16 | for (; s[n] != '/'; --n) if (!n) return STRCPY(s, "."); 17 | for (; s[n] == '/'; --n) if (!n) return STRCPY(s, "/"); 18 | 19 | s[n+1] = 0; 20 | return s; 21 | } 22 | -------------------------------------------------------------------------------- /man/c_dir_close.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 10 2023 $ 2 | .Dt C_DIR_CLOSE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dir_close 6 | .Nd close file hierarchy stream 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_dir_close "ctype_dir *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dir_close 17 | function closes a file hierarchy stream 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_dir_close 22 | function returns the value 0. 23 | .Sh SEE ALSO 24 | .Xr c_dir_open 3 25 | -------------------------------------------------------------------------------- /man/c_str_len.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_STR_LEN 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_str_len 6 | .Nd find length of string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_str_len "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_str_len 17 | function calculates the length of the string 18 | .Fa s , 19 | up to 20 | .Fa n 21 | characters. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_str_len 25 | function returns the length of the given string. 26 | -------------------------------------------------------------------------------- /man/c_taia_sub.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_SUB 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_sub 6 | .Nd subtract TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_taia_sub "ctype_tai *t" "ctype_tai *u" "ctype_tai *v" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_sub 17 | function calculates the difference from the TAI64NA label 18 | .Fa u 19 | and 20 | .Fa v 21 | storing the result to 22 | .Fa t . 23 | .Sh SEE ALSO 24 | .Xr c_taia_add 3 25 | -------------------------------------------------------------------------------- /man/c_hsh_octets.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_OCTETS 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_octets 6 | .Nd calculate octets 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_hsh_octets "ctype_hst *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_octets 17 | function calculates the number of octets in the hash structure 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_hsh_octets 22 | function returns the number of octets from the given structure. 23 | .Sh SEE ALSO 24 | .Xr 25 | -------------------------------------------------------------------------------- /man/c_nix_deepsleep.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_NIX_DEEPSLEEP 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_nix_deepsleep 6 | .Nd sleep 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_nix_deepsleep "ctype_taia *deadline" "ctype_taia *stamp" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_nix_deepsleep 17 | function sleeps until the absolute time represented by the TAI64NA label 18 | .Fa deadline . 19 | The TAI64NA label 20 | .Fa stamp 21 | must contain the current time and is updated after waking up. 22 | -------------------------------------------------------------------------------- /src/cal/timeutc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | c_cal_timeutc(ctype_caltime *p, ctype_tai *t) 6 | { 7 | ctype_tai tmp; 8 | u64 u; 9 | long s; 10 | int leap; 11 | 12 | c_mem_cpy(&tmp, t, sizeof(t)); 13 | leap = c_tai_leapsub(&tmp); 14 | u = tmp.x + 58486; 15 | s = u % 86400ULL; 16 | 17 | p->second = (s % 60) + leap; 18 | s /= 60; 19 | p->minute = s % 60; 20 | s /= 60; 21 | p->hour = s; 22 | 23 | u /= 86400ULL; 24 | c_cal_datefrommjd(&p->date, u - 53375995543064ULL); 25 | p->offset = 0; 26 | } 27 | -------------------------------------------------------------------------------- /src/dir/list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | ctype_dent * 7 | c_dir_list(ctype_dir *p) 8 | { 9 | ctype_dent *ep; 10 | ctype_node *cur; 11 | 12 | if (!(cur = p->ccur)) { 13 | p->ccur = p->cur; 14 | if ((ep = p->ccur->p)->info == C_DIR_FSINT) { 15 | p->ccur = p->ccur->next; 16 | ep = p->ccur->p; 17 | } 18 | return ep; 19 | } 20 | 21 | cur = cur->next; 22 | if (cur->prev) { 23 | p->ccur = cur; 24 | return cur->p; 25 | } 26 | 27 | p->ccur = nil; 28 | return nil; 29 | } 30 | -------------------------------------------------------------------------------- /src/ioq/nput.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define BLK(x) C_STD_MIN(C_IOQ_BSIZ, (x)) 5 | 6 | ctype_status 7 | c_ioq_nput(ctype_ioq *p, char *s, usize n) 8 | { 9 | size r; 10 | 11 | if (n > c_arr_avail(&p->arr)) { 12 | if (c_ioq_flush(p) < 0) 13 | return -1; 14 | while (n > c_arr_avail(&p->arr)) { 15 | if ((r = c_nix_allrw(p->op, p->fd, s, BLK(n))) < 0) 16 | return -1; 17 | n -= r; 18 | s += r; 19 | } 20 | } 21 | c_mem_cpy(p->arr.p + p->arr.n, s, n); 22 | p->arr.n += n; 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /src/ioq/tofrom.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size 5 | c_ioq_tofrom(ctype_ioq *dest, ctype_ioq *src, usize n) 6 | { 7 | usize len, min; 8 | size r; 9 | 10 | len = n; 11 | while (len) { 12 | if ((r = c_ioq_feed(src)) < 0) 13 | return -1; 14 | if (!r) 15 | break; 16 | 17 | min = C_STD_MIN((usize)r, len); 18 | if (c_ioq_nput(dest, (char *)src->arr.p + src->arr.a, min) < 0) 19 | return -1; 20 | src->arr.n -= min; 21 | src->arr.a += min; 22 | len -= min; 23 | } 24 | return len ? n - len : n; 25 | } 26 | -------------------------------------------------------------------------------- /src/nix/mklntemp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_mklntemp(char *s, usize n, char *target) 6 | { 7 | usize len; 8 | char *p; 9 | 10 | if (!(p = c_str_rchr(s, n, 'X'))) { 11 | errno = C_ERR_EINVAL; 12 | return -1; 13 | } 14 | 15 | for (len = 0; *p == 'X'; --p, ++len) ; 16 | ++p, ++len; 17 | 18 | for (;;) { 19 | c_rand_name(p, len); 20 | if (c_nix_symlink(s, target) < 0) { 21 | if (errno != C_ERR_EEXIST) return -1; 22 | continue; 23 | } 24 | break; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /src/utf8/istitle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | static ctype_rune rangetab[] = { 7 | 0x1F88, 0x1F90, 8 | 0x1F98, 0x1FA0, 9 | 0x1FA8, 0x1FB0, 10 | }; 11 | 12 | static ctype_rune tab[] = { 13 | 0x01C5, 14 | 0x01C8, 15 | 0x01CB, 16 | 0x01F2, 17 | 0x1FBC, 18 | 0x1FCC, 19 | 0x1FFC, 20 | }; 21 | 22 | /* Lt */ 23 | int 24 | c_utf8_istitle(ctype_rune r) 25 | { 26 | if (UTF8_RANGESEARCH(&r, rangetab)) 27 | return 1; 28 | if (UTF8_SEARCH(&r, tab)) 29 | return 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /man/c_adt_lfree.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ADT_LFREE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_adt_lfree 6 | .Nd free a list 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_adt_lfree "ctype_node *np" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_adt_lfree 17 | function free all the resources assigned to the node 18 | .Fa np . 19 | .Sh EXAMPLES 20 | To free an entire list: 21 | .Bd -literal -offset ident 22 | ctype_node *p; 23 | while ((p = c_adt_lpop(&list))) c_adt_lfree(p); 24 | .Ed 25 | -------------------------------------------------------------------------------- /man/c_fmt_put.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_FMT_PUT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_fmt_put 6 | .Nd print string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_fmt_put "ctype_fmt *p" "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_fmt_put 17 | function writes the string 18 | .Fa s 19 | using the output function assigned to the formatter 20 | Fa p . 21 | .Sh RETURN VALUES 22 | .Rv -std 23 | .Sh SEE ALSO 24 | .Xr c_fmt_fmt 3 , 25 | .Xr c_fmt_nput 3 , 26 | .Xr c_fmt_vprint 3 27 | -------------------------------------------------------------------------------- /src/cdb/init.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_init(ctype_cdb *p, ctype_fd fd) 6 | { 7 | ctype_stat st; 8 | uchar *x; 9 | 10 | p->map = nil; 11 | c_cdb_free(p); 12 | c_cdb_findstart(p); 13 | p->fd = fd; 14 | if (c_nix_fdstat(&st, fd) < 0) 15 | return -1; 16 | if (st.size >= 0xFFFFFFFF) { 17 | errno = C_ERR_EOVERFLOW; 18 | return -1; 19 | } 20 | if (!(x = c_nix_mmap(0, st.size, C_NIX_PROTREAD, C_NIX_MAPSHARED, fd, 0))) { 21 | p->size = st.size; 22 | p->map = x; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/dir/children.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | ctype_dent * 7 | c_dir_children(ctype_dir *p) 8 | { 9 | ctype_dent *ep; 10 | ctype_node *cur; 11 | 12 | if (!(cur = p->ccur)) { 13 | ep = p->cur->p; 14 | if (ep->info != C_DIR_FSD) return nil; 15 | p->child = p->ccur = _tertium_dir_builddir(p); 16 | return p->ccur->p; 17 | } 18 | 19 | cur = cur->next; 20 | if (cur->prev) { 21 | p->ccur = cur; 22 | ep = cur->p; 23 | return ep; 24 | } 25 | 26 | p->ccur = nil; 27 | return nil; 28 | } 29 | -------------------------------------------------------------------------------- /man/c_tai_approx.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_APPROX 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_approx 6 | .Nd calculate double-precision approximation 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft double 13 | .Fn c_tai_approx "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_approx 17 | function calculates a double-precision approximation from the TAI64 label 18 | .Fa t . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_tai_approx 22 | function returns a double-precision timestamp approximation. 23 | -------------------------------------------------------------------------------- /man/c_utf8_checkrune.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_CHECKRUNE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_checkrune 6 | .Nd check rune validity 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_utf8_checkrune "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_checkrune 17 | function checks the validity of the Unicode code point 18 | .Fa r . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_utf8_checkrune 22 | function returns the value 0 if the given rune is valid, and \-1 otherwise. 23 | -------------------------------------------------------------------------------- /src/cdb/mkadd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_cdb_mkadd(ctype_cdbmk *p, char *k, usize klen, char *s, usize dlen) 6 | { 7 | char buf[C_HSH_H32DIG]; 8 | 9 | if (c_cdb_mkaddbegin(p, klen, dlen) < 0 || 10 | c_ioq_nput(&p->ioq, k, klen) < 0 || 11 | c_ioq_nput(&p->ioq, s, dlen) < 0) 12 | goto fail; 13 | 14 | c_hsh_str(buf, c_hsh_murmur32, k, klen); 15 | if (c_cdb_mkaddend(p, klen, dlen, c_uint_32unpack(buf)) < 0) 16 | goto fail; 17 | return 0; 18 | fail: 19 | c_dyn_free(&p->hplist); 20 | return -1; 21 | } 22 | -------------------------------------------------------------------------------- /man/c_rand_u32.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_U32 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_u32 6 | .Nd random number generator 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_rand_u32 "u32 n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_u32 17 | function generates a random number, 18 | uniformly distributed but less than 19 | .Fa n . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_rand_u32 23 | function returns the generated number. 24 | .Sh SEE ALSO 25 | .Xr c_rand_data 3 , 26 | .Xr c_rand_name 3 27 | -------------------------------------------------------------------------------- /man/c_tai_less.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAI_LESS 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_tai_less 6 | .Nd compare TAI64 label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_tai_less "ctype_tai *t" "ctype_tai *u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_tai_less 17 | function compares two TAI64 labels 18 | .Fa t 19 | and 20 | .Fa u . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_tai_less 24 | function returns the value 1 if the first TAI64 label is 25 | less than the second; otherwise 0 is returned. 26 | -------------------------------------------------------------------------------- /src/utf8/isspace.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | static ctype_rune rangetab[] = { 7 | 0x00009, 0x0000E, 8 | 0x0001C, 0x00021, 9 | 0x02000, 0x0200B, 10 | 0x02028, 0x0202A, 11 | }; 12 | 13 | static ctype_rune tab[] = { 14 | 0x00085, 15 | 0x000A0, 16 | 0x01680, 17 | 0x0202F, 18 | 0x0205F, 19 | 0x03000, 20 | }; 21 | 22 | /* Zs, Zl, Zp */ 23 | int 24 | c_utf8_isspace(ctype_rune r) 25 | { 26 | if (UTF8_RANGESEARCH(&r, rangetab)) 27 | return 1; 28 | if (UTF8_SEARCH(&r, tab)) 29 | return 1; 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /man/c_hsh_str.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_STR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_str 6 | .Nd hash string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_hsh_str "char *buf" "ctype_hmd *p" "char *data" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_str 17 | function hashes the string 18 | .Fa data 19 | of 20 | .Fa n 21 | bytes in size, using the algorithm specified by 22 | .Fa p , 23 | storing the resulting hash is stored in 24 | .Fa buf . 25 | .Sh SEE ALSO 26 | .Xr c_hsh_putfd 3 , 27 | .Xr c_hsh_putfile 3 28 | -------------------------------------------------------------------------------- /man/c_taia_less.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_LESS 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_less 6 | .Nd compare TAI64NA label 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_taia_less "ctype_tai *t" "ctype_tai *u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_less 17 | function compares two TAI64NA labels 18 | .Fa t 19 | and 20 | .Fa u . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_taia_less 24 | function returns the value 1 if the first TAI64NA label is 25 | less than the second; otherwise 0 is returned. 26 | -------------------------------------------------------------------------------- /src/ioq/getdelim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_ioq_getdelim(ctype_arr *b, ctype_ioq *p, char *delim) 6 | { 7 | size n, r; 8 | int found; 9 | char *d, *s, *tmp; 10 | found = 0; 11 | while (!found) { 12 | if ((r = n = c_ioq_feed(p)) <= 0) return n; 13 | s = c_ioq_peek(p); 14 | for (tmp = delim; *tmp; ++tmp) { 15 | if ((d = c_mem_chr(s, n, *tmp))) { 16 | found = 1; 17 | r = (d - s) + 1; 18 | } 19 | } 20 | if (c_dyn_cat(b, s, r, sizeof(uchar)) < 0) return -1; 21 | c_ioq_seek(p, r); 22 | } 23 | return 1; 24 | } 25 | -------------------------------------------------------------------------------- /src/rand/datainc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static u64 _tertium_rand_const = 0x19D699A5; /* !!! */ 5 | 6 | static u32 7 | rng(ctype_rst *p) 8 | { 9 | u64 x; 10 | x = p->state; 11 | p->state = x * 6364136223846793005u + _tertium_rand_const; 12 | return c_hsh_ror32(((x >> 18) ^ x) >> 27, x >> 59); 13 | } 14 | 15 | char * 16 | c_rand_datainc(ctype_rst *p, char *s, usize n) 17 | { 18 | u32 x; 19 | u8 r; 20 | 21 | while (n) { 22 | n -= r = C_STD_MIN(n, sizeof(u32)); 23 | x = rng(p); 24 | c_mem_cpy(s + n, &x, r); 25 | } 26 | return s; 27 | } 28 | -------------------------------------------------------------------------------- /man/c_adt_kvfree.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ADT_KVFREE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_adt_kvfree 6 | .Nd 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_adt_kvfree "ctype_kvtree *t" "void (*freeobj)(void *)" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_adt_kvfree 17 | function traverses the key-value tree 18 | .Fa t 19 | calling, if given, the function 20 | .Fa freeobj 21 | with the key associated value as argument before freeing the key. 22 | .Sh SEE ALSO 23 | .Xr c_adt_kvdel 3 , 24 | .Xr c_adt_kvtraverse 3 25 | -------------------------------------------------------------------------------- /man/c_rand_data.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_DATA 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_data 6 | .Nd random data generator 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_rand_data "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_data 17 | function fills the region 18 | .Fa s 19 | of 20 | .Fa n 21 | bytes with random data. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_rand_data 25 | function returns a pointer to 26 | .Fa s . 27 | .Sh SEE ALSO 28 | .Xr c_rand_name 3 , 29 | .Xr c_rand_u32 3 30 | -------------------------------------------------------------------------------- /man/c_std_getenv.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_GETENV 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_getenv 6 | .Nd retrieve environment variable 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_std_getenv "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_getenv 17 | function retrieves the current value of the environment variable 18 | .Fa s . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_std_getenv 22 | function returns a pointer to the requested value, 23 | or nil if it could not be found. 24 | .Sh SEE ALSO 25 | .Xr c_exc_setenv 3 26 | -------------------------------------------------------------------------------- /man/c_utf8_utflen.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_UTFLEN 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_utflen 6 | .Nd calculate string rune length 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_utf8_utflen "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_utflen 17 | function calculates the number of runes that are represented by 18 | the UTF string 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_utf8_utflen 23 | function returns the found number of runes. 24 | .Sh SEE ALSO 25 | .Xr c_utf8_utfnlen 3 26 | -------------------------------------------------------------------------------- /man/c_fmt_nput.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_FMT_NPUT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_fmt_nput 6 | .Nd print string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_fmt_nput "ctype_fmt *p" "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_fmt_nput 17 | function writes the string 18 | .Fa s 19 | of 20 | .Fa n 21 | bytes in size, using the output function assigned to the formatter 22 | Fa p . 23 | .Sh RETURN VALUES 24 | .Rv -std 25 | .Sh SEE ALSO 26 | .Xr c_fmt_fmt 3 , 27 | .Xr c_fmt_put 3 , 28 | .Xr c_fmt_vprint 3 29 | -------------------------------------------------------------------------------- /man/c_ioq_init.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_INIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_init 6 | .Nd initialize queue 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_ioq_init "ctype_ioq *p" "ctype_fd fd" "char *buf" "usize n" "ctype_iofn f" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_init 17 | function initializes the I/O queue 18 | .Fa p , 19 | it sets the internal buffer to 20 | .Fa buf 21 | of 22 | .Fa n 23 | bytes in size , 24 | sets the I/O operation function to 25 | .Fa f , 26 | and sets the file descriptor to 27 | .Fa fd . 28 | -------------------------------------------------------------------------------- /src/arr/idxcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_arr_idxcat(ctype_arr *p, usize pos, void *v, usize m, usize n) 6 | { 7 | usize len; 8 | uchar *target; 9 | 10 | if (c_arr_ready(p, m, n) < 0) return -1; 11 | len = c_arr_bytes(p); 12 | if (!(target = c_arr_get(p, pos, n))) return -1; 13 | 14 | if (pos) pos = (pos - 1) * n; 15 | m *= n; 16 | if (len > (pos + n)) { 17 | c_mem_cpy(target + m, target, len - pos); 18 | p->n += m; 19 | } else { 20 | p->n += m - n; 21 | } 22 | c_mem_cpy(target, v, m); 23 | p->p[p->n] = 0; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/dyn/idxcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_dyn_idxcat(ctype_arr *p, usize pos, void *v, usize m, usize n) 6 | { 7 | usize len; 8 | uchar *target; 9 | 10 | if (c_dyn_ready(p, m, n) < 0) return -1; 11 | len = c_arr_bytes(p); 12 | if (!(target = c_dyn_alloc(p, pos, n))) return -1; 13 | 14 | if (pos) pos = (pos - 1) * n; 15 | m *= n; 16 | if (len > (pos + n)) { 17 | c_mem_cpy(target + m, target, len - pos); 18 | p->n += m; 19 | } else { 20 | p->n += m - n; 21 | } 22 | c_mem_cpy(target, v, m); 23 | p->p[p->n] = 0; 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /man/c_hsh_rol32.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_ROL32 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_rol32 6 | .Nd rotate left 32-bit unsigned integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_hsh_rol32 "u32 n" "int k" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_rol32 17 | function rotates the unsigned 32-bit integer 18 | .Fa n 19 | left by 20 | .Fa k 21 | bits. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_hsh_rol32 25 | function returns the rotated value. 26 | .Sh SEE ALSO 27 | .Xr c_hsh_rol64 3 , 28 | .Xr c_hsh_ror32 3 , 29 | .Xr c_hsh_ror64 3 30 | -------------------------------------------------------------------------------- /man/c_hsh_rol64.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_ROL64 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_rol64 6 | .Nd rotate left 64-bit unsigned integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u64 13 | .Fn c_hsh_rol64 "u64 n" "int k" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_rol64 17 | function rotates the unsigned 64-bit integer 18 | .Fa n 19 | left by 20 | .Fa k 21 | bits. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_hsh_rol64 25 | function returns the rotated value. 26 | .Sh SEE ALSO 27 | .Xr c_hsh_rol32 3 , 28 | .Xr c_hsh_ror32 3 , 29 | .Xr c_hsh_ror64 3 30 | -------------------------------------------------------------------------------- /man/c_hsh_ror32.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_ROR32 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_ror32 6 | .Nd rotate right 32-bit unsigned integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_hsh_ror32 "u32 n" "int k" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_ror32 17 | function rotates the unsigned 32-bit integer 18 | .Fa n 19 | right by 20 | .Fa k 21 | bits. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_hsh_ror32 25 | function returns the rotated value. 26 | .Sh SEE ALSO 27 | .Xr c_hsh_rol32 3 , 28 | .Xr c_hsh_rol64 3 , 29 | .Xr c_hsh_ror64 3 30 | -------------------------------------------------------------------------------- /man/c_hsh_ror64.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_ROR64 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_ror64 6 | .Nd rotate right 64-bit unsigned integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u64 13 | .Fn c_hsh_ror64 "u64 n" "int k" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_ror64 17 | function rotates the unsigned 64-bit integer 18 | .Fa n 19 | right by 20 | .Fa k 21 | bits. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_hsh_ror64 25 | function returns the rotated value. 26 | .Sh SEE ALSO 27 | .Xr c_hsh_rol32 3 , 28 | .Xr c_hsh_rol64 3 , 29 | .Xr c_hsh_ror32 3 30 | -------------------------------------------------------------------------------- /man/c_ioq_feed.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_FEED 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_feed 6 | .Nd feed queue 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft size 13 | .Fn c_ioq_feed "ctype_ioq *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_feed 17 | function attempts to fill the input queue 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_ioq_feed 22 | function returns the current data size if existent, otherwise it returns the 23 | size of filled data. If the operation function fails \-1 is returned. 24 | .Sh SEE ALSO 25 | .Xr c_ioq_flush 3 26 | -------------------------------------------------------------------------------- /src/std/errstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define ERRBUF (_tertium_syserr ? _tertium_syserr() : errbuf) 5 | 6 | char *(*_tertium_syserr)(void); 7 | static char errbuf[C_IOQ_ERRSIZ]; 8 | 9 | static void 10 | swap(uchar *a, uchar *b) 11 | { 12 | *a ^= *b; 13 | *b ^= *a; 14 | *a ^= *b; 15 | } 16 | 17 | static void 18 | swapn(uchar *a, uchar *b, usize n) 19 | { 20 | for (; n; ++a, ++b, --n) swap(a, b); 21 | } 22 | 23 | void 24 | c_std_errstr(char *s, usize n) 25 | { 26 | swapn((uchar *)s, (uchar *)ERRBUF, C_STD_MIN(C_IOQ_ERRSIZ, n)); 27 | errno = C_ERR_ECSTM; 28 | } 29 | -------------------------------------------------------------------------------- /man/c_utf8_utfrune.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_UTFRUNE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_utfrune 6 | .Nd 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_utf8_utfrune "char *s" "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_utfrune 17 | function searches for the first occurence of the rune 18 | .Fa r 19 | in the string 20 | .Fa s . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_utf8_utfrune 24 | function returns a pointer to the located rune or nil if not found. 25 | .Sh SEE ALSO 26 | .Xr c_utf8_utfrrune 3 27 | -------------------------------------------------------------------------------- /src/nix/iopause.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_nix_iopause(ctype_iopause *p, uint n, ctype_taia *deadline, ctype_taia *stamp) 6 | { 7 | ctype_taia t; 8 | int millisecs; 9 | double d; 10 | uint i; 11 | 12 | if (c_taia_less(deadline, stamp)) { 13 | millisecs = 0; 14 | } else { 15 | t = *stamp; 16 | c_taia_sub(&t, deadline, &t); 17 | if ((d = c_taia_approx(&t)) > 1000.0) 18 | d = 1000.0; 19 | millisecs = d * 1000.0 + 20.0; 20 | } 21 | 22 | for (i = 0; i < n; ++i) 23 | p[i].revents = 0; 24 | 25 | return c_sys_poll(p, n, millisecs); 26 | } 27 | -------------------------------------------------------------------------------- /src/std/putfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_status 5 | c_std_putfile(void *data, char *s, ctype_status (*fn)(void *, char *, usize)) 6 | { 7 | ctype_stat st; 8 | ctype_fd fd; 9 | ctype_status r; 10 | 11 | if (!c_mem_cmp(s, sizeof("") - 1, "")) { 12 | return c_std_putfd(data, C_IOQ_FD0, 0, fn); 13 | } 14 | 15 | if ((fd = c_nix_fdopen2(s, C_NIX_OREAD)) < 0) return -1; 16 | if (c_nix_fdstat(&st, fd) < 0) { 17 | c_nix_fdclose(fd); 18 | return -1; 19 | } 20 | r = c_std_putfd(data, fd, st.size, fn); 21 | c_nix_fdclose(fd); 22 | return r; 23 | } 24 | -------------------------------------------------------------------------------- /man/c_taia_approx.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_APPROX 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_approx 6 | .Nd calculate double-precision approximation 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft double 13 | .Fn c_taia_approx "ctype_taia *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_approx 17 | function calculates a double-precision approximation from the TAI64NA label 18 | .Fa t . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_taia_approx 22 | function returns a double-precision timestamp approximation. 23 | .Sh SEE ALSO 24 | .Xr c_taia_frac 3 25 | -------------------------------------------------------------------------------- /man/c_utf8_utfrrune.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_UTFRRUNE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_utfrrune 6 | .Nd 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_utf8_utfrrune "char *s" "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_utfrrune 17 | function searches for the last occurence of the rune 18 | .Fa r 19 | in the string 20 | .Fa s . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_utf8_utfrrune 24 | function returns a pointer to the located rune or nil if not found. 25 | .Sh SEE ALSO 26 | .Xr c_utf8_utfrrune 3 27 | -------------------------------------------------------------------------------- /man/c_utf8_runelen.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_RUNELEN 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_runelen 6 | .Nd calculate conversion length 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_runelen "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_runelen 17 | function calculates the number of bytes required to convert the rune 18 | .Fa r 19 | into UTF. 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_utf8_runelen 23 | function returns the length required to convert the given rune. 24 | .Sh SEE ALSO 25 | .Xr c_utf8_runenlen 3 26 | -------------------------------------------------------------------------------- /man/c_arr_init.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_INIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_init 6 | .Nd initialize array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_arr_init "ctype_arr *p" "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_init 17 | function initializes the internal buffer of the array 18 | .Fa p 19 | to the buffer 20 | .Fa s 21 | of 22 | .Fa n Ns \-1 23 | bytes in size. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | ctype_arr arr; 27 | char buf[64]; 28 | c_arr_init(&arr, buf, sizeof(buf)); 29 | .Ed 30 | -------------------------------------------------------------------------------- /src/exc/setenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ctype_arr _tertium_exc_env; 5 | 6 | ctype_status 7 | c_exc_setenv(char *s, char *v) 8 | { 9 | ctype_arr e; 10 | ctype_status r; 11 | char *p; 12 | 13 | if (!(s && *s)) { 14 | errno = C_ERR_EINVAL; 15 | return -1; 16 | } 17 | 18 | if ((p = c_str_chr(s, -1, '='))) *p = 0; 19 | 20 | c_mem_set(&e, sizeof(e), 0); 21 | r = v ? c_dyn_fmt(&e, "%s=%s", s, v) : c_dyn_fmt(&e, "%s", s); 22 | if (r < 0) { 23 | c_dyn_free(&e); 24 | return -1; 25 | } 26 | p = c_arr_data(&e); 27 | return c_dyn_cat(&_tertium_exc_env, &p, 1, sizeof(char *)); 28 | } 29 | -------------------------------------------------------------------------------- /man/c_dir_list.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 10 2023 $ 2 | .Dt C_DIR_LIST 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dir_list 6 | .Nd iterate current directory entries 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_dent * 13 | .Fn c_dir_list "ctype_dir *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dir_list 17 | function iterates through the current directory entries in 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_dir_list 22 | function returns a pointer to the next entry, or nil when 23 | there are no more entries. 24 | .Sh SEE ALSO 25 | .Xr c_dir_children 3 , 26 | .Xr c_dir_read 3 27 | -------------------------------------------------------------------------------- /man/c_utf8_runetochar.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_RUNETOCHAR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_runetochar 6 | .Nd convert rune to utf8 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_runetochar "char *s" "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_runetochar 17 | function converts the rune 18 | .Fa r 19 | to the string 20 | .Fa s . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_utf8_runetochar 24 | function retruns the length of the converted rune. 25 | .Sh SEE ALSO 26 | .Xr c_utf8_charntorune 3 , 27 | .Xr c_utf8_chartorune 3 28 | -------------------------------------------------------------------------------- /man/c_adt_kvdel.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ADT_KVDEL 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_adt_kvdel 6 | .Nd delete a key from a key-value tree 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_adt_kvdel "ctype_kvtree *t" "char *k" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_adt_kvdel 17 | function deletes the key 18 | .Fa k 19 | from the key-value tree 20 | .Fa t . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn 24 | function returns 0 if successful; otherwise \-1 is returned, indicating that 25 | the key does not exist. 26 | .Sh SEE ALSO 27 | .Xr c_adt_kvfree 3 28 | -------------------------------------------------------------------------------- /man/c_fmt_print.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_FMT_PRINT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_fmt_print 6 | .Nd print formatted string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_fmt_print "ctype_fmt *p" "char *fmt" "..." 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_fmt_print 17 | function writes a string according to the format 18 | .Fa fmt 19 | using the output function assigned to the formatter 20 | .Fa p . 21 | .Sh RETURN VALUES 22 | .Rv -std 23 | .Sh ERRORS 24 | .Sh SEE ALSO 25 | .Xr c_fmt_fmt 3 , 26 | .Xr c_fmt_nput 3 , 27 | .Xr c_fmt_put 3 , 28 | .Xr c_fmt_vprint 3 29 | -------------------------------------------------------------------------------- /man/c_utf8_fullrune.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_FULLRUNE 3 3 | .Os check string 4 | .Sh NAME 5 | .Nm c_utf8_fullrune 6 | .Nd check rune availability 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_fullrune "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_fullrune 17 | function checks if the string 18 | .Fa s 19 | of length 20 | .Fa n 21 | contains a complete Unicode code point. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_utf8_fullrune 25 | function returns the value 1 if the given string contains a complete rune, 26 | and 0 otherwise. 27 | -------------------------------------------------------------------------------- /man/c_utf8_utfnlen.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_UTFNLEN 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_utfnlen 6 | .Nd calculate string rune length 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_utf8_utfnlen "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_utfnlen 17 | function calculates the number of runes that are represented by 18 | the UTF string 19 | .Fa s 20 | of length 21 | .Fa n 22 | in bytes. 23 | .Sh RETURN VALUES 24 | The 25 | .Fn c_utf8_utfnlen 26 | function returns the found number of runes. 27 | .Sh SEE ALSO 28 | .Xr c_utf8_utflen 3 29 | -------------------------------------------------------------------------------- /man/c_cal_timetai.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CAL_TIMETAI 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cal_timetai 6 | .Nd convert calendar to tai 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_cal_timetai "ctype_tai *t" "ctype_caltime *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the calendar 18 | .Fa p 19 | to the tai timestamp 20 | .Fa t . 21 | .Sh EXAMPLES 22 | .Bd -literal -offset indent 23 | ctype_caltime cd = { .year = 2012, .month = 12, .day = 12 }; 24 | ctype_tai t; 25 | c_cal_timetai(&t, &cd); 26 | .Ed 27 | .Sh SEE ALSO 28 | .Xr c_cal_timeutc 3 29 | -------------------------------------------------------------------------------- /man/c_fmt_vprint.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_FMT_VPRINT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_fmt_print 6 | .Nd print formatted string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_fmt_print "ctype_fmt *p" "char *fmt" "va_list args" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_fmt_print 17 | function writes a string according to the format 18 | .Fa fmt 19 | using the output function assigned to the formatter 20 | .Fa p . 21 | .Sh RETURN VALUES 22 | .Rv -std 23 | .Sh ERRORS 24 | .Sh SEE ALSO 25 | .Xr c_fmt_fmt 3 , 26 | .Xr c_fmt_nput 3 , 27 | .Xr c_fmt_print 3 , 28 | .Xr c_fmt_put 3 29 | -------------------------------------------------------------------------------- /man/c_cal_datefrommjd.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CAL_DATEFROMMJD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cal_datefrommjd 6 | .Nd convert modified Julian day to calendar date 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_cal_datefrommjd "ctype_caldate *p" "long day" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_cal_datefrommjd 17 | function converts the modified Julian 18 | .Fa day 19 | to the calendar date 20 | .Fa p . 21 | .Sh EXAMPLES 22 | .Bd -literal -offset indent 23 | ctype_caldate cd; 24 | c_cal_datefrommjd(&cd, 55555); 25 | .Ed 26 | .Sh SEE ALSO 27 | .Xr c_cal_datemjd 3 28 | -------------------------------------------------------------------------------- /man/c_dyn_shrink.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_DYN_SHRINK 3 | .Os 4 | .Sh NAME 5 | .Nm c_dyn_shrink 6 | .Nd shrink dynamic array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_dyn_shrink "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dyn_shrink 17 | function resizes the internal buffer of the dynamic array 18 | .Fa p 19 | to match the number of initialized bytes, thus releasing any 20 | surplus allocated memory. 21 | .Pp 22 | It should be called after you are done adding objects to the dynamic array, 23 | since the growth heuristics may have over-allocated space. 24 | -------------------------------------------------------------------------------- /man/c_fmt_init.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_FMT_INIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_fmt_init 6 | .Nd initialize formatter 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_fmt_init "ctype_fmt *p" "void *farg" "ctype_fmtopfn func" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_fmt_init 17 | function initializes the formatter 18 | .Fa p 19 | storing the data 20 | .Fa farg 21 | and setting the function 22 | .Fa func 23 | as output function. 24 | .Sh SEE ALSO 25 | .Xr c_fmt_fmt 3 , 26 | .Xr c_fmt_install 3 , 27 | .Xr c_fmt_nput 3 , 28 | .Xr c_fmt_print 3 , 29 | .Xr c_fmt_put 3 , 30 | .Xr c_fmt_vprint 3 31 | -------------------------------------------------------------------------------- /man/c_dir_children.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 10 2023 $ 2 | .Dt C_DIR_CHILDREN 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dir_children 6 | .Nd get subdirectory content 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_dent * 13 | .Fn c_dir_children "ctype_dir *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dir_children 17 | function iterates through the child entries from the current directory in 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_dir_children 22 | function returns a pointer to the next entry, or nil when 23 | there are no more entries. 24 | .Sh SEE ALSO 25 | .Xr c_dir_list 3 , 26 | .Xr c_dir_read 3 27 | -------------------------------------------------------------------------------- /man/c_cal_timeutc.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CAL_TIMEUTC 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cal_timeutc 6 | .Nd convert tai to calendar date 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_cal_timeutc "ctype_caltime *p" "ctype_tai *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function converts the tai timestamp 18 | .Fa t 19 | to the calendar date 20 | .Fa p . 21 | .Sh EXAMPLES 22 | .Bd -literal -offset indent 23 | ctype_tai t; 24 | ctype_caldate cd; 25 | c_tai_now(&t); 26 | c_cal_timeutc(&cd, &t); 27 | .Ed 28 | .Sh SEE ALSO 29 | .Xr c_cal_timetai 3 , 30 | .Xr c_cal_datefrommjd 3 31 | -------------------------------------------------------------------------------- /man/c_taia_frac.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_TAIA_FRAC 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_taia_frac 6 | .Nd calculate double-precision approximation 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft double 13 | .Fn c_taia_frac "ctype_taia *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_taia_frac 17 | function calculates a double-precision approximation to the fraction part 18 | of the TAI64NA label 19 | .Fa t . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_taia_frac 23 | function returns a double-precision approximation to the fraction part of 24 | the given TAI64NA label. 25 | .Sh SEE ALSO 26 | .Xr c_taia_approx 3 27 | -------------------------------------------------------------------------------- /sys/Linux/generic/types.h.in: -------------------------------------------------------------------------------- 1 | typedef unsigned ctype_rune; 2 | typedef int ctype_fd; 3 | typedef int ctype_error; 4 | typedef int ctype_status; 5 | 6 | typedef int (*ctype_cmpfn)(void *, void *); 7 | typedef size (*ctype_iofn)(int, void *, usize); 8 | typedef void *(*ctype_allocfn)(void *, usize, usize); 9 | 10 | typedef struct ctype_iopause ctype_iopause; 11 | typedef struct ctype_uts ctype_utsname; 12 | 13 | struct ctype_iopause { 14 | int fd; 15 | short events; 16 | short revents; 17 | }; 18 | 19 | struct ctype_uts { 20 | char sysname[65]; 21 | char nodename[65]; 22 | char release[65]; 23 | char version[65]; 24 | char machine[65]; 25 | char domainname[65]; 26 | }; 27 | -------------------------------------------------------------------------------- /man/c_rand_u32inc.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_U32INC 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_u32inc 6 | .Nd deterministic pseudo-random number generator 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_rand_u32inc "ctype_rst *p" "u32 n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_u32inc 17 | function generates a pseudo-random number, 18 | uniformly distributed but less than 19 | .Fa n , 20 | determined from the state 21 | .Fa p . 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_rand_u32inc 25 | function returns the generated number. 26 | .Sh SEE ALSO 27 | .Xr c_rand_data 3 , 28 | .Xr c_rand_name 3 29 | -------------------------------------------------------------------------------- /src/hsh/update.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef void (*hfunc)(ctype_hst *, char *); 5 | 6 | void 7 | c_hsh_update(hfunc f, int b, ctype_hst *p, char *data, usize n) 8 | { 9 | usize len; 10 | while (n) { 11 | if (!p->curlen && n >= (uint)b) { 12 | f(p, data); 13 | p->len += b << 3; 14 | data += b; 15 | n -= b; 16 | } else { 17 | len = C_STD_MIN(b - p->curlen, n); 18 | c_mem_cpy(p->buf + p->curlen, data, len); 19 | p->curlen += len; 20 | data += len; 21 | n -= len; 22 | if (p->curlen == (uint)b) { 23 | f(p, (char *)p->buf); 24 | p->len += b << 3; 25 | p->curlen = 0; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/c_utf8_runenlen.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_RUNENLEN 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_runenlen 6 | .Nd calculate conversion length 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_utf8_runenlen "ctype_rune *p" "usize len" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_runenlen 17 | function calculates the number of bytes required to convert the rune string 18 | .Fa r , 19 | of length 20 | .Fa len 21 | into UTF. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_utf8_runenlen 25 | function returns the length required to convert the given string rune. 26 | .Sh SEE ALSO 27 | .Xr c_utf8_runelen 3 28 | -------------------------------------------------------------------------------- /man/c_cdb_free.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CDB_FREE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cdb_free 6 | .Nd free constant database 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_cdb_free "ctype_cdb *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_cdb_free 17 | function releases the resources assigned to the constant database 18 | .Fa p . 19 | If the constant database has already been freed 20 | .Fn c_cdb_free 21 | has no effects. 22 | It does not close the file descriptor. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | c_cdb_free(&c); 26 | c_nix_fdclose(fd); 27 | .Ed 28 | .Sh SEE ALSO 29 | .Xr c_cdb_init 3 30 | -------------------------------------------------------------------------------- /src/adt/kvtraverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "kv.h" 5 | 6 | static ctype_status 7 | traverse(void *t, ctype_status (*func)(char *, void *)) 8 | { 9 | ctype_kvent *p; 10 | struct node *q; 11 | uchar *s; 12 | if ((uintptr)(s = (void *)t) & 1) { 13 | q = (void *)(s - 1); 14 | if (traverse(q->child[0], func) == -1) return -1; 15 | return traverse(q->child[1], func); 16 | } else { 17 | p = (void *)s; 18 | return func(p->k, p->v); 19 | } 20 | return 0; 21 | } 22 | 23 | ctype_status 24 | c_adt_kvtraverse(ctype_kvtree *t, ctype_status (*func)(char *, void *)) 25 | { 26 | if (!t->root) return 0; 27 | return traverse(t->root, func); 28 | } 29 | -------------------------------------------------------------------------------- /man/c_rand_name.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_RAND_NAME 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_rand_name 6 | .Nd random name generator 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_rand_name "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_rand_name 17 | function fills the region 18 | .Fa s 19 | of 20 | .Fa n 21 | bytes in size with random alphanumeric 22 | .Pq Dq A-Za-z0-9 , 23 | slash 24 | .Pq Sq \&- 25 | and underline 26 | .Pq Sq \&_ 27 | characters. 28 | .Sh RETURN VALUES 29 | The 30 | .Fn c_rand_name 31 | function returns a pointer to 32 | .Fa s . 33 | .Sh SEE ALSO 34 | .Xr c_rand_data 3 , 35 | .Xr c_rand_u32 3 36 | -------------------------------------------------------------------------------- /man/c_nix_allrw.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_NIX_ALLRW 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_nix_allrw 6 | .Nd perform full rw operation 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft size 13 | .Fn c_nix_allrw "ctype_iofn op" "ctype_fd fd" "void *p" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_nix_allrw 17 | function copies 18 | .Fa n 19 | bytes from/to the file descriptor 20 | .Fa fd 21 | to/from the buffer 22 | .Fa p 23 | using the function 24 | .Fa op . 25 | .Sh RETURN VALUES 26 | The 27 | .Fn c_nix_allrw 28 | function returns the total number of bytes copied if successful; 29 | otherwise \-1 is returned and 30 | .Va errno 31 | is set to indicate the error. 32 | -------------------------------------------------------------------------------- /man/c_cdb_findstart.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CDB_FINDSTART 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cdb_findstart 6 | .Nd start search position 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_cdb_findstart "ctype_cdb *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function prepares the constant database 18 | .Fa p 19 | to search for the first record under a new key. 20 | .Sh EXAMPLES 21 | .Bd -literal -offset indent 22 | ctype_status 23 | c_cdb_find(ctype_cdb *p, char *k, usize n) 24 | { 25 | c_cdb_findstart(p); 26 | return c_cdb_findnext(p, k, n); 27 | } 28 | .Ed 29 | .Sh SEE ALSO 30 | .Xr c_cdb_find 3 , 31 | .Xr c_cdb_findnext 3 32 | -------------------------------------------------------------------------------- /man/c_dyn_free.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_DYN_FREE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dyn_free 6 | .Nd free dynamic array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_dyn_free "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dyn_free 17 | function releases the memory assigned to the dynamic array 18 | .Fa p . 19 | If the array has already been freed, 20 | .Fa c_dyn_free 21 | has no effects. 22 | .Sh SEE ALSO 23 | .Xr c_arr_trunc 3 24 | .Sh CAVEATS 25 | Is not recommended to free dynamic arrays if they are to be reused soon, 26 | since it has a cost and may result in memory fragmentation; instead, truncate 27 | the array to zero. 28 | -------------------------------------------------------------------------------- /man/c_std_atexit.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_ATEXIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_atexit 6 | .Nd register function to be called on exit 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_std_atexit "void (*func)(void)" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_atexit 17 | function registers the function 18 | .Fa func 19 | to be called at program exit, via 20 | .Xr c_std_exit 3 . 21 | Function so registered are called in LIFO 22 | .Pq Last \&In First Out 23 | order. 24 | .Sh RETURN VALUES 25 | .Rv -std 26 | .Sh ERRORS 27 | .Bl -tag -width Er 28 | .It Bq Er C_ERR_NOMEM 29 | Not enough memory. 30 | .El 31 | .Sh SEE ALSO 32 | .Xr c_std_exit 3 33 | -------------------------------------------------------------------------------- /man/c_utf8_islower.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISLOWER 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_islower 6 | .Nd lower-case rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_islower "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_islower 17 | function tests whether the rune 18 | .Fa r 19 | represents a lower-case letter. 20 | .Pp 21 | Lower-case letter are those in the Unicode category Lowercase Letter 22 | .Pq Ll . 23 | .Sh RETURN VALUES 24 | The 25 | .Fn c_utf8_islower 26 | function returns non-zero if the rune tests true, and zero otherwise. 27 | .Sh SEE ALSO 28 | .Xr c_utf8_istitle 3 , 29 | .Xr c_utf8_isupper 3 30 | -------------------------------------------------------------------------------- /man/c_utf8_isupper.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISUPPER 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_isupper 6 | .Nd upper-case rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_isupper "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_isupper 17 | function tests whether the rune 18 | .Fa r 19 | represents a upper-case letter. 20 | .Pp 21 | Upper-case letter are those in the Unicode category Uppercase Letter 22 | .Pq Lu . 23 | .Sh RETURN VALUES 24 | The 25 | .Fn c_utf8_isupper 26 | function returns non-zero if the rune tests true, and zero otherwise. 27 | .Sh SEE ALSO 28 | .Xr c_utf8_islower 3 , 29 | .Xr c_utf8_istitle 3 30 | -------------------------------------------------------------------------------- /man/c_arr_tofrom.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_TOFROM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_tofrom 6 | .Nd append array to array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_arr_tofrom "ctype_arr *dest" "ctype_arr *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_tofrom 17 | function appends the content from the array 18 | .Fa s 19 | to the array 20 | .Fa dest . 21 | .Sh RETURN VALUES 22 | .Rv -std 23 | .Sh ERRORS 24 | The 25 | .Fn c_arr_tofrom 26 | function may fail and set the external variable 27 | .Va errno 28 | for any of the errors specified for the library function 29 | .Xr c_arr_cat 3 . 30 | .Sh SEE ALSO 31 | .Xr c_arr_cat 3 32 | -------------------------------------------------------------------------------- /man/c_exc_setenv.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 10 2023 $ 2 | .Dt C_EXC_SETENV 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_exc_setenv 6 | .Nd set environment 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_exc_setenv "char *s" "char *v" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_exc_setenv 17 | function sets the environment variable 18 | .Fa s 19 | to the value 20 | .Fa v . 21 | .Sh RETURN VALUES 22 | .Rv -std 23 | .Sh ERRORS 24 | The 25 | .Fn c_dyn_ready 26 | function may fail and set the external variable 27 | .Va errno 28 | for any of the errors specified for the library function 29 | .Xr c_std_alloc 3 . 30 | .Sh SEE ALSO 31 | .Xr c_exc_run 3 , 32 | .Xr c_exc_runenv 3 33 | -------------------------------------------------------------------------------- /man/c_utf8_istitle.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISTITLUE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_istitle 6 | .Nd title-case rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_islower "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_islower 17 | function tests whether the rune 18 | .Fa r 19 | represents a title-case letter. 20 | .Pp 21 | Title-case letter are those in the Unicode category Titlecase Letter 22 | .Pq Lt . 23 | .Sh RETURN VALUES 24 | The 25 | .Fn c_utf8_islower 26 | function returns non-zero if the rune tests true, and zero otherwise. 27 | .Sh SEE ALSO 28 | .Xr c_utf8_islower 3 , 29 | .Xr c_utf8_isupper 3 30 | -------------------------------------------------------------------------------- /src/dyn/ready.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define GFACT 1.618 5 | 6 | ctype_status 7 | c_dyn_ready(ctype_arr *p, usize m, usize n) 8 | { 9 | usize a; 10 | void *tmp; 11 | 12 | if (C_STD_OVERFLOWM(usize, m, n)) { 13 | errno = C_ERR_EOVERFLOW; 14 | return -1; 15 | } 16 | m = (m * n) + n; 17 | if (p->a) { 18 | if (m > c_arr_avail(p)) { 19 | a = p->a; 20 | while (m > (a - p->n)) a *= GFACT; 21 | if (!(tmp = c_std_realloc(p->p, a, sizeof(uchar)))) 22 | return -1; 23 | p->p = tmp; 24 | p->a = a; 25 | } 26 | } else { 27 | if (!(p->p = c_std_alloc((p->a = m * GFACT), sizeof(uchar)))) 28 | return -1; 29 | } 30 | c_mem_set(p->p + p->n, n, 0); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /src/hsh/putfile.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct hash { 5 | ctype_hst *st; 6 | ctype_hmd *md; 7 | }; 8 | 9 | static ctype_status 10 | event(void *data, char *s, usize n) 11 | { 12 | struct hash *h; 13 | h = data; 14 | h->md->update(h->st, s, n); 15 | return 0; 16 | } 17 | 18 | ctype_status 19 | c_hsh_putfd(ctype_hst *h, ctype_hmd *md, ctype_fd fd, usize n) 20 | { 21 | struct hash hash; 22 | hash.st = h; 23 | hash.md = md; 24 | return c_std_putfd(&hash, fd, n, &event); 25 | 26 | } 27 | 28 | ctype_status 29 | c_hsh_putfile(ctype_hst *h, ctype_hmd *md, char *s) 30 | { 31 | struct hash hash; 32 | hash.st = h; 33 | hash.md = md; 34 | return c_std_putfile(&hash, s, &event); 35 | } 36 | -------------------------------------------------------------------------------- /man/c_utf8_isdigit.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISDIGIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_isdigit 6 | .Nd digit rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_isdigit "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_isdigit 17 | function tests whether the rune 18 | .Fa r 19 | represents a numeric character. 20 | .Pp 21 | Numeric characters are those in the Unicode category Number 22 | and Decimal Digit 23 | .Pq Nd . 24 | .Sh RETURN VALUES 25 | The 26 | .Fn c_utf8_isdigit 27 | function returns non-zero if the rune tests true, and zero otherwise. 28 | .Sh SEE ALSO 29 | .Xr c_utf8_isalnum 3 , 30 | .Xr c_utf8_isxdigit 3 31 | -------------------------------------------------------------------------------- /man/c_ioq_putfile.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_PUTFILE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_putfile 6 | .Nd queue file 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_putfile "ctype_ioq *p" "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_putfile 17 | function reads the file 18 | .Fa s 19 | appending the input to the queue 20 | .Fa p . 21 | If the number of bytes to append exceeds the available space in the queue, 22 | .Fn c_ioq_putfile 23 | flushes the data until it is enough to fit. 24 | .Sh RETURN VALUES 25 | .Rv -std 26 | .Sh SEE ALSO 27 | .Xr c_ioq_fmt 3 , 28 | .Xr c_ioq_nput 3 , 29 | .Xr c_ioq_put 3 , 30 | .Xr c_ioq_putfd 3 , 31 | .Xr c_ioq_vfmt 3 32 | -------------------------------------------------------------------------------- /man/c_str_rtrim.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_STR_RTRIM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_str_ltrim 6 | .Nd right trim a string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_str_rtrim "char *str" "usize n" "char *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_str_ltrim 17 | function replaces any of the characters in the string 18 | .Fa t 19 | found at the end of the string 20 | .Fa str 21 | with a nul-character 22 | .Pq Sq \e0 . 23 | It goes no further than 24 | .Fa n 25 | bytes . 26 | .Sh RETURN VALUES 27 | The 28 | .Fn c_str_rtrim 29 | function returns a pointer to the string 30 | .Fa str . 31 | .Sh SEE ALSO 32 | .Xr c_str_ltrim 3 , 33 | .Xr c_str_trim 3 34 | -------------------------------------------------------------------------------- /man/c_arr_data.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_DATA 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_data 6 | .Nd retrieve buffer from array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_arr_data "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_data 17 | function returns a pointer to the internal buffer from the array 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_arr_data 22 | function returns a pointer to the internal buffer from the given array. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | void *p = c_arr_data(&arr); 26 | c_ioq_fmt(ioq1, "Buffer Address: %p", p); 27 | c_ioq_flush(ioq1); 28 | .Ed 29 | .Sh SEE ALSO 30 | .Xr c_arr_get 3 31 | -------------------------------------------------------------------------------- /man/c_ioq_put.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_PUT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_put 6 | .Nd queue string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_put "ctype_ioq *p" "char s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_put 17 | function appends the string 18 | .Fa s 19 | to the output queue 20 | .Fa p . 21 | If the number of bytes to append exceeds the available space in the queue, 22 | .Fn c_ioq_put 23 | flushes the data until it is enough to fit. 24 | .Sh RETURN VALUES 25 | .Rv -std 26 | .Sh SEE ALSO 27 | .Xr c_ioq_flush 3 , 28 | .Xr c_ioq_fmt 3 , 29 | .Xr c_ioq_put 3 , 30 | .Xr c_ioq_putfd 3 , 31 | .Xr c_ioq_putfile 3 32 | .Xr c_ioq_vfmt 3 33 | -------------------------------------------------------------------------------- /man/c_uint_16pack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_16PACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_16pack 6 | .Nd store unsigned little-endian 16-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_16pack "char *s" "u16 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_16pack 17 | function portably stores the 16-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in little-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_16pack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u16)]; 29 | c_uint_16pack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_16bigpack 3 33 | -------------------------------------------------------------------------------- /man/c_uint_32pack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_32PACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_32pack 6 | .Nd store unsigned little-endian 32-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_32pack "char *s" "u32 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_32pack 17 | function portably stores the 32-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in little-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_32pack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u32)]; 29 | c_uint_32pack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_32bigpack 3 33 | -------------------------------------------------------------------------------- /man/c_uint_64pack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_64PACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_64pack 6 | .Nd store unsigned little-endian 64-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_64pack "char *s" "u64 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_64pack 17 | function portably stores the 64-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in little-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_64pack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u64)]; 29 | c_uint_64pack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_64bigpack 3 33 | -------------------------------------------------------------------------------- /man/c_nix_rmpath.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_NIX_RMPATH 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_nix_rmpath 6 | .Nd one line about what it does 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_nix_rmpath "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_nix_rmpath 17 | function removes the directory path 18 | .Fa dir , 19 | removing from the last component to the first empty directories. 20 | .Sh RETURN VALUES 21 | .Rv -std 22 | .Sh ERRORS 23 | The 24 | .Fn c_nix_rmtemp 25 | function may fail and set the external variable 26 | .Va errno 27 | for any of the errors specified for the library function 28 | .Xr c_nix_rmdir 3 . 29 | .Sh SEE ALSO 30 | .Xr c_nix_rmdir 3 , 31 | .Xr c_nix_mkpath 3 32 | -------------------------------------------------------------------------------- /man/c_ioq_getln.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_GETLN 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_getln 6 | .Nd get queue delimited data 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_getln "ctype_arr *b" "ctype_ioq *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_getln 17 | function reads from the input queue 18 | .Fa p 19 | until it encounters a line feed character 20 | .Pq Sq \en , 21 | storing the input in the dynamic array 22 | .Fa b . 23 | It will block if the queue is empty or smaller than needed, 24 | waiting for more data to arrive via 25 | .Xr c_ioq_feed 3 26 | .Sh RETURN VALUES 27 | .Rv -std 28 | .Sh SEE ALSO 29 | .Xr c_ioq_feed 3 , 30 | .Xr c_ioq_get 3 , 31 | .Xr c_ioq_getln 3 32 | -------------------------------------------------------------------------------- /man/c_mem_set.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_MEM_SET 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_mem_set 6 | .Nd set bytes in memory 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_mem_set "void *v" "usize n" "int c" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_mem_set 17 | function fills the first 18 | .Fa n 19 | bytes of the memory area 20 | .Fa v 21 | with the byte 22 | .Fa c 23 | .Pq Li uchar . 24 | It is guaranteed not to be optimized away by the compiler. 25 | .Sh RETURN VALUES 26 | The 27 | .Fn c_mem_set 28 | function returns a pointer to the memory area 29 | .Fa v . 30 | .Sh EXAMPLES 31 | .Bd -literal -offset indent 32 | char buf[32]; 33 | c_mem_set(buf, sizeof(buf), 0); 34 | .Ed 35 | -------------------------------------------------------------------------------- /man/c_str_ltrim.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_STR_LTRIM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_str_ltrim 6 | .Nd left trim a string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_str_ltrim "char *str" "usize n" "char *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_str_ltrim 17 | function replaces any of the characters in the string 18 | .Fa t 19 | found at the start of the string 20 | .Fa str 21 | with a nul-character 22 | .Pq Sq \e0 . 23 | It goes no further than 24 | .Fa n 25 | bytes . 26 | .Sh RETURN VALUES 27 | The 28 | .Fn c_str_ltrim 29 | function returns a pointer to the first character after the trimmed part. 30 | .Sh SEE ALSO 31 | .Xr c_str_rtrim 3 , 32 | .Xr c_str_trim 3 33 | -------------------------------------------------------------------------------- /man/c_uint_16bigpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_16BIGPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_16bigpack 6 | .Nd store unsigned big-endian 16-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_16bigpack "char *s" "u16 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_16bigpack 17 | function portably stores the 16-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in big-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_16bigpack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u16)]; 29 | c_uint_16bigpack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_16pack 3 33 | -------------------------------------------------------------------------------- /man/c_uint_32bigpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_32BIGPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_32bigpack 6 | .Nd store unsigned big-endian 32-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_32bigpack "char *s" "u32 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_32bigpack 17 | function portably stores the 32-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in big-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_32bigpack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u32)]; 29 | c_uint_32bigpack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_32pack 3 33 | -------------------------------------------------------------------------------- /man/c_uint_64bigpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_64BIGPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_64bigpack 6 | .Nd store unsigned big-endian 64-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_uint_64bigpack "char *s" "u64 u" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_64bigpack 17 | function portably stores the 64-bit integer 18 | .Fa u 19 | to 20 | .Fa s 21 | in big-endian byte order. 22 | .Sh RETURN VALUES 23 | The 24 | .Fn c_uint_64bigpack 25 | function returns a pointer to the given buffer. 26 | .Sh EXAMPLES 27 | .Bd -literal -offset indent 28 | char buf[sizeof(u64)]; 29 | c_uint_64bigpack(buf, 31); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_uint_64pack 3 33 | -------------------------------------------------------------------------------- /man/c_gen_dirname.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_GEN_DIRNAME 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_gen_dirname 6 | .Nd extract the directory portion of a pathname 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_gen_dirname "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_gen_dirname 17 | function searches for the parent directory of the pathname 18 | .Fa s . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_gen_dirname 22 | function returns a pointer to the parent directory of the given pathname. 23 | If the pathname is a nil pointer, the string empty, or contains no slashes 24 | .Pq Sq / 25 | a pointer to the string 26 | .Dq \&. 27 | is returned. 28 | .Sh SEE ALSO 29 | .Xr c_gen_basename 3 30 | -------------------------------------------------------------------------------- /man/c_std_strerror.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_STRERROR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_strerror 6 | .Nd get error message string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_std_strerror "int e" "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_strerror 17 | function maps the error number 18 | .Fa e 19 | to an error message string, the result is stored in the buffer 20 | .Fa s 21 | of 22 | .Fa n 23 | bytes in size. 24 | If the buffer is smaller than the error message it is truncated to fit it. 25 | .Sh RETURN VALUES 26 | The 27 | .Fn c_std_strerror 28 | function returns a pointer to the given buffer. 29 | .Sh SEE ALSO 30 | .Xr c_std_errstr 3 , 31 | .Xr c_std_werrstr 3 32 | -------------------------------------------------------------------------------- /man/c_str_trim.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_STR_TRIM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_str_ltrim 6 | .Nd trim a string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_str_trim "char *str" "usize n" "char *t" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_str_ltrim 17 | function replaces any of the characters in the string 18 | .Fa t 19 | found at the start and the end of the string 20 | .Fa str 21 | with a nul-character 22 | .Pq Sq \e0 . 23 | It goes no further than 24 | .Fa n 25 | bytes . 26 | .Sh RETURN VALUES 27 | The 28 | .Fn c_str_trim 29 | function returns a pointer to the first character after the trimmed part. 30 | .Sh SEE ALSO 31 | .Xr c_str_ltrim 3 , 32 | .Xr c_str_trim 3 33 | -------------------------------------------------------------------------------- /man/c_adt_lpop.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt c_adt_lpop 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_adt_lpop 6 | .Nd pop node from list 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_node * 13 | .Fn c_adt_lpop "ctype_node **sp" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_adt_lpop 17 | function removes the last node from the linked list 18 | .Fa sp . 19 | It adjusts the list so that the new last node becomes the tail. 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_adt_lpop 23 | function returns a pointer to the removed node, or nil if the list is empty. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | c_adt_lfree(c_adt_lpop(&tail)); 27 | .Ed 28 | .Sh SEE ALSO 29 | .Xr c_adt_lfree 3 , 30 | .Xr c_adt_ltpop 3 31 | -------------------------------------------------------------------------------- /man/c_cal_datemjd.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_CAL_DATEMJD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_cal_datemjd 6 | .Nd calculate the modified Julian day 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft long 13 | .Fn c_cal_datemjd "ctype_caldate *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn 17 | function calculates the modified Julian day number corresponding to the date 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn 22 | function returns the modified Julian day number for the given date. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | ctype_caldate cd; 26 | cd.year = 2012 27 | cd.month = 12 28 | cd.day = 12 29 | long mjd = c_cal_datemjd(&cd); 30 | .Ed 31 | .Sh SEE ALSO 32 | .Xr c_cal_frommjd 3 33 | -------------------------------------------------------------------------------- /man/c_utf8_isspace.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISSPACE 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_isspace 6 | .Nd space rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_isspace "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_isspace 17 | function tests whether the rune 18 | .Fa r 19 | represents a space character. 20 | .Pp 21 | Space characters are those in the Unicode categories Space Separator 22 | .Pq Zs , 23 | Line Separator 24 | .Pq Zl , 25 | and Paragraph Separator 26 | .Pq Zp . 27 | .Sh RETURN VALUES 28 | The 29 | .Fn c_utf8_isspace 30 | function returns non-zero if the rune tests true, and zero otherwise. 31 | .Sh SEE ALSO 32 | .Xr c_utf8_isgraph 3 33 | -------------------------------------------------------------------------------- /man/c_adt_ltpop.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt c_adt_ltpop 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_adt_ltpop 6 | .Nd pop node from list 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_node * 13 | .Fn c_adt_ltpop "ctype_node **sp" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_adt_ltpop 17 | function removes the first node from the linked list 18 | .Fa sp . 19 | It adjusts the list so that the new first node becomes the head. 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_adt_ltpop 23 | function returns a pointer to the removed node, or nil if the list is empty. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | c_adt_lfree(c_adt_ltpop(&tail)); 27 | .Ed 28 | .Sh SEE ALSO 29 | .Xr c_adt_lfree 3 , 30 | .Xr c_adt_lpop 3 31 | -------------------------------------------------------------------------------- /man/c_std_exit.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_EXIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_exit 6 | .Nd exit program 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void 13 | .Fn c_std_exit "ctype_status status" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_exit 17 | function terminates a process. 18 | .Pp 19 | Before termination it performs the following functions in the order listed: 20 | .Bl -enum -offset indent 21 | .It 22 | Call functions registered with the 23 | .Xr c_std_atexit 3 24 | function. 25 | .It 26 | Flush all open output streams. 27 | .El 28 | .Pp 29 | Following this, 30 | .Fn c_std_exit 31 | calls 32 | .Xr c_sys_exit 2 33 | passing the 34 | .Fa status 35 | as exit code. 36 | .Sh SEE ALSO 37 | .Xr c_std_atexit 3 38 | -------------------------------------------------------------------------------- /man/c_gen_basename.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_GEN_BASENAME 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_gen_basename 6 | .Nd extract the base portion of a pathname 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft char * 13 | .Fn c_gen_basename "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_gen_basename 17 | function searches for the last component from the pathname 18 | .Fa s 19 | deleting any trailing slashes 20 | .Pq Sq / . 21 | .Sh RETURN VALUES 22 | The 23 | .Fn c_gen_basename 24 | function returns a pointer to the last component from the given pathname. 25 | If the pathname is a nil pointer or the string empty, 26 | a pointer to the string 27 | .Dq \&. 28 | is returned. 29 | .Sh SEE ALSO 30 | .Xr c_gen_dirname 3 31 | -------------------------------------------------------------------------------- /man/c_utf8_isblank.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISBLANK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_isblank 6 | .Nd blank rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_isblank "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_isblank 17 | function tests whether the rune 18 | .Fa r 19 | represents a blank character. 20 | .Pp 21 | Blank characters are those in the Unicode category Paragraph Separator 22 | .Pq Zs , 23 | along with horizontal tabulation 24 | .Pq Sq \et . 25 | .Sh RETURN VALUES 26 | The 27 | .Fn c_utf8_isblank 28 | function returns non-zero if the rune tests true, and zero otherwise. 29 | .Sh SEE ALSO 30 | .Xr c_utf8_iscntrl 3 , 31 | .Xr c_utf8_isgraph 3 32 | -------------------------------------------------------------------------------- /man/c_ioq_nput.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_NPUT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_nput 6 | .Nd queue string 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_nput "ctype_ioq *p" "char s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_nput 17 | function appends the string 18 | .Fa s 19 | of 20 | .Fa n 21 | bytes in size to the output queue 22 | .Fa p . 23 | If the number of bytes to append exceeds the available space in the queue, 24 | .Fn c_ioq_nput 25 | flushes the data until it is enough to fit. 26 | .Sh RETURN VALUES 27 | .Rv -std 28 | .Sh SEE ALSO 29 | .Xr c_ioq_flush 3 , 30 | .Xr c_ioq_fmt 3 , 31 | .Xr c_ioq_put 3 , 32 | .Xr c_ioq_putfd 3 , 33 | .Xr c_ioq_putfile 3 , 34 | .Xr c_ioq_vfmt 3 35 | -------------------------------------------------------------------------------- /man/c_uint_16unpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_16UNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_16unpack 6 | .Nd read little-endian 16-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u16 13 | .Fn c_uint_16unpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_16unpack 17 | function portably reads a 16-bit unsigned integer as stored on a little-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_16unpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u16)]; 27 | /* fill buf with number */ 28 | u16 x = c_uint_16unpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_16bigunpack 3 32 | -------------------------------------------------------------------------------- /man/c_uint_32unpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_32UNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_32unpack 6 | .Nd read little-endian 32-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_uint_32unpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_32unpack 17 | function portably reads a 32-bit unsigned integer as stored on a little-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_32unpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u32)]; 27 | /* fill buf with number */ 28 | u32 x = c_uint_32unpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_32bigunpack 3 32 | -------------------------------------------------------------------------------- /man/c_uint_64unpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_64UNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_64unpack 6 | .Nd read little-endian 64-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u64 13 | .Fn c_uint_64unpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_64unpack 17 | function portably reads a 64-bit unsigned integer as stored on a little-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_64unpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u64)]; 27 | /* fill buf with number */ 28 | u64 x = c_uint_64unpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_64bigunpack 3 32 | -------------------------------------------------------------------------------- /src/exc/vsplit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void * 5 | c_exc_vsplit(char *prog, va_list ap) 6 | { 7 | usize len; 8 | int i, n; 9 | char *s; 10 | char **av; 11 | va_list tmp; 12 | 13 | va_copy(tmp, ap); 14 | for (n = 1; va_arg(tmp, char *); ++n) ; 15 | va_end(tmp); 16 | 17 | len = 1; 18 | for (s = prog; *s; ++s) { 19 | if (*s == ' ') ++n; 20 | ++len; 21 | } 22 | 23 | s = c_std_alloc(len + ((n + 1) * sizeof(void *)) + 1, sizeof(uchar)); 24 | if (!s) return nil; 25 | c_mem_cpy(s, prog, len); 26 | av = (void *)(s + len); 27 | 28 | i = 1; 29 | av[0] = s; 30 | for (; *s; ++s) { 31 | if (*s == ' ') { 32 | *s++ = 0; 33 | av[i++] = s; 34 | } 35 | } 36 | for (; i <= n; ++i) av[i] = va_arg(ap, char *); 37 | return av; 38 | } 39 | -------------------------------------------------------------------------------- /src/cal/datemjd.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static uint tmon[] = { 0, 31, 61, 92, 122, 153, 184, 214, 245, 275, 306, 337 }; 5 | 6 | long 7 | c_cal_datemjd(ctype_caldate *p) 8 | { 9 | long d, m, y; 10 | 11 | y = (p->year % 400); 12 | m = p->month - 1; 13 | d = (p->day - 678882L) + (p->year / 400) * 146097L; 14 | 15 | if (m >= 2) { 16 | m -= 2; 17 | } else { 18 | m += 10; 19 | --y; 20 | } 21 | y += (m / 12); 22 | if ((m %= 12) < 0) { 23 | m += 12; 24 | --y; 25 | } 26 | 27 | d += tmon[m] + ((y / 400) * 146097L); 28 | if ((y %= 400) < 0) { 29 | y += 400; 30 | d -= 146097L; 31 | } 32 | 33 | d += (y & 3) * 365; 34 | y >>= 2; 35 | 36 | d += (y % 25) * 1461L; 37 | y /= 25; 38 | 39 | d += (y & 3) * 36524; 40 | return d; 41 | } 42 | -------------------------------------------------------------------------------- /man/c_mem_cpy.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_MEM_CPY 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_mem_cpy 6 | .Nd copy memory area 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_mem_cpy "void *d" "usize n" "void *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_mem_cpy 17 | function copies 18 | .Fa n 19 | bytes from memory area 20 | .Fa s 21 | to memory area 22 | .Fa d . 23 | The memory areas may overlap. 24 | .Sh RETURN VALUES 25 | The 26 | .Fn c_mem_cpy 27 | function returns a pointer to 28 | .Fa d . 29 | .Sh EXAMPLES 30 | .Bd -literal -offset indent 31 | char buf[16]; 32 | c_mem_cpy(buf, sizeof(buf), "Hello, World\en\e0"); 33 | c_ioq_put(ioq1, buf); 34 | c_ioq_flush(ioq1); 35 | .Ed 36 | .Sh SEE ALSO 37 | .Xr c_mem_ccpy 3 38 | -------------------------------------------------------------------------------- /man/c_uint_16bigunpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_16BIGUNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_16bigunpack 6 | .Nd read big-endian 16-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u16 13 | .Fn c_uint_16bigunpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_16bigunpack 17 | function portably reads a 16-bit unsigned integer as stored on a big-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_16bigunpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u16)]; 27 | /* fill buf with number */ 28 | u16 x = c_uint_16bigunpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_16unpack 3 32 | -------------------------------------------------------------------------------- /man/c_uint_32bigunpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_32BIGUNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_32bigunpack 6 | .Nd read big-endian 32-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u32 13 | .Fn c_uint_32bigunpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_32bigunpack 17 | function portably reads a 32-bit unsigned integer as stored on a big-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_32bigunpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u32)]; 27 | /* fill buf with number */ 28 | u32 x = c_uint_32bigunpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_32unpack 3 32 | -------------------------------------------------------------------------------- /man/c_uint_64bigunpack.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UINT_64BIGUNPACK 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_uint_64bigunpack 6 | .Nd read big-endian 64-bit integer 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft u64 13 | .Fn c_uint_64bigunpack "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_uint_64bigunpack 17 | function portably reads a 64-bit unsigned integer as stored on a big-endian 18 | architecture from 19 | .Fa s . 20 | .Sh RETURN VALUES 21 | The 22 | .Fn c_uint_64bigunpack 23 | function returns the read unsigned integer. 24 | .Sh EXAMPLES 25 | .Bd -literal -offset indent 26 | char buf[sizeof(u64)]; 27 | /* fill buf with number */ 28 | u64 x = c_uint_64bigunpack(buf); 29 | .Ed 30 | .Sh SEE ALSO 31 | .Xr c_uint_64unpack 3 32 | -------------------------------------------------------------------------------- /src/adt/kvfree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "kv.h" 5 | 6 | /* XXX */ 7 | static void 8 | alignfree(void *p) 9 | { 10 | c_std_free_(((void **)p)[-1]); 11 | } 12 | 13 | static void 14 | traverse(void *t, void (*freeobj)(void *)) 15 | { 16 | ctype_kvent *p; 17 | struct node *q; 18 | uchar *s; 19 | if ((uintptr)(s = t) & 1) { 20 | q = (void *)(s - 1); 21 | traverse(q->child[0], freeobj); 22 | traverse(q->child[1], freeobj); 23 | alignfree(q); 24 | } else { 25 | p = (void *)s; 26 | if (freeobj) freeobj(p->v); 27 | c_std_free(p->k); 28 | alignfree(p); 29 | } 30 | } 31 | 32 | void 33 | c_adt_kvfree(ctype_kvtree *t, void (*freeobj)(void *)) 34 | { 35 | if (!t->root) return; 36 | traverse(t->root, freeobj); 37 | t->root = nil; 38 | } 39 | -------------------------------------------------------------------------------- /man/c_arr_bytes.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_BYTES 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_bytes 6 | .Nd calculate used memory in array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_arr_bytes "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_bytes 17 | function calculates the used memory in the array 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_arr_bytes 22 | function returns the number of initialized bytes in the given array. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | usize n = c_arr_len(&arr, sizeof(int)); 26 | c_ioq_fmt(ioq1, "Used Memory: %llu\en", n); 27 | c_ioq_flush(ioq1); 28 | .Ed 29 | .Sh SEE ALSO 30 | .Xr c_arr_avail 3 , 31 | .Xr c_arr_len 3 , 32 | .Xr c_arr_total 3 33 | -------------------------------------------------------------------------------- /man/c_hsh_putfile.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_HSH_PUTFD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_hsh_putfd 6 | .Nd hash file 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_hsh_putfd "ctype_hst *hs" "ctype_hmd *p" "char *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_hsh_putfd 17 | function reads the file descriptor 18 | .Fa s 19 | then hashes it with the algorithm 20 | .Fa p 21 | storing the result in the hash structure 22 | .Fa hs . 23 | .Sh RETURN VALUES 24 | .Rv -std 25 | .Sh ERRORS 26 | The 27 | .Fn c_hsh_putfile 28 | function may fail and set the external variable 29 | .Va errno 30 | for any of the errors specified for the library function 31 | .Xr c_hsh_putfd 3 . 32 | .Sh SEE ALSO 33 | .Xr c_hsh_putfd 3 , 34 | .Xr c_hsh_str 3 35 | -------------------------------------------------------------------------------- /man/c_ioq_get.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_GET 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_get 6 | .Nd get queue data 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft size 13 | .Fn c_ioq_get "char *b" "usize n" "ctype_ioq *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_get 17 | function copies upto 18 | .Fa n 19 | bytes of data from the input queue 20 | .Fa p 21 | to the buffer 22 | .Fa b . 23 | It will block if the queue is empty or smaller than needed, 24 | waiting for more data to arrive via 25 | .Xr c_ioq_feed 3 . 26 | .Sh RETURN VALUES 27 | The 28 | .Fn c_ioq_get 29 | function returns the amount of bytes copied if successful; 30 | otherwise \-1 is returned. 31 | .Sh SEE ALSO 32 | .Xr c_ioq_feed 3 , 33 | .Xr c_ioq_getdelim 3 , 34 | .Xr c_ioq_getln 3 35 | -------------------------------------------------------------------------------- /man/c_ioq_putfd.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_PUTFD 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_putfd 6 | .Nd queue file descriptor 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_putfd "ctype_ioq *p" "ctype_fd fd" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_putfd 17 | function reads the file descriptor 18 | .Fa fd 19 | of 20 | .Fa n 21 | bytes in size, appending the input to the queue 22 | .Fa p . 23 | If the number of bytes to append exceeds the available space in the queue, 24 | .Fn c_ioq_putfd 25 | flushes the data until it is enough to fit. 26 | .Sh RETURN VALUES 27 | .Rv -std 28 | .Sh SEE ALSO 29 | .Xr c_ioq_fmt 3 , 30 | .Xr c_ioq_nput 3 , 31 | .Xr c_ioq_put 3 , 32 | .Xr c_ioq_putfile 3 , 33 | .Xr c_ioq_vfmt 3 34 | -------------------------------------------------------------------------------- /man/c_nix_mktemp.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_NIX_MKTEMP 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_nix_mktemp 6 | .Nd create directory path 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_nix_mktemp "char *s" "usize n" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_nix_mktemp 17 | function takes the filename template 18 | .Fa s 19 | and overwrites part of it to create a unique file. 20 | The template may be any filename with 21 | .Ql X Ns s 22 | appended to it. 23 | .Sh RETURN VALUES 24 | .Rv -std 25 | .Sh ERRORS 26 | The 27 | .Fn c_nix_mktemp 28 | function may fail and set the external variable 29 | .Va errno 30 | for any of the errors specified for the library function 31 | .Xr c_nix_fdopen3 3 . 32 | .Sh SEE ALSO 33 | .Xr c_nix_mktemp 3 34 | -------------------------------------------------------------------------------- /src/cdb/mkaddend.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct hp { 5 | u32 h; 6 | u32 p; 7 | }; 8 | 9 | ctype_status 10 | c_cdb_mkaddend(ctype_cdbmk *p, usize klen, usize dlen, u64 h) 11 | { 12 | struct hp hp; 13 | usize newoff; 14 | 15 | hp.h = (u32)h; 16 | hp.p = p->off; 17 | if (c_dyn_cat(&p->hplist, &hp, 1, sizeof(hp)) < 0) 18 | return -1; 19 | 20 | newoff = 8; 21 | if (C_STD_OVERFLOWA(usize, newoff, klen)) { 22 | errno = C_ERR_ENOMEM; 23 | return -1; 24 | } 25 | newoff += dlen; 26 | if (C_STD_OVERFLOWA(usize, newoff, dlen)) { 27 | errno = C_ERR_ENOMEM; 28 | return -1; 29 | } 30 | newoff += klen; 31 | if (C_STD_OVERFLOWA(u32, p->off, newoff)) { 32 | errno = C_ERR_ENOMEM; 33 | return -1; 34 | } 35 | p->off += newoff; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /man/c_utf8_isxdigit.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_UTF8_ISXDIGIT 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_utf8_isxdigit 6 | .Nd hexadecimal-digit rune test 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft int 13 | .Fn c_utf8_isdigit "ctype_rune r" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_utf8_isdigit 17 | function tests whether the rune 18 | .Fa r 19 | represents a hexadecimal digit character. 20 | .Pp 21 | Hexadecimal digits are those in the Unicode category Number and 22 | Decimal Digit 23 | .Pq Nd , 24 | along with the letters A-F and a-f. 25 | .Sh RETURN VALUES 26 | The 27 | .Fn c_utf8_isxdigit 28 | function returns non-zero if the rune tests true, and zero otherwise. 29 | .Sh SEE ALSO 30 | .Xr c_utf8_isalnum 3 , 31 | .Xr c_utf8_isdigit 3 32 | -------------------------------------------------------------------------------- /man/c_arr_total.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_TOTAL 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_total 6 | .Nd retrieve the buffer size from array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_arr_total "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_total 17 | function returns the internal buffer size, in bytes, from the array 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_arr_total 22 | function returns the number of allocated bytes in the given array. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | usize n = c_arr_total(&arr); 26 | c_ioq_fmt(ioq1, "Total Memory: %llu\en", n); 27 | c_ioq_flush(ioq1); 28 | .Ed 29 | .Sh SEE ALSO 30 | .Xr c_arr_avail 3 , 31 | .Xr c_arr_bytes 3 , 32 | .Xr c_arr_len 3 33 | -------------------------------------------------------------------------------- /man/c_ioq_getdelim.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_IOQ_GETDELIM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_ioq_getdelim 6 | .Nd get queue delimited data 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_ioq_getdelim "ctype_arr *b" "ctype_ioq *p" "char *delim" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_ioq_getdelim 17 | function reads from the input queue 18 | .Fa p 19 | until it encounters a character matching any of the delimiters 20 | .Fa delim , 21 | storing the input in the dynamic array 22 | .Fa b . 23 | It will block if the queue is empty or smaller than needed, 24 | waiting for more data to arrive via 25 | .Xr c_ioq_feed 3 26 | .Sh RETURN VALUES 27 | .Rv -std 28 | .Sh SEE ALSO 29 | .Xr c_ioq_feed 3 , 30 | .Xr c_ioq_get 3 , 31 | .Xr c_ioq_getln 3 32 | -------------------------------------------------------------------------------- /man/c_mem_chr.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_MEM_CHR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_mem_chr 6 | .Nd find byte in memory 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_mem_chr "void *v" "usize n" "int c" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_mem_chr 17 | function locates the first occurence of 18 | .Fa c 19 | .Pq Li uchar 20 | in the initial 21 | .Fa n 22 | bytes of 23 | .Fa v . 24 | .Sh RETURN VALUES 25 | The 26 | .Fn c_mem_chr 27 | function returns a pointer to the byte located, 28 | or nil if the byte is not found. 29 | .Sh EXAMPLES 30 | .Bd -literal -offset indent 31 | char path[] = "/tmp/file.ext"; 32 | char *s = c_mem_chr(path, sizeof(path), '.'); 33 | *s = '\e0'; 34 | .Ed 35 | .Sh SEE ALSO 36 | .Xr c_mem_rchr 3 37 | -------------------------------------------------------------------------------- /man/c_arr_avail.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_ARR_AVAIL 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_arr_avail 6 | .Nd calculate available memory in array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft usize 13 | .Fn c_arr_avail "ctype_arr *p" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_arr_avail 17 | function calculates the available memory in the array 18 | .Fa p . 19 | .Sh RETURN VALUES 20 | The 21 | .Fn c_arr_avail 22 | function returns the number of uninitialized bytes in the given array. 23 | .Sh EXAMPLES 24 | .Bd -literal -offset indent 25 | usize n = c_arr_len(&arr, sizeof(int)); 26 | c_ioq_fmt(ioq1, "Available Memory: %llu\en", n); 27 | c_ioq_flush(ioq1); 28 | .Ed 29 | .Sh SEE ALSO 30 | .Xr c_arr_bytes 3 , 31 | .Xr c_arr_len 3 , 32 | .Xr c_arr_total 3 33 | -------------------------------------------------------------------------------- /man/c_dyn_tofrom.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 07 2023 $ 2 | .Dt C_DYN_TOFROM 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dyn_tofrom 6 | .Nd append array to dynamic array 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_dyn_tofrom "ctype_arr *dest" "ctype_arr *s" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dyn_tofrom 17 | function appends the content from the array 18 | .Fa s 19 | to the array 20 | .Fa dest . 21 | If not enough bytes are allocated, 22 | .Fn c_dyn_tofrom 23 | allocates more bytes. 24 | .Sh RETURN VALUES 25 | .Rv -std 26 | .Sh ERRORS 27 | The 28 | .Fn c_dyn_tofrom 29 | function may fail and set the external variable 30 | .Va errno 31 | for any of the errors specified for the library function 32 | .Xr c_dyn_cat 3 . 33 | .Sh SEE ALSO 34 | .Xr c_dyn_cat 3 35 | -------------------------------------------------------------------------------- /man/c_std_bsearch.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt C_STD_BSEARCH 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_std_bsearch 6 | .Nd binary search of a sorted table 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_std_bsearch "void *k" "void *buf" "usize m" "usize n" "ctype_cmpfn f" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_std_bsearch 17 | function searches for the object 18 | .Fa k 19 | in the memory region 20 | .Fa buf 21 | which holds a total of 22 | .Fa m 23 | objects, each 24 | .Fa n 25 | bytes in size. 26 | in ascending order according to the comparison function 27 | .Fa f . 28 | .Sh RETURN VALUES 29 | The 30 | .Fn c_std_bsearch 31 | function returns a pointer to the matching object, or a nil 32 | pointer if no match is found. 33 | .Sh SEE ALSO 34 | .Xr c_std_nbsearch 3 35 | -------------------------------------------------------------------------------- /src/fmt/install.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "private.h" 5 | 6 | static int 7 | cmp(void *a, void *b) 8 | { 9 | return *(uchar *)a - ((struct fmtverb *)b)->c; 10 | } 11 | 12 | ctype_status 13 | c_fmt_install(ctype_rune c, ctype_fmtfn f) 14 | { 15 | struct fmtverb *p; 16 | struct fmtverb nent; 17 | ctype_arr *ap; 18 | usize n; 19 | uchar *s; 20 | 21 | ap = &_tertium_fmt_fmts; 22 | if (c_dyn_ready(ap, 1, sizeof(nent))) 23 | return -1; 24 | 25 | n = c_arr_len(ap, sizeof(*p)); 26 | s = c_arr_data(ap); 27 | p = c_std_nbsearch(&c, s, n, sizeof(*p), &cmp); 28 | if (p->c == c) { 29 | p->f = f; 30 | return 0; 31 | } 32 | nent = (struct fmtverb){ c, f }; 33 | n = (((uchar *)p - s) / sizeof(*p)) + !!n; 34 | return c_dyn_idxcat(ap, n, &nent, 1, sizeof(nent)); 35 | } 36 | -------------------------------------------------------------------------------- /man/c_mem_rchr.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: January 01 2020 $ 2 | .Dt C_MEM_RCHR 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_mem_rchr 6 | .Nd find byte in memory area 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft void * 13 | .Fn c_mem_rchr "void *v" "usize n" "int c" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_mem_rchr 17 | function locates the last occurence of 18 | .Fa c 19 | .Pq Li uchar 20 | in the initial 21 | .Fa n 22 | bytes of 23 | .Fa v . 24 | .Sh RETURN VALUES 25 | The 26 | .Fn c_mem_rchr 27 | function returns a pointer to the byte located, 28 | or nil if the byte is not found. 29 | .Sh EXAMPLES 30 | .Bd -literal -offset indent 31 | char path[] = "/tmp/.hidden/file.ext"; 32 | char *s = c_mem_rchr(path, sizeof(path), '.'); 33 | *s = '\e0'; 34 | 35 | .Ed 36 | .Sh SEE ALSO 37 | .Xr c_mem_chr 3 38 | -------------------------------------------------------------------------------- /man/c_dir_set.3: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate: September 10 2023 $ 2 | .Dt C_DIR_SET 3 3 | .Os 4 | .Sh NAME 5 | .Nm c_dir_set 6 | .Nd set directory entry instruction 7 | .Sh LIBRARY 8 | .Lb tertium 9 | .Sh SYNOPSIS 10 | .In tertium/cpu.h 11 | .In tertium/std.h 12 | .Ft ctype_status 13 | .Fn c_dir_set "ctype_dir *p" "ctype_dent *ep" "int instr" 14 | .Sh DESCRIPTION 15 | The 16 | .Fn c_dir_set 17 | function sets the instruction 18 | .Fa instr 19 | for further processing for the entry 20 | .Fa ep . 21 | .Pp 22 | The 23 | .Fa instr 24 | must be set to one of the following values: 25 | .Bl -tag -width XXXXXXXXXXX 26 | .It Dv C_DIR_FSAGN 27 | Re-visit the entry. 28 | .It Dv C_DIR_FSFLW 29 | Follow this entry. 30 | .It Dv C_DIR_FSSKP 31 | Skip this entry descendants. 32 | .El 33 | .Sh RETURN VALUES 34 | The 35 | .Fn c_dir_set 36 | function returns the value 0. 37 | --------------------------------------------------------------------------------