refactor: Replaced fmt.printf calls with fmt.eprintf.

This commit is contained in:
2026-06-25 17:19:11 -04:00
parent ad3de74e35
commit 13e9495642
4 changed files with 53 additions and 55 deletions

View File

@@ -26,11 +26,9 @@
13. Test all cmds / terminal branches. 13. Test all cmds / terminal branches.
14. Fix error messages to use fmt.eprintf (stderr) instead of fmt.printf (stdout) 14. Pass allocator to findr?
15. Pass allocator to findr? 15. Update `read_wire_string` to use a slice.
16. Update `read_wire_string` to use a slice.
## Double-check AI output ## Double-check AI output

View File

@@ -30,14 +30,14 @@ load_config :: proc(config_path: string, allocator := context.allocator) -> (Con
// TODO: Should we use context.allocator + defer delete()? // TODO: Should we use context.allocator + defer delete()?
data, read_err := os.read_entire_file_from_path(config_path, context.temp_allocator) data, read_err := os.read_entire_file_from_path(config_path, context.temp_allocator)
if read_err != nil { if read_err != nil {
fmt.println("No config file found. Please run `envr init` to generate one.") fmt.eprintln("No config file found. Please run `envr init` to generate one.")
return Config{}, false return Config{}, false
} }
cfg: Config cfg: Config
err := json.unmarshal(data, &cfg, .JSON5, allocator) err := json.unmarshal(data, &cfg, .JSON5, allocator)
if err != nil { if err != nil {
fmt.printf("Error parsing config: %v\n", err) fmt.eprintf("Error parsing config: %v\n", err)
return Config{}, false return Config{}, false
} }
cfg.config_path = config_path cfg.config_path = config_path
@@ -79,7 +79,7 @@ save_config :: proc(cfg: Config, force: bool = false) -> bool {
if !os.exists(config_dir) { if !os.exists(config_dir) {
mkdir_err := os.make_directory(config_dir) mkdir_err := os.make_directory(config_dir)
if mkdir_err != nil { if mkdir_err != nil {
fmt.printf("Error creating %s directory: %v\n", config_dir, mkdir_err) fmt.eprintf("Error creating %s directory: %v\n", config_dir, mkdir_err)
return false return false
} }
} }
@@ -89,7 +89,7 @@ save_config :: proc(cfg: Config, force: bool = false) -> bool {
if stat_err == nil { if stat_err == nil {
defer os.file_info_delete(info, context.temp_allocator) defer os.file_info_delete(info, context.temp_allocator)
if info.size > 0 { if info.size > 0 {
fmt.println("Config file already exists. Run again with --force to reinitialize.") fmt.eprintln("Config file already exists. Run again with --force to reinitialize.")
return false return false
} }
} }
@@ -101,13 +101,13 @@ save_config :: proc(cfg: Config, force: bool = false) -> bool {
context.temp_allocator, context.temp_allocator,
) )
if marshal_err != nil { if marshal_err != nil {
fmt.printf("Error marshaling config: %v\n", marshal_err) fmt.eprintf("Error marshaling config: %v\n", marshal_err)
return false return false
} }
write_err := os.write_entire_file(cfg.config_path, data) write_err := os.write_entire_file(cfg.config_path, data)
if write_err != nil { if write_err != nil {
fmt.printf("Error writing config: %v\n", write_err) fmt.eprintf("Error writing config: %v\n", write_err)
return false return false
} }
@@ -150,19 +150,19 @@ new_config :: proc(
find_ssh_private_keys :: proc() -> (keys: [dynamic]string, ok: bool) { find_ssh_private_keys :: proc() -> (keys: [dynamic]string, ok: bool) {
home, home_err := os.user_home_dir(context.allocator) home, home_err := os.user_home_dir(context.allocator)
if home_err != nil { if home_err != nil {
fmt.printf("Error getting home dir: %v\n", home_err) fmt.eprintf("Error getting home dir: %v\n", home_err)
return return
} }
ssh_dir, join_err := filepath.join([]string{home, ".ssh"}) ssh_dir, join_err := filepath.join([]string{home, ".ssh"})
if join_err != nil { if join_err != nil {
fmt.printf("Error building ssh path: %v\n", join_err) fmt.eprintf("Error building ssh path: %v\n", join_err)
return return
} }
entries, dir_err := os.read_all_directory_by_path(ssh_dir, context.allocator) entries, dir_err := os.read_all_directory_by_path(ssh_dir, context.allocator)
if dir_err != nil { if dir_err != nil {
fmt.printf("Could not read ~/.ssh directory: %v\n", dir_err) fmt.eprintf("Could not read ~/.ssh directory: %v\n", dir_err)
return return
} }
defer os.file_info_slice_delete(entries, context.allocator) defer os.file_info_slice_delete(entries, context.allocator)

View File

@@ -60,7 +60,7 @@ encrypt :: proc(plaintext: []u8, keys: []SshKeyPair) -> (ciphertext: []u8, ok: b
&sym_key[0], &sym_key[0],
) )
if rc != 0 { if rc != 0 {
fmt.println("Error: symmetric encryption failed") fmt.eprintln("Error: symmetric encryption failed")
delete(secret_ct) delete(secret_ct)
return return
} }
@@ -84,7 +84,7 @@ encrypt :: proc(plaintext: []u8, keys: []SshKeyPair) -> (ciphertext: []u8, ok: b
&x25519_pairs[0].Private[0], &x25519_pairs[0].Private[0],
) )
if rc != 0 { if rc != 0 {
fmt.printf("Error: failed to encrypt for recipient %d\n", i) fmt.eprintf("Error: failed to encrypt for recipient %d\n", i)
delete(entries) delete(entries)
delete(secret_ct) delete(secret_ct)
return return
@@ -132,13 +132,13 @@ encrypt :: proc(plaintext: []u8, keys: []SshKeyPair) -> (ciphertext: []u8, ok: b
decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: bool) { decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: bool) {
if len(ciphertext) < HEADER_SIZE { if len(ciphertext) < HEADER_SIZE {
fmt.println("Error: ciphertext too short (header)") fmt.eprintln("Error: ciphertext too short (header)")
return return
} }
for i in 0 ..< 4 { for i in 0 ..< 4 {
if ciphertext[i] != MAGIC_BYTES[i] { if ciphertext[i] != MAGIC_BYTES[i] {
fmt.println("Error: invalid magic bytes") fmt.eprintln("Error: invalid magic bytes")
return return
} }
} }
@@ -166,7 +166,7 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
recipients_end := offset + int(num_recipients) * RECIPIENT_ENTRY_SIZE recipients_end := offset + int(num_recipients) * RECIPIENT_ENTRY_SIZE
if recipients_end > len(ciphertext) { if recipients_end > len(ciphertext) {
fmt.println("Error: ciphertext too short (recipient data)") fmt.eprintln("Error: ciphertext too short (recipient data)")
return return
} }
@@ -222,7 +222,7 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
} }
if !found { if !found {
fmt.println("Error: no matching recipient found") fmt.eprintln("Error: no matching recipient found")
return return
} }
@@ -236,14 +236,14 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
&x25519_pairs[matched_pi].Private[0], &x25519_pairs[matched_pi].Private[0],
) )
if rc != 0 { if rc != 0 {
fmt.println("Error: failed to decrypt symmetric key") fmt.eprintln("Error: failed to decrypt symmetric key")
return return
} }
ct_data := ciphertext[recipients_end:] ct_data := ciphertext[recipients_end:]
pt_len := len(ct_data) - CRYPTO_SECRETBOX_MAC_BYTES pt_len := len(ct_data) - CRYPTO_SECRETBOX_MAC_BYTES
if pt_len < 0 { if pt_len < 0 {
fmt.println("Error: ciphertext too short (no encrypted data)") fmt.eprintln("Error: ciphertext too short (no encrypted data)")
return return
} }
@@ -260,7 +260,7 @@ decrypt :: proc(ciphertext: []u8, keys: []SshKeyPair) -> (plaintext: []u8, ok: b
&sym_key[0], &sym_key[0],
) )
if rc != 0 { if rc != 0 {
fmt.println("Error: symmetric decryption failed") fmt.eprintln("Error: symmetric decryption failed")
delete(plaintext) delete(plaintext)
return return
} }
@@ -285,21 +285,21 @@ ssh_to_x25519 :: proc(
for i in 0 ..< len(keys) { for i in 0 ..< len(keys) {
ssh_kp, parse_ok := parse_ssh_private_key(keys[i].private) ssh_kp, parse_ok := parse_ssh_private_key(keys[i].private)
if !parse_ok { if !parse_ok {
fmt.printf("Error: failed to parse SSH private key: %s\n", keys[i].private) fmt.eprintf("Error: failed to parse SSH private key: %s\n", keys[i].private)
delete(pairs) delete(pairs)
return pairs, false return pairs, false
} }
ssh_pub, pub_ok := parse_ssh_public_key(keys[i].public) ssh_pub, pub_ok := parse_ssh_public_key(keys[i].public)
if !pub_ok { if !pub_ok {
fmt.printf("Error: failed to parse SSH public key: %s\n", keys[i].public) fmt.eprintf("Error: failed to parse SSH public key: %s\n", keys[i].public)
delete(pairs) delete(pairs)
return pairs, false return pairs, false
} }
pk_rc := crypto_sign_ed25519_pk_to_curve25519(&pairs[i].Public[0], &ssh_pub[0]) pk_rc := crypto_sign_ed25519_pk_to_curve25519(&pairs[i].Public[0], &ssh_pub[0])
if pk_rc != 0 { if pk_rc != 0 {
fmt.println("Error: failed to convert ed25519 public key to curve25519") fmt.eprintln("Error: failed to convert ed25519 public key to curve25519")
delete(pairs) delete(pairs)
return pairs, false return pairs, false
} }
@@ -314,7 +314,7 @@ ssh_to_x25519 :: proc(
sk_rc := crypto_sign_ed25519_sk_to_curve25519(&pairs[i].Private[0], &ed25519_sk[0]) sk_rc := crypto_sign_ed25519_sk_to_curve25519(&pairs[i].Private[0], &ed25519_sk[0])
if sk_rc != 0 { if sk_rc != 0 {
fmt.println("Error: failed to convert ed25519 private key to curve25519") fmt.eprintln("Error: failed to convert ed25519 private key to curve25519")
delete(pairs) delete(pairs)
return pairs, false return pairs, false
} }

58
db.odin
View File

@@ -94,14 +94,14 @@ db_init :: proc() -> (db: Db, ok: bool) {
conn: sqlite.Db conn: sqlite.Db
rc := sqlite.open(":memory:", &conn) rc := sqlite.open(":memory:", &conn)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error opening in-memory database: %s\n", sqlite.errmsg(conn)) fmt.eprintf("Error opening in-memory database: %s\n", sqlite.errmsg(conn))
return return
} }
create_sql: cstring = "CREATE TABLE IF NOT EXISTS envr_env_files (path TEXT PRIMARY KEY NOT NULL, remotes TEXT, sha256 TEXT NOT NULL, contents TEXT NOT NULL)" create_sql: cstring = "CREATE TABLE IF NOT EXISTS envr_env_files (path TEXT PRIMARY KEY NOT NULL, remotes TEXT, sha256 TEXT NOT NULL, contents TEXT NOT NULL)"
rc = sqlite.exec(conn, create_sql, nil, nil, nil) rc = sqlite.exec(conn, create_sql, nil, nil, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error creating table: %s\n", sqlite.errmsg(conn)) fmt.eprintf("Error creating table: %s\n", sqlite.errmsg(conn))
sqlite.close(conn) sqlite.close(conn)
return return
} }
@@ -119,14 +119,14 @@ db_allocator :: proc(db: ^Db) -> mem.Allocator {
db_restore_from_encrypted :: proc(db: ^Db, data_path: string) -> bool { db_restore_from_encrypted :: proc(db: ^Db, data_path: string) -> bool {
encrypted_data, read_err := os.read_entire_file_from_path(data_path, context.temp_allocator) encrypted_data, read_err := os.read_entire_file_from_path(data_path, context.temp_allocator)
if read_err != nil { if read_err != nil {
fmt.printf("Error reading encrypted database: %v\n", read_err) fmt.eprintf("Error reading encrypted database: %v\n", read_err)
return false return false
} }
// TODO: Use context.temp_allocator // TODO: Use context.temp_allocator
plaintext, dec_ok := decrypt(encrypted_data, db.cfg.keys[:]) plaintext, dec_ok := decrypt(encrypted_data, db.cfg.keys[:])
if !dec_ok { if !dec_ok {
fmt.println("Error: decryption failed") fmt.eprintln("Error: decryption failed")
return false return false
} }
defer delete(plaintext) defer delete(plaintext)
@@ -134,7 +134,7 @@ db_restore_from_encrypted :: proc(db: ^Db, data_path: string) -> bool {
n := i64(len(plaintext)) n := i64(len(plaintext))
buf := sqlite.malloc64(n) buf := sqlite.malloc64(n)
if buf == nil { if buf == nil {
fmt.println("Error: failed to allocate buffer for deserialization") fmt.eprintln("Error: failed to allocate buffer for deserialization")
return false return false
} }
copy(buf[:len(plaintext)], plaintext) copy(buf[:len(plaintext)], plaintext)
@@ -144,7 +144,7 @@ db_restore_from_encrypted :: proc(db: ^Db, data_path: string) -> bool {
rc := sqlite.deserialize(db.conn, "main", buf, n, n, flags) rc := sqlite.deserialize(db.conn, "main", buf, n, n, flags)
if rc != sqlite.OK { if rc != sqlite.OK {
sqlite.free(buf) sqlite.free(buf)
fmt.printf("Error deserializing database: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error deserializing database: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
@@ -167,14 +167,14 @@ db_close :: proc(db: ^Db) {
if db.changed && len(db.cfg.keys) > 0 { if db.changed && len(db.cfg.keys) > 0 {
rc := sqlite.exec(db.conn, "VACUUM", nil, nil, nil) rc := sqlite.exec(db.conn, "VACUUM", nil, nil, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error vacuuming database: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error vacuuming database: %s\n", sqlite.errmsg(db.conn))
return return
} }
sz: i64 sz: i64
data := sqlite.serialize(db.conn, "main", &sz, 0) data := sqlite.serialize(db.conn, "main", &sz, 0)
if data == nil { if data == nil {
fmt.println("Error: failed to serialize database") fmt.eprintln("Error: failed to serialize database")
return return
} }
defer sqlite.free(data) defer sqlite.free(data)
@@ -195,7 +195,7 @@ db_close :: proc(db: ^Db) {
write_err := os.write_entire_file(data_path, encrypted) write_err := os.write_entire_file(data_path, encrypted)
delete(encrypted) delete(encrypted)
if write_err != nil { if write_err != nil {
fmt.printf("Error writing encrypted database: %v\n", write_err) fmt.eprintf("Error writing encrypted database: %v\n", write_err)
return return
} }
@@ -214,7 +214,7 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) {
nil, nil,
) )
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error preparing query: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error preparing query: %s\n", sqlite.errmsg(db.conn))
return []EnvFile{}, false return []EnvFile{}, false
} }
defer sqlite.finalize(stmt) defer sqlite.finalize(stmt)
@@ -229,7 +229,7 @@ db_list :: proc(db: ^Db) -> ([]EnvFile, bool) {
break break
} }
if rc != sqlite.ROW { if rc != sqlite.ROW {
fmt.printf("Error stepping query: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error stepping query: %s\n", sqlite.errmsg(db.conn))
#no_bounds_check return results[:], false #no_bounds_check return results[:], false
} }
@@ -282,7 +282,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
stmt: sqlite.Stmt stmt: sqlite.Stmt
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil) rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error preparing insert: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error preparing insert: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
defer sqlite.finalize(stmt) defer sqlite.finalize(stmt)
@@ -292,7 +292,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
defer delete(cpath) defer delete(cpath)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding path: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
@@ -300,7 +300,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
defer delete(cremotes) defer delete(cremotes)
rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil) rc = sqlite.bind_text(stmt, 2, cremotes, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding remotes: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding remotes: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
@@ -308,7 +308,7 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
defer delete(csha) defer delete(csha)
rc = sqlite.bind_text(stmt, 3, csha, -1, nil) rc = sqlite.bind_text(stmt, 3, csha, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding sha256: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding sha256: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
@@ -316,13 +316,13 @@ db_insert :: proc(db: ^Db, file: EnvFile) -> bool {
defer delete(ccontents) defer delete(ccontents)
rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil) rc = sqlite.bind_text(stmt, 4, ccontents, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding contents: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding contents: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc != sqlite.DONE { if rc != sqlite.DONE {
fmt.printf("Error inserting: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error inserting: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
@@ -340,7 +340,7 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) {
stmt: sqlite.Stmt stmt: sqlite.Stmt
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil) rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error preparing fetch: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error preparing fetch: %s\n", sqlite.errmsg(db.conn))
return EnvFile{}, false return EnvFile{}, false
} }
defer sqlite.finalize(stmt) defer sqlite.finalize(stmt)
@@ -351,16 +351,16 @@ db_fetch :: proc(db: ^Db, path: string) -> (EnvFile, bool) {
defer delete(cpath, allocator) defer delete(cpath, allocator)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding path: %s\n", sqlite.errmsg(db.conn))
return EnvFile{}, false return EnvFile{}, false
} }
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc == sqlite.DONE { if rc == sqlite.DONE {
fmt.printf("No file found with path: %s\n", path) fmt.eprintf("No file found with path: %s\n", path)
return EnvFile{}, false return EnvFile{}, false
} }
if rc != sqlite.ROW { if rc != sqlite.ROW {
fmt.printf("Error fetching: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error fetching: %s\n", sqlite.errmsg(db.conn))
return EnvFile{}, false return EnvFile{}, false
} }
@@ -406,7 +406,7 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
stmt: sqlite.Stmt stmt: sqlite.Stmt
rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil) rc := sqlite.prepare_v2(db.conn, sql, -1, &stmt, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error preparing delete: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error preparing delete: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
defer sqlite.finalize(stmt) defer sqlite.finalize(stmt)
@@ -415,17 +415,17 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
defer delete(cpath) defer delete(cpath)
rc = sqlite.bind_text(stmt, 1, cpath, -1, nil) rc = sqlite.bind_text(stmt, 1, cpath, -1, nil)
if rc != sqlite.OK { if rc != sqlite.OK {
fmt.printf("Error binding path: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error binding path: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
rc = sqlite.step(stmt) rc = sqlite.step(stmt)
if rc != sqlite.DONE { if rc != sqlite.DONE {
fmt.printf("Error deleting: %s\n", sqlite.errmsg(db.conn)) fmt.eprintf("Error deleting: %s\n", sqlite.errmsg(db.conn))
return false return false
} }
if sqlite.changes(db.conn) == 0 { if sqlite.changes(db.conn) == 0 {
fmt.printf("No file found with path: %s\n", path) fmt.eprintf("No file found with path: %s\n", path)
return false return false
} }
@@ -437,7 +437,7 @@ db_delete :: proc(db: ^Db, path: string) -> bool {
new_env_file :: proc(path: string) -> (EnvFile, bool) { new_env_file :: proc(path: string) -> (EnvFile, bool) {
abs_path, abs_err := filepath.abs(path) abs_path, abs_err := filepath.abs(path)
if abs_err != nil { if abs_err != nil {
fmt.printf("Error getting absolute path: %v\n", abs_err) fmt.eprintf("Error getting absolute path: %v\n", abs_err)
return EnvFile{}, false return EnvFile{}, false
} }
@@ -448,7 +448,7 @@ new_env_file :: proc(path: string) -> (EnvFile, bool) {
data, read_err := os.read_entire_file_from_path(abs_path, context.allocator) data, read_err := os.read_entire_file_from_path(abs_path, context.allocator)
if read_err != nil { if read_err != nil {
fmt.printf("Error reading file %s: %v\n", abs_path, read_err) fmt.eprintf("Error reading file %s: %v\n", abs_path, read_err)
return EnvFile{}, false return EnvFile{}, false
} }
@@ -631,7 +631,7 @@ to_cstring :: proc {
string_to_cstring :: proc(s: string, allocator := context.allocator) -> cstring { string_to_cstring :: proc(s: string, allocator := context.allocator) -> cstring {
cs, err := strings.clone_to_cstring(s, allocator) cs, err := strings.clone_to_cstring(s, allocator)
if err != nil { if err != nil {
fmt.printf("Failed to convert string to cstring: %v\n", err) fmt.eprintf("Failed to convert string to cstring: %v\n", err)
panic("Allocation Exception") panic("Allocation Exception")
} }
return cs return cs
@@ -641,7 +641,7 @@ string_to_cstring :: proc(s: string, allocator := context.allocator) -> cstring
clone_cstring :: proc(c: cstring, allocator := context.allocator) -> string { clone_cstring :: proc(c: cstring, allocator := context.allocator) -> string {
str, err := strings.clone_from_cstring(c, allocator) str, err := strings.clone_from_cstring(c, allocator)
if err != nil { if err != nil {
fmt.printf("Failed to convert string to cstring: %v\n", err) fmt.eprintf("Failed to convert string to cstring: %v\n", err)
delete(str) delete(str)
panic("Allocation Exception") panic("Allocation Exception")
} }