Git 2.44-rc2
[git/gitster.git] / t / helper / test-truncate.c
blob3931deaec7dcdaec9789bc03e09f0ae5cb3b0d3e
1 #include "test-tool.h"
2 #include "git-compat-util.h"
4 /*
5 * Truncate a file to the given size.
6 */
7 int cmd__truncate(int argc, const char **argv)
9 char *p = NULL;
10 uintmax_t sz = 0;
11 int fd = -1;
13 if (argc != 3)
14 die("expected filename and size");
16 sz = strtoumax(argv[2], &p, 0);
17 if (*p)
18 die("invalid size");
20 fd = xopen(argv[1], O_WRONLY | O_CREAT, 0600);
22 if (ftruncate(fd, (off_t) sz) < 0)
23 die_errno("failed to truncate file");
24 return 0;