hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 3415a5fca356d3c633abd90e45029b12cb198da5
parent 2056f41feb1c0e2b22fe954212c7da0ab7ecde44
Author: Sebastian <sebastian@sebsite.pw>
Date:   Tue,  9 May 2023 21:59:05 -0400

Move C string funcs from strings to types::c

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mformat/tar/reader.ha | 4++--
Mlinux/keyctl/keyctl.ha | 8++++----
Mlinux/vdso/vdso.ha | 6+++---
Mos/+freebsd/dirfdfs.ha | 3++-
Mos/+freebsd/environ.ha | 12++++++------
Mos/+freebsd/fs.ha | 4++--
Mos/+linux/dirfdfs.ha | 3++-
Mos/+linux/environ+libc.ha | 22+++++++++++-----------
Mos/+linux/environ.ha | 22+++++++++++-----------
Mos/+linux/fs.ha | 4++--
Mos/exec/exec+freebsd.ha | 8++++----
Mos/exec/exec+linux.ha | 8++++----
Mscripts/gen-stdlib | 28+++++++++++++++-------------
Mstdlib.mk | 40++++++++++++++++++++--------------------
Dstrings/cstrings.ha | 55-------------------------------------------------------
Atypes/c/strings.ha | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Munix/tty/+freebsd/pty.ha | 4++--
17 files changed, 141 insertions(+), 141 deletions(-)

