Add touchf(), formatted version of touch()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2021-03-26 12:39:32 +01:00
1 parent 733a7062e9
commit 2040569f0a
5 files changed
+97 -3

No files matched your search

+24 -2
View File
@@ -6,6 +6,8 @@
#include "check.h"
#define FMT "%s-bar"
int verbose = 0;
@@ -32,10 +34,30 @@ static int mtime(char *file)
ret = timespec_newer(&after.st_mtim, &before.st_mtim);
PRINT("Before: %s\n", timespec2str(&before.st_mtim, buf, sizeof(buf)));
PRINT("After : %s\n", timespec2str(&after.st_mtim, buf, sizeof(buf)));
erase(file);
return !ret;
}
static int formatted(char *file)
{
char vrfy[80];
if (touchf(FMT, file))
err(1, "Failed creating " FMT, file);
PRINT("Created " FMT "\n", file);
snprintf(vrfy, sizeof(vrfy), FMT, file);
if (!fexist(vrfy))
errx(1, "touchf() does not detect failure to create file " FMT, file);
PRINT("File " FMT " really does exist!\n", file);
erase(vrfy);
return 0;
}
int main(int argc, char *argv[])
{
int fd;
@@ -49,13 +71,13 @@ int main(int argc, char *argv[])
err(1, "Failed creating tempfile, %s", file);
close(fd);
return mtime(file);
return mtime(file) || formatted(file);
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* compile-command: "make pidfile && ./pidfile -v"
* compile-command: "make touch && ./touch -v"
* End:
*/