1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-14 04:51:05 +01:00

libutil: Implement createAnonymousTempFile

There are a lot of cases where we don't care about having
the temporary file linked anywhere at all -- just a descriptor is more
than enough.
This commit is contained in:
Sergei Zimmerman 2025-12-01 04:21:05 +03:00
parent 3a32039508
commit 4ad272015e
No known key found for this signature in database
3 changed files with 43 additions and 0 deletions

View file

@ -381,4 +381,21 @@ TEST(openFileEnsureBeneathNoSymlinks, works)
#endif
/* ----------------------------------------------------------------------------
* createAnonymousTempFile
* --------------------------------------------------------------------------*/
TEST(createAnonymousTempFile, works)
{
auto fd = createAnonymousTempFile();
writeFull(fd.get(), "test");
lseek(fd.get(), 0, SEEK_SET);
FdSource source{fd.get()};
EXPECT_EQ(source.drain(), "test");
lseek(fd.get(), 0, SEEK_END);
writeFull(fd.get(), "test");
lseek(fd.get(), 0, SEEK_SET);
EXPECT_EQ(source.drain(), "testtest");
}
} // namespace nix