mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Remove use of tempnam.
This commit is contained in:
@@ -1,15 +1,13 @@
|
|||||||
module std::io::file @if(env::LIBC &&& env::POSIX);
|
module std::io::file @if(env::LIBC &&& env::POSIX);
|
||||||
import libc;
|
import std::math, libc, std::io::path;
|
||||||
|
|
||||||
tlocal char[1024] buf;
|
tlocal char[1024] buf;
|
||||||
|
|
||||||
fn String random_name()
|
fn String random_name()
|
||||||
{
|
{
|
||||||
ZString str = libc::tempnam(null, "randfile_");
|
String filename = string::tformat("c3_test_file_%x", rand(0xFFFFFFF));
|
||||||
String s = str.str_view();
|
Path temp_dir = path::temp_directory(tmem).tappend(filename)!!;
|
||||||
buf[:s.len] = s[..];
|
return temp_dir.str_view();
|
||||||
libc::free(str);
|
|
||||||
return (String)buf[:s.len];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn void map_read_only() @test
|
fn void map_read_only() @test
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module std::io::file @test;
|
module std::io::file @test;
|
||||||
import std::io, libc;
|
import std::io, libc, std::math;
|
||||||
|
|
||||||
struct Data
|
struct Data
|
||||||
{
|
{
|
||||||
@@ -59,9 +59,10 @@ fn void read_write_any()
|
|||||||
|
|
||||||
char[1024] buf;
|
char[1024] buf;
|
||||||
|
|
||||||
ZString zname = libc::tempnam(null, "testfile_");
|
String filename = string::tformat("c3_test_file_%x", rand(0xFFFFFFF));
|
||||||
defer libc::free(zname);
|
Path temp_dir = path::temp_directory(tmem).tappend(filename)!!;
|
||||||
String name = zname.str_view();
|
|
||||||
|
String name = temp_dir.str_view();
|
||||||
File file = file::open(name, "wb")!!;
|
File file = file::open(name, "wb")!!;
|
||||||
|
|
||||||
io::write_any(&file, &data)!!;
|
io::write_any(&file, &data)!!;
|
||||||
|
|||||||
Reference in New Issue
Block a user