mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add libc mktemp and tempnam. Update test.
This commit is contained in:
@@ -126,6 +126,7 @@ extern fn CInt memcmp(void* buf1, void* buf2, usz count);
|
||||
extern fn void* memcpy(void* dest, void* src, usz n);
|
||||
extern fn void* memmove(void* dest, void* src, usz n);
|
||||
extern fn void* memset(void* dest, CInt value, usz n);
|
||||
extern fn ZString mktemp(char* template) @cname(env::WIN32 ??? "_mktemp" : "mktemp");
|
||||
extern fn Time_t* mktime(Tm* time) @if(!env::WIN32);
|
||||
extern fn void perror(ZString string);
|
||||
extern fn CInt printf(ZString format, ...);
|
||||
@@ -177,6 +178,7 @@ extern fn CLong strtol(char* str, char** endptr, CInt base);
|
||||
extern fn CULong strtoul(char* str, char** endptr, CInt base);
|
||||
extern fn usz strxfrm(char* dest, ZString src, usz n);
|
||||
extern fn CInt system(ZString str);
|
||||
extern fn ZString tempnam(ZString dir, ZString prefix) @cname(env::WIN32 ??? "_tempnam" : "tempnam") @nodiscard;
|
||||
extern fn Time_t timegm(Tm* timeptr) @if(!env::WIN32 && !env::NETBSD);
|
||||
extern fn ZString tmpnam(char *buffer);
|
||||
extern fn CFile tmpfile();
|
||||
|
||||
@@ -5,7 +5,11 @@ tlocal char[1024] buf;
|
||||
|
||||
fn String random_name()
|
||||
{
|
||||
return libc::tmpnam(&buf).str_view();
|
||||
ZString str = libc::tempnam(null, "randfile_");
|
||||
String s = str.str_view();
|
||||
buf[:s.len] = s[..];
|
||||
libc::free(str);
|
||||
return (String)buf[:s.len];
|
||||
}
|
||||
|
||||
fn void map_read_only() @test
|
||||
|
||||
@@ -58,7 +58,10 @@ fn void read_write_any()
|
||||
data.hello = 0xCC;
|
||||
|
||||
char[1024] buf;
|
||||
String name = libc::tmpnam(&buf).str_view();
|
||||
|
||||
ZString zname = libc::tempnam(null, "testfile_");
|
||||
defer libc::free(zname);
|
||||
String name = zname.str_view();
|
||||
File file = file::open(name, "wb")!!;
|
||||
|
||||
io::write_any(&file, &data)!!;
|
||||
|
||||
Reference in New Issue
Block a user