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:
parent
3a32039508
commit
4ad272015e
3 changed files with 43 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue