mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Remove use of tempnam.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)!!;
|
||||
|
||||
Reference in New Issue
Block a user