struct utimbuf times;
static const int numfiles = sizeof(files) / sizeof(files[0]);
int i;
- int fd;
for (i = 0; i < numfiles; ++i) {
- fd = open(files[i].name, O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
/*
* Note: Have to write at least one byte to the file.
* cpio doesn't bother reading the file if it's zero length,
* so the atime never gets changed in that case, which
* makes the tests below rather pointless.
*/
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile(files[i].name, 0644, "a");
/* If utime() isn't supported on your platform, just
* #ifdef this section out. Most of the test below is
{
struct stat st;
int r;
- int f;
- char buff[64];
+ char *p;
/* Create all of the test files. */
test_create();
/* Sanity check; verify that atimes really do get modified. */
- f = open(files[0].name, O_RDONLY);
- assertEqualInt(1, read(f,buff, 1));
- assertEqualInt(0, close(f));
+ assert((p = slurpfile(NULL, "f0")) != NULL);
+ free(p);
assertEqualInt(0, stat("f0", &st));
if (st.st_atime == files[0].atime_sec) {
skipping("Cannot verify -a option\n"
DEFINE_TEST(test_option_l)
{
struct stat st, st2;
- int fd;
int r;
/* Create a file. */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile("f", 0644, "a");
/* Stat it. */
assertEqualInt(0, stat("f", &st));
DEFINE_TEST(test_option_lzma)
{
char *p;
- int fd;
int r;
size_t s;
/* Create a file. */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile("f", 0644, "a");
/* Archive it with lzma compression. */
r = systemf("echo f | %s -o --lzma >archive.out 2>archive.err",
struct utimbuf times;
char *p;
size_t s;
- int fd;
int r;
/* Create a file. */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile("f", 0644, "a");
/* Copy the file to the "copy" dir. */
r = systemf("echo f | %s -pd copy >copy.out 2>copy.err",
assertEqualMem(p, "a", 1);
/* Recreate the file with a single "b" */
- fd = open("f", O_CREAT | O_TRUNC | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "b", 1));
- close(fd);
+ assertMakeFile("f", 0644, "b");
/* Set the mtime to the distant past. */
memset(×, 0, sizeof(times));
DEFINE_TEST(test_option_y)
{
char *p;
- int fd;
int r;
size_t s;
/* Create a file. */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile("f", 0644, "a");
/* Archive it with bzip2 compression. */
r = systemf("echo f | %s -oy >archive.out 2>archive.err",
DEFINE_TEST(test_option_z)
{
char *p;
- int fd;
int r;
size_t s;
/* Create a file. */
- fd = open("f", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(1, write(fd, "a", 1));
- close(fd);
+ assertMakeFile("f", 0644, "a");
/* Archive it with gzip compression. */
r = systemf("echo f | %s -oz >archive.out 2>archive.err",
DEFINE_TEST(test_passthrough_dotdot)
{
struct stat st;
- int fd, r;
- int filelist;
+ int r;
+ FILE *filelist;
assertUmask(0);
/*
* Create an assortment of files on disk.
*/
- filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+ filelist = fopen("filelist", "w");
/* Directory. */
assertMakeDir("dir", 0755);
assertChdir("dir");
- write(filelist, ".\n", 2);
+ fprintf(filelist, ".\n");
/* File with 10 bytes content. */
- fd = open("file", O_CREAT | O_WRONLY, 0642);
- assert(fd >= 0);
- assertEqualInt(10, write(fd, "123456789", 10));
- close(fd);
- write(filelist, "file\n", 5);
+ assertMakeFile("file", 0642, "1234567890");
+ fprintf(filelist, "file\n");
/* All done. */
- close(filelist);
+ fclose(filelist);
/*
DEFINE_TEST(test_passthrough_reverse)
{
struct stat st;
- int fd, r;
- int filelist;
+ int r;
+ FILE *filelist;
assertUmask(0);
/*
* Create an assortment of files on disk.
*/
- filelist = open("filelist", O_CREAT | O_WRONLY, 0644);
+ filelist = fopen("filelist", "w");
/* Directory. */
assertMakeDir("dir", 0743);
/* File with 10 bytes content. */
- fd = open("dir/file", O_CREAT | O_WRONLY, 0644);
- assert(fd >= 0);
- assertEqualInt(10, write(fd, "123456789", 10));
- close(fd);
- write(filelist, "dir/file\n", 9);
+ assertMakeFile("dir/file", 0644, "1234567890");
+ fprintf(filelist, "dir/file\n");
/* Write dir last. */
- write(filelist, "dir\n", 4);
+ fprintf(filelist, "dir\n");
/* All done. */
- close(filelist);
+ fclose(filelist);
/*