interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / helper / test-truncate.c

28 lines · 470 bytes Raw Blame History
1#include "test-tool.h"
2#include "git-compat-util.h"
3
4/*
5 * Truncate a file to the given size.
6 */
7int cmd__truncate(int argc, const char **argv)
8{
9 char *p = NULL;
10 uintmax_t sz = 0;
11 int fd = -1;
12
13 if (argc != 3)
14 die("expected filename and size");
15
16 sz = strtoumax(argv[2], &p, 0);
17 if (*p)
18 die("invalid size");
19
20 fd = xopen(argv[1], O_WRONLY | O_CREAT, 0600);
21
22 if (ftruncate(fd, (off_t) sz) < 0)
23 die_errno("failed to truncate file");
24
25 close(fd);
26
27 return 0;
28}