diff --git a/format/tar/reader.ha b/format/tar/reader.ha @@ -6,8 +6,8 @@ use endian; use errors; use io; use strconv; -use strings; use strio; +use types::c; export type reader = struct { src: io::handle, @@ -207,7 +207,7 @@ fn readstr(rd: *bufio::memstream, ln: size) str = { case io::EOF => abort(); }; - return strings::fromc(buf: *[*]u8: *const char)!; + return c::tostr(buf: *[*]u8: *const char)!; }; fn readoct(rd: *bufio::memstream, ln: size) (uint | invalid) = { diff --git a/linux/keyctl/keyctl.ha b/linux/keyctl/keyctl.ha @@ -1,7 +1,7 @@ use bytes; use errors; use rt; -use strings; +use types::c; fn errno(errno: rt::errno) error = { switch (errno) { @@ -19,9 +19,9 @@ export fn add_key( payload: []u8, keyring: serial, ) (serial | error) = { - const keytype = strings::to_c(keytype); + const keytype = c::fromstr(keytype); defer free(keytype); - const name = strings::to_c(name); + const name = c::fromstr(name); defer free(name); match (rt::add_key(keytype, name, payload: *[*]u8: *void, len(payload), keyring)) { @@ -61,7 +61,7 @@ export fn join_session_keyring(name: str) (serial | error) = { let name = if (name == "") { yield null; } else { - yield strings::to_c(name); + yield c::fromstr(name); }; defer free(name); return keyctl(command::JOIN_SESSION_KEYRING, diff --git a/linux/vdso/vdso.ha b/linux/vdso/vdso.ha @@ -2,9 +2,9 @@ // (c) 2021 Drew DeVault <sir@cmpwn.com> // (c) 2021 Ember Sawady <ecs@d2evs.net> // (c) 2021 Mykyta Holubakha <hilobakho@gmail.com> -use strings; use format::elf; use linux; +use types::c; let ehdr: nullable *elf::header64 = null; @@ -141,7 +141,7 @@ fn vdso_checkver(ctx: *vdso_ctx, version: str, num: u32) bool = { cur.vd_aux: uintptr): *elf::verdaux64; const name = ctx.stringtab: uintptr + aux.vda_name: uintptr; - return version == strings::fromc(name: *char)!; + return version == c::tostr(name: *char)!; }; prev = cur; cur = (cur: uintptr + cur.vd_next: uintptr): *elf::verdef64; @@ -174,7 +174,7 @@ export fn getsym(symname: str, symver: str) nullable *void = { continue; }; const name = ctx.stringtab: uintptr + sym.st_name: uintptr; - const s: str = strings::fromc(name: *const char)!; + const s: str = c::tostr(name: *const char)!; if (s != symname) continue; if (!vdso_checkver(ctx, symver, i)) diff --git a/os/+freebsd/dirfdfs.ha b/os/+freebsd/dirfdfs.ha @@ -11,6 +11,7 @@ use path; use rt; use strings; use time; +use types::c; type os_filesystem = struct { fs: fs::fs, @@ -383,7 +384,7 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { }; let de = &iter.buf[iter.buf_pos]: *rt::freebsd11_dirent; iter.buf_pos += de.d_reclen; - let name = strings::fromc(&de.d_name: *const char)!; + let name = c::tostr(&de.d_name: *const char)!; let ftype: fs::mode = switch (de.d_type) { case rt::DT_UNKNOWN => diff --git a/os/+freebsd/environ.ha b/os/+freebsd/environ.ha @@ -5,7 +5,7 @@ use bytes; use errors; use rt; use strings; -use types; +use types::c; // The command line arguments provided to the program. By convention, the first // member is usually the name of the program. @@ -19,12 +19,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = strings::fromc(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i])!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, strings::fromc(rt::argv[i])!); + append(args, c::tostr(rt::argv[i])!); }; }; @@ -42,7 +42,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = strings::cstrlen(item: *char); + const ln = c::strlen(item: *char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -50,7 +50,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = strings::cstrlen(item: *const char); + const ln = c::strlen(item: *const char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -73,7 +73,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, strings::fromc(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const char)!); }; return envp; }; diff --git a/os/+freebsd/fs.ha b/os/+freebsd/fs.ha @@ -5,7 +5,7 @@ use errors; use fs; use path; use rt; -use strings; +use types::c; export fn init_cwd() void = { // XXX: Workaround for https://todo.sr.ht/~sircmpwn/hare/616 @@ -22,7 +22,7 @@ export fn init_cwd() void = { // Returns the current working directory. The return value is statically // allocated and must be duplicated (see [[strings::dup]]) before calling getcwd // again. -export fn getcwd() str = strings::fromc(rt::getcwd() as *const char)!; +export fn getcwd() str = c::tostr(rt::getcwd() as *const char)!; // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -13,6 +13,7 @@ use path; use rt; use strings; use time; +use types::c; // Controls how symlinks are followed (or not) in a dirfd filesystem. Support // for this feature varies, you should gate usage of this enum behind a build @@ -431,7 +432,7 @@ fn iter_next(iter: *fs::iterator) (fs::dirent | void) = { }; let de = &iter.buf[iter.buf_pos]: *rt::dirent64; iter.buf_pos += de.d_reclen; - let name = strings::fromc(&de.d_name: *const char)!; + let name = c::tostr(&de.d_name: *const char)!; let ftype: fs::mode = switch (de.d_type) { case rt::DT_UNKNOWN => diff --git a/os/+linux/environ+libc.ha b/os/+linux/environ+libc.ha @@ -3,7 +3,7 @@ use bytes; use rt; use strings; -use types; +use types::c; // The command line arguments provided to the program. By convention, the first // member is usually the name of the program. @@ -18,12 +18,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = strings::fromc(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i])!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, strings::fromc(rt::argv[i])!); + append(args, c::tostr(rt::argv[i])!); }; }; @@ -41,7 +41,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = strings::cstrlen(item: *char); + const ln = c::strlen(item: *char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -49,7 +49,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = strings::cstrlen(item: *const char); + const ln = c::strlen(item: *const char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -72,7 +72,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, strings::fromc(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const char)!); }; return envp; }; @@ -86,7 +86,7 @@ export fn sysname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.sysname: *const char)!; + return c::tostr(&uts.sysname: *const char)!; }; // Returns the host system hostname @@ -95,7 +95,7 @@ export fn hostname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.nodename: *const char)!; + return c::tostr(&uts.nodename: *const char)!; }; // Returns the host kernel version @@ -104,7 +104,7 @@ export fn release() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.release: *const char)!; + return c::tostr(&uts.release: *const char)!; }; // Returns the host operating system version @@ -113,7 +113,7 @@ export fn version() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.version: *const char)!; + return c::tostr(&uts.version: *const char)!; }; // Returns the host CPU architecture @@ -122,5 +122,5 @@ export fn machine() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.machine: *const char)!; + return c::tostr(&uts.machine: *const char)!; }; diff --git a/os/+linux/environ.ha b/os/+linux/environ.ha @@ -6,7 +6,7 @@ use errors; use math; use rt; use strings; -use types; +use types::c; // The command line arguments provided to the program. By convention, the first // member is usually the name of the program. @@ -20,12 +20,12 @@ let args_static: [32]str = [""...]; if (rt::argc < len(args_static)) { args = args_static[..rt::argc]; for (let i = 0z; i < rt::argc; i += 1) { - args[i] = strings::fromc(rt::argv[i])!; + args[i] = c::tostr(rt::argv[i])!; }; } else { args = alloc([], rt::argc); for (let i = 0z; i < rt::argc; i += 1) { - append(args, strings::fromc(rt::argv[i])!); + append(args, c::tostr(rt::argv[i])!); }; }; @@ -43,7 +43,7 @@ export fn getenv(name: const str) (str | void) = { const name_b = strings::toutf8(name); for (let i = 0z; rt::envp[i] != null; i += 1) { const item = rt::envp[i]: *[*]u8; - const ln = strings::cstrlen(item: *char); + const ln = c::strlen(item: *char); const eq: size = match (bytes::index(item[..ln], '=')) { case void => abort("Environment violates System-V invariants"); @@ -51,7 +51,7 @@ export fn getenv(name: const str) (str | void) = { yield i; }; if (bytes::equal(name_b, item[..eq])) { - const ln = strings::cstrlen(item: *const char); + const ln = c::strlen(item: *const char); return strings::fromutf8(item[eq+1..ln])!; }; }; @@ -74,7 +74,7 @@ export fn getenvs() []str = { return envp; }; for (let i = 0z; rt::envp[i] != null; i += 1) { - append(envp, strings::fromc(rt::envp[i]: *const char)!); + append(envp, c::tostr(rt::envp[i]: *const char)!); }; return envp; }; @@ -88,7 +88,7 @@ export fn sysname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.sysname: *const char)!; + return c::tostr(&uts.sysname: *const char)!; }; // Returns the host system hostname @@ -97,7 +97,7 @@ export fn hostname() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.nodename: *const char)!; + return c::tostr(&uts.nodename: *const char)!; }; // Returns the host kernel version @@ -106,7 +106,7 @@ export fn release() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.release: *const char)!; + return c::tostr(&uts.release: *const char)!; }; // Returns the host operating system version @@ -115,7 +115,7 @@ export fn version() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.version: *const char)!; + return c::tostr(&uts.version: *const char)!; }; // Returns the host CPU architecture @@ -124,7 +124,7 @@ export fn machine() const str = { rt::uname(&uts) as void; uts_valid = true; }; - return strings::fromc(&uts.machine: *const char)!; + return c::tostr(&uts.machine: *const char)!; }; // Returns the number of usable CPUs. diff --git a/os/+linux/fs.ha b/os/+linux/fs.ha @@ -5,7 +5,7 @@ use errors; use fs; use path; use rt; -use strings; +use types::c; export fn init_cwd() void = { // XXX: Workaround for https://todo.sr.ht/~sircmpwn/hare/616 @@ -22,7 +22,7 @@ export fn init_cwd() void = { // Returns the current working directory. The return value is statically // allocated and must be duplicated (see [[strings::dup]]) before calling getcwd // again. -export fn getcwd() str = strings::fromc(rt::getcwd() as *const char)!; +export fn getcwd() str = c::tostr(rt::getcwd() as *const char)!; // Change the current working directory. export fn chdir(target: (*fs::fs | str)) (void | fs::error) = { diff --git a/os/exec/exec+freebsd.ha b/os/exec/exec+freebsd.ha @@ -4,8 +4,8 @@ use errors; use io; use rt; -use strings; use os; +use types::c; use unix; export type platform_cmd = io::file; @@ -79,11 +79,11 @@ fn open(path: str) (platform_cmd | error) = { fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!; fn platform_exec(cmd: *command) error = { - // We don't worry about freeing the return values from strings::to_c + // We don't worry about freeing the return values from c::fromstr // because once we exec(2) our heap is fried anyway let argv: []nullable *const char = alloc([], len(cmd.argv) + 1z); for (let i = 0z; i < len(cmd.argv); i += 1z) { - append(argv, strings::to_c(cmd.argv[i])); + append(argv, c::fromstr(cmd.argv[i])); }; append(argv, null); @@ -91,7 +91,7 @@ fn platform_exec(cmd: *command) error = { if (len(cmd.env) != 0) { let env: []nullable *const char = alloc([], len(cmd.env) + 1); for (let i = 0z; i < len(cmd.env); i += 1) { - append(env, strings::to_c(cmd.env[i])); + append(env, c::fromstr(cmd.env[i])); }; append(env, null); envp = env: *[*]nullable *const char; diff --git a/os/exec/exec+linux.ha b/os/exec/exec+linux.ha @@ -5,7 +5,7 @@ use errors; use io; use os; use rt; -use strings; +use types::c; use unix; export type platform_cmd = io::file; @@ -80,11 +80,11 @@ fn open(path: str) (platform_cmd | error) = { fn platform_finish(cmd: *command) void = rt::close(cmd.platform)!; fn platform_exec(cmd: *command) error = { - // We don't worry about freeing the return values from strings::to_c + // We don't worry about freeing the return values from c::fromstr // because once we exec(2) our heap is fried anyway let argv: []nullable *const char = alloc([], len(cmd.argv) + 1z); for (let i = 0z; i < len(cmd.argv); i += 1z) { - append(argv, strings::to_c(cmd.argv[i])); + append(argv, c::fromstr(cmd.argv[i])); }; append(argv, null); @@ -92,7 +92,7 @@ fn platform_exec(cmd: *command) error = { if (len(cmd.env) != 0) { let env: []nullable *const char = alloc([], len(cmd.env) + 1); for (let i = 0z; i < len(cmd.env); i += 1) { - append(env, strings::to_c(cmd.env[i])); + append(env, c::fromstr(cmd.env[i])); }; append(env, null); envp = env: *[*]nullable *const char; diff --git a/scripts/gen-stdlib b/scripts/gen-stdlib @@ -672,7 +672,7 @@ format_tar() { gen_srcs format::tar \ types.ha \ reader.ha - gen_ssa format::tar bufio bytes endian errors io strconv strings strio + gen_ssa format::tar bufio bytes endian errors io strconv strio types::c } fs() { @@ -954,7 +954,7 @@ linux_keyctl() { gen_srcs -plinux linux::keyctl \ keyctl.ha \ types.ha - gen_ssa -plinux linux::keyctl rt errors strings bytes + gen_ssa -plinux linux::keyctl rt errors bytes types::c } linux_timerfd() { @@ -966,7 +966,7 @@ linux_timerfd() { linux_vdso() { gen_srcs -plinux linux::vdso \ vdso.ha - gen_ssa -plinux linux::vdso linux strings format::elf + gen_ssa -plinux linux::vdso linux format::elf types::c } log() { @@ -1175,8 +1175,8 @@ os() { +linux/memory.ha \ +linux/stdfd.ha \ os.ha - gen_ssa -plinux os io strings types fs encoding::utf8 bytes bufio \ - errors math + gen_ssa -plinux os io strings fs encoding::utf8 bytes bufio \ + errors math types::c gen_srcs -pfreebsd os \ +freebsd/environ.ha \ @@ -1185,7 +1185,8 @@ os() { +freebsd/stdfd.ha \ +freebsd/fs.ha \ os.ha - gen_ssa -pfreebsd os io strings types fs encoding::utf8 bytes bufio errors + gen_ssa -pfreebsd os io strings fs encoding::utf8 bytes bufio \ + errors types::c } os_exec() { @@ -1195,14 +1196,15 @@ os_exec() { types.ha \ cmd.ha gen_ssa -plinux os::exec os strings fmt errors unix rt io ascii \ - unix::signal + unix::signal types::c gen_srcs -pfreebsd os::exec \ exec+freebsd.ha \ process+freebsd.ha \ types.ha \ cmd.ha - gen_ssa -pfreebsd os::exec os strings fmt errors unix rt io ascii + gen_ssa -pfreebsd os::exec os strings fmt errors unix rt io ascii \ + types::c } path() { @@ -1307,7 +1309,6 @@ strings() { cap.ha \ concat.ha \ contains.ha \ - cstrings.ha \ dup.ha \ iter.ha \ runes.ha \ @@ -1400,11 +1401,11 @@ types() { types_c() { if [ $testing -eq 1 ] then - gen_srcs types::c +test.ha types.ha 'arch+$(ARCH).ha' + gen_srcs types::c +test.ha strings.ha types.ha 'arch+$(ARCH).ha' else - gen_srcs types::c types.ha 'arch+$(ARCH).ha' + gen_srcs types::c strings.ha types.ha 'arch+$(ARCH).ha' fi - gen_ssa types::c types + gen_ssa types::c encoding::utf8 types } unix() { @@ -1492,7 +1493,8 @@ unix_tty() { +freebsd/open.ha \ +freebsd/pty.ha \ +freebsd/winsize.ha - gen_ssa -pfreebsd unix::tty bufio errors fmt fs io os rt strings + gen_ssa -pfreebsd unix::tty bufio errors fmt fs io os rt strings \ + types::c } uuid() { diff --git a/stdlib.mk b/stdlib.mk @@ -1248,7 +1248,7 @@ stdlib_format_tar_any_srcs = \ $(STDLIB)/format/tar/types.ha \ $(STDLIB)/format/tar/reader.ha -$(HARECACHE)/format/tar/format_tar-any.ssa: $(stdlib_format_tar_any_srcs) $(stdlib_rt) $(stdlib_bufio_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_endian_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strconv_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_strio_$(PLATFORM)) +$(HARECACHE)/format/tar/format_tar-any.ssa: $(stdlib_format_tar_any_srcs) $(stdlib_rt) $(stdlib_bufio_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_endian_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_strconv_$(PLATFORM)) $(stdlib_strio_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/format/tar @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nformat::tar \ @@ -1533,7 +1533,7 @@ stdlib_linux_keyctl_linux_srcs = \ $(STDLIB)/linux/keyctl/keyctl.ha \ $(STDLIB)/linux/keyctl/types.ha -$(HARECACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(stdlib_linux_keyctl_linux_srcs) $(stdlib_rt) $(stdlib_rt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) +$(HARECACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(stdlib_linux_keyctl_linux_srcs) $(stdlib_rt) $(stdlib_rt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/linux/keyctl @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux::keyctl \ @@ -1553,7 +1553,7 @@ $(HARECACHE)/linux/timerfd/linux_timerfd-linux.ssa: $(stdlib_linux_timerfd_linux stdlib_linux_vdso_linux_srcs = \ $(STDLIB)/linux/vdso/vdso.ha -$(HARECACHE)/linux/vdso/linux_vdso-linux.ssa: $(stdlib_linux_vdso_linux_srcs) $(stdlib_rt) $(stdlib_linux_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_format_elf_$(PLATFORM)) +$(HARECACHE)/linux/vdso/linux_vdso-linux.ssa: $(stdlib_linux_vdso_linux_srcs) $(stdlib_rt) $(stdlib_linux_$(PLATFORM)) $(stdlib_format_elf_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/linux/vdso @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nlinux::vdso \ @@ -1796,7 +1796,7 @@ stdlib_os_linux_srcs = \ $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/os.ha -$(HARECACHE)/os/os-linux.ssa: $(stdlib_os_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_math_$(PLATFORM)) +$(HARECACHE)/os/os-linux.ssa: $(stdlib_os_linux_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_math_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/os @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos \ @@ -1811,7 +1811,7 @@ stdlib_os_freebsd_srcs = \ $(STDLIB)/os/+freebsd/fs.ha \ $(STDLIB)/os/os.ha -$(HARECACHE)/os/os-freebsd.ssa: $(stdlib_os_freebsd_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) +$(HARECACHE)/os/os-freebsd.ssa: $(stdlib_os_freebsd_srcs) $(stdlib_rt) $(stdlib_io_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_bytes_$(PLATFORM)) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/os @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos \ @@ -1824,7 +1824,7 @@ stdlib_os_exec_linux_srcs = \ $(STDLIB)/os/exec/types.ha \ $(STDLIB)/os/exec/cmd.ha -$(HARECACHE)/os/exec/os_exec-linux.ssa: $(stdlib_os_exec_linux_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_ascii_$(PLATFORM)) $(stdlib_unix_signal_$(PLATFORM)) +$(HARECACHE)/os/exec/os_exec-linux.ssa: $(stdlib_os_exec_linux_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_ascii_$(PLATFORM)) $(stdlib_unix_signal_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/os/exec @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos::exec \ @@ -1837,7 +1837,7 @@ stdlib_os_exec_freebsd_srcs = \ $(STDLIB)/os/exec/types.ha \ $(STDLIB)/os/exec/cmd.ha -$(HARECACHE)/os/exec/os_exec-freebsd.ssa: $(stdlib_os_exec_freebsd_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_ascii_$(PLATFORM)) +$(HARECACHE)/os/exec/os_exec-freebsd.ssa: $(stdlib_os_exec_freebsd_srcs) $(stdlib_rt) $(stdlib_os_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_unix_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_ascii_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/os/exec @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nos::exec \ @@ -1930,7 +1930,6 @@ stdlib_strings_any_srcs = \ $(STDLIB)/strings/cap.ha \ $(STDLIB)/strings/concat.ha \ $(STDLIB)/strings/contains.ha \ - $(STDLIB)/strings/cstrings.ha \ $(STDLIB)/strings/dup.ha \ $(STDLIB)/strings/iter.ha \ $(STDLIB)/strings/runes.ha \ @@ -2066,10 +2065,11 @@ $(HARECACHE)/types/types-any.ssa: $(stdlib_types_any_srcs) $(stdlib_rt) # types::c (+any) stdlib_types_c_any_srcs = \ + $(STDLIB)/types/c/strings.ha \ $(STDLIB)/types/c/types.ha \ $(STDLIB)/types/c/arch+$(ARCH).ha -$(HARECACHE)/types/c/types_c-any.ssa: $(stdlib_types_c_any_srcs) $(stdlib_rt) $(stdlib_types_$(PLATFORM)) +$(HARECACHE)/types/c/types_c-any.ssa: $(stdlib_types_c_any_srcs) $(stdlib_rt) $(stdlib_encoding_utf8_$(PLATFORM)) $(stdlib_types_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/types/c @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Ntypes::c \ @@ -2219,7 +2219,7 @@ stdlib_unix_tty_freebsd_srcs = \ $(STDLIB)/unix/tty/+freebsd/pty.ha \ $(STDLIB)/unix/tty/+freebsd/winsize.ha -$(HARECACHE)/unix/tty/unix_tty-freebsd.ssa: $(stdlib_unix_tty_freebsd_srcs) $(stdlib_rt) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) +$(HARECACHE)/unix/tty/unix_tty-freebsd.ssa: $(stdlib_unix_tty_freebsd_srcs) $(stdlib_rt) $(stdlib_bufio_$(PLATFORM)) $(stdlib_errors_$(PLATFORM)) $(stdlib_fmt_$(PLATFORM)) $(stdlib_fs_$(PLATFORM)) $(stdlib_io_$(PLATFORM)) $(stdlib_os_$(PLATFORM)) $(stdlib_rt_$(PLATFORM)) $(stdlib_strings_$(PLATFORM)) $(stdlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(HARECACHE)/unix/tty @HARECACHE=$(HARECACHE) $(HAREC) $(HAREFLAGS) -o $@ -Nunix::tty \ @@ -3525,7 +3525,7 @@ testlib_format_tar_any_srcs = \ $(STDLIB)/format/tar/types.ha \ $(STDLIB)/format/tar/reader.ha -$(TESTCACHE)/format/tar/format_tar-any.ssa: $(testlib_format_tar_any_srcs) $(testlib_rt) $(testlib_bufio_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_endian_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strconv_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_strio_$(PLATFORM)) +$(TESTCACHE)/format/tar/format_tar-any.ssa: $(testlib_format_tar_any_srcs) $(testlib_rt) $(testlib_bufio_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_endian_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_strconv_$(PLATFORM)) $(testlib_strio_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/format/tar @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nformat::tar \ @@ -3825,7 +3825,7 @@ testlib_linux_keyctl_linux_srcs = \ $(STDLIB)/linux/keyctl/keyctl.ha \ $(STDLIB)/linux/keyctl/types.ha -$(TESTCACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(testlib_linux_keyctl_linux_srcs) $(testlib_rt) $(testlib_rt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) +$(TESTCACHE)/linux/keyctl/linux_keyctl-linux.ssa: $(testlib_linux_keyctl_linux_srcs) $(testlib_rt) $(testlib_rt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/linux/keyctl @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux::keyctl \ @@ -3845,7 +3845,7 @@ $(TESTCACHE)/linux/timerfd/linux_timerfd-linux.ssa: $(testlib_linux_timerfd_linu testlib_linux_vdso_linux_srcs = \ $(STDLIB)/linux/vdso/vdso.ha -$(TESTCACHE)/linux/vdso/linux_vdso-linux.ssa: $(testlib_linux_vdso_linux_srcs) $(testlib_rt) $(testlib_linux_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_format_elf_$(PLATFORM)) +$(TESTCACHE)/linux/vdso/linux_vdso-linux.ssa: $(testlib_linux_vdso_linux_srcs) $(testlib_rt) $(testlib_linux_$(PLATFORM)) $(testlib_format_elf_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/linux/vdso @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nlinux::vdso \ @@ -4096,7 +4096,7 @@ testlib_os_linux_srcs = \ $(STDLIB)/os/+linux/stdfd.ha \ $(STDLIB)/os/os.ha -$(TESTCACHE)/os/os-linux.ssa: $(testlib_os_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_math_$(PLATFORM)) +$(TESTCACHE)/os/os-linux.ssa: $(testlib_os_linux_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_math_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/os @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos \ @@ -4111,7 +4111,7 @@ testlib_os_freebsd_srcs = \ $(STDLIB)/os/+freebsd/fs.ha \ $(STDLIB)/os/os.ha -$(TESTCACHE)/os/os-freebsd.ssa: $(testlib_os_freebsd_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) +$(TESTCACHE)/os/os-freebsd.ssa: $(testlib_os_freebsd_srcs) $(testlib_rt) $(testlib_io_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_bytes_$(PLATFORM)) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/os @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos \ @@ -4124,7 +4124,7 @@ testlib_os_exec_linux_srcs = \ $(STDLIB)/os/exec/types.ha \ $(STDLIB)/os/exec/cmd.ha -$(TESTCACHE)/os/exec/os_exec-linux.ssa: $(testlib_os_exec_linux_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_ascii_$(PLATFORM)) $(testlib_unix_signal_$(PLATFORM)) +$(TESTCACHE)/os/exec/os_exec-linux.ssa: $(testlib_os_exec_linux_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_ascii_$(PLATFORM)) $(testlib_unix_signal_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/os/exec @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos::exec \ @@ -4137,7 +4137,7 @@ testlib_os_exec_freebsd_srcs = \ $(STDLIB)/os/exec/types.ha \ $(STDLIB)/os/exec/cmd.ha -$(TESTCACHE)/os/exec/os_exec-freebsd.ssa: $(testlib_os_exec_freebsd_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_ascii_$(PLATFORM)) +$(TESTCACHE)/os/exec/os_exec-freebsd.ssa: $(testlib_os_exec_freebsd_srcs) $(testlib_rt) $(testlib_os_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_unix_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_ascii_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/os/exec @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nos::exec \ @@ -4235,7 +4235,6 @@ testlib_strings_any_srcs = \ $(STDLIB)/strings/cap.ha \ $(STDLIB)/strings/concat.ha \ $(STDLIB)/strings/contains.ha \ - $(STDLIB)/strings/cstrings.ha \ $(STDLIB)/strings/dup.ha \ $(STDLIB)/strings/iter.ha \ $(STDLIB)/strings/runes.ha \ @@ -4372,10 +4371,11 @@ $(TESTCACHE)/types/types-any.ssa: $(testlib_types_any_srcs) $(testlib_rt) # types::c (+any) testlib_types_c_any_srcs = \ $(STDLIB)/types/c/+test.ha \ + $(STDLIB)/types/c/strings.ha \ $(STDLIB)/types/c/types.ha \ $(STDLIB)/types/c/arch+$(ARCH).ha -$(TESTCACHE)/types/c/types_c-any.ssa: $(testlib_types_c_any_srcs) $(testlib_rt) $(testlib_types_$(PLATFORM)) +$(TESTCACHE)/types/c/types_c-any.ssa: $(testlib_types_c_any_srcs) $(testlib_rt) $(testlib_encoding_utf8_$(PLATFORM)) $(testlib_types_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/types/c @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Ntypes::c \ @@ -4525,7 +4525,7 @@ testlib_unix_tty_freebsd_srcs = \ $(STDLIB)/unix/tty/+freebsd/pty.ha \ $(STDLIB)/unix/tty/+freebsd/winsize.ha -$(TESTCACHE)/unix/tty/unix_tty-freebsd.ssa: $(testlib_unix_tty_freebsd_srcs) $(testlib_rt) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) +$(TESTCACHE)/unix/tty/unix_tty-freebsd.ssa: $(testlib_unix_tty_freebsd_srcs) $(testlib_rt) $(testlib_bufio_$(PLATFORM)) $(testlib_errors_$(PLATFORM)) $(testlib_fmt_$(PLATFORM)) $(testlib_fs_$(PLATFORM)) $(testlib_io_$(PLATFORM)) $(testlib_os_$(PLATFORM)) $(testlib_rt_$(PLATFORM)) $(testlib_strings_$(PLATFORM)) $(testlib_types_c_$(PLATFORM)) @printf 'HAREC \t$@\n' @mkdir -p $(TESTCACHE)/unix/tty @HARECACHE=$(TESTCACHE) $(HAREC) $(TESTHAREFLAGS) -o $@ -Nunix::tty \ diff --git a/strings/cstrings.ha b/strings/cstrings.ha @@ -1,55 +0,0 @@ -// License: MPL-2.0 -// (c) 2021 Drew DeVault <sir@cmpwn.com> -// (c) 2021 Ember Sawady <ecs@d2evs.net> -// (c) 2022 Vlad-Stefan Harbuz <vlad@vladh.net> -use encoding::utf8; -use types; - -// Computes the length of a NUL-terminated C string, in octets, in O(n). The -// computed length does not include the NUL terminator. -export fn cstrlen(cstr: *const char) size = { - const ptr = cstr: *[*]u8; - let ln = 0z; - for (ptr[ln] != 0; ln += 1) void; - return ln; -}; - -// Converts a C string to a Hare string in O(n), and does not check if it's -// valid UTF-8. -export fn fromc_unsafe(cstr: *const char) const str = { - const l = cstrlen(cstr); - const s = types::string { - data = cstr: *[*]u8, - length = l, - capacity = l + 1, - }; - return *(&s: *const str); -}; - -// Converts a C string to a Hare string in O(n). If the string is not valid -// UTF-8, return [[encoding::utf8::invalid.]] -export fn fromc(cstr: *const char) (const str | utf8::invalid) = { - let s = fromc_unsafe(cstr); - return if (utf8::valid(s)) s else utf8::invalid; -}; - -// Converts a Hare string to a C string. The result is allocated; the caller -// must free it when they're done. -export fn to_c(s: const str) *char = { - let slice: []u8 = alloc([0...], len(s) + 1); - return to_cbuf(s, slice); -}; - -// Converts a Hare string to a C string. The result is stored into a -// user-supplied buffer. -export fn to_cbuf(s: const str, sl: []u8) *char = { - if (len(sl) < len(s) + 1) { - abort("to_cbuf: buffer has insufficient space for string plus NUL"); - }; - - const s = &s: *[]u8; - sl[..len(s)] = s[..]; - sl[len(s)] = 0; - - return (*(&sl: *types::slice)).data: *char; -}; diff --git a/types/c/strings.ha b/types/c/strings.ha @@ -0,0 +1,51 @@ +use encoding::utf8; +use types; + +// Computes the length of a NUL-terminated C string, in octets, in O(n). The +// computed length does not include the NUL terminator. +export fn strlen(cstr: *const char) size = { + const ptr = cstr: *[*]u8; + let ln = 0z; + for (ptr[ln] != 0; ln += 1) void; + return ln; +}; + +// Converts a C string to a Hare string in O(n), and does not check if it's +// valid UTF-8. +export fn tostr_unsafe(cstr: *const char) const str = { + const l = strlen(cstr); + const s = types::string { + data = cstr: *[*]u8, + length = l, + capacity = l + 1, + }; + return *(&s: *const str); +}; + +// Converts a C string to a Hare string in O(n). If the string is not valid +// UTF-8, return [[encoding::utf8::invalid.]] +export fn tostr(cstr: *const char) (const str | utf8::invalid) = { + let s = tostr_unsafe(cstr); + return if (utf8::valid(s)) s else utf8::invalid; +}; + +// Converts a Hare string to a C string. The result is allocated; the caller +// must free it when they're done. +export fn fromstr(s: const str) *char = { + let slice: []char = alloc([0...], len(s) + 1); + return fromstr_buf(s, slice); +}; + +// Converts a Hare string to a C string. The result is stored into a +// user-supplied buffer. +export fn fromstr_buf(s: const str, sl: []char) *char = { + if (len(sl) < len(s) + 1) { + abort("types::c::fromstr_buf: buffer has insufficient space for string plus NUL"); + }; + + const s = &s: *[]char; + sl[..len(s)] = s[..]; + sl[len(s)] = 0; + + return (*(&sl: *types::slice)).data: *char; +}; diff --git a/unix/tty/+freebsd/pty.ha b/unix/tty/+freebsd/pty.ha @@ -6,7 +6,7 @@ use fs; use io; use os; use rt; -use strings; +use types::c; // Opens an available pseudoterminal master. fn open_master() (io::file | fs::error) = { @@ -48,7 +48,7 @@ export fn ptsname(master: io::file) (str | error) = { case => static let path_buf: [rt::PATH_MAX]u8 = [0...]; return fmt::bsprintf(path_buf, - "/dev/{}", strings::fromc(&name: *const char)!); + "/dev/{}", c::tostr(&name: *const char)!); }; };