X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/914fc88e61be54aed6b18205ff2775b48793a3b6..866f8763175ff60e4fa455b92b5eb660a12fe6c7:/RegressionTests/SecAtomicFile/SecAtomicFile.cpp diff --git a/RegressionTests/SecAtomicFile/SecAtomicFile.cpp b/RegressionTests/SecAtomicFile/SecAtomicFile.cpp new file mode 100644 index 00000000..5efea33b --- /dev/null +++ b/RegressionTests/SecAtomicFile/SecAtomicFile.cpp @@ -0,0 +1,62 @@ +// +// Copyright 2017 Apple. All rights reserved. +// + +#include "AtomicFile.h" +#include + +#if 0 +static void +fill_disk(const char *path) +{ + int fd = ::open(path, O_CREAT|O_RDWR, 0600); + if (fd < 0) + errx(1, "failed to create fill file"); + + uint8 buffer[1024] = {}; + ::memset(reinterpret_cast(buffer), 0x77, sizeof(buffer)); + + for (unsigned count = 0; count < 1000; count++) { + if (::write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) { + warn("write fill file failed"); + break; + } + } + if (close(fd) < 0) + warn("close fill file failed"); +} +#endif + +int +main(int argc, char **argv) +{ + int fail = 0; + + if (argc != 2) + errx(1, "argc != 2"); + + try { + AtomicFile file(argv[1]); + + RefPointer temp = file.write(); + + unsigned count = 0; + uint8 buffer[1024] = {}; + ::memset(reinterpret_cast(buffer), 0xff, sizeof(buffer)); + + for (count = 0; count < 1000; count++) { + temp->write(AtomicFile::FromEnd, 0, buffer, sizeof(buffer)); + } + + temp->commit(); + temp = NULL; + } catch (...) { + fail = 1; + } + if (fail) + errx(1, "failed to create new file"); + return 0; +} + + +