Remove use of tempnam.

This commit is contained in:
Christoffer Lerno
2026-02-09 00:04:05 +01:00
parent 80ad0e02ad
commit 565b08846f
2 changed files with 9 additions and 10 deletions

View File

@@ -1,15 +1,13 @@
module std::io::file @if(env::LIBC &&& env::POSIX);
import libc;
import std::math, libc, std::io::path;
tlocal char[1024] buf;
fn String random_name()
{
ZString str = libc::tempnam(null, "randfile_");
String s = str.str_view();
buf[:s.len] = s[..];
libc::free(str);
return (String)buf[:s.len];
String filename = string::tformat("c3_test_file_%x", rand(0xFFFFFFF));
Path temp_dir = path::temp_directory(tmem).tappend(filename)!!;
return temp_dir.str_view();
}
fn void map_read_only() @test

View File

@@ -1,5 +1,5 @@
module std::io::file @test;
import std::io, libc;
import std::io, libc, std::math;
struct Data
{
@@ -59,9 +59,10 @@ fn void read_write_any()
char[1024] buf;
ZString zname = libc::tempnam(null, "testfile_");
defer libc::free(zname);
String name = zname.str_view();
String filename = string::tformat("c3_test_file_%x", rand(0xFFFFFFF));
Path temp_dir = path::temp_directory(tmem).tappend(filename)!!;
String name = temp_dir.str_view();
File file = file::open(name, "wb")!!;
io::write_any(&file, &data)!!;