Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/helper/test-truncate.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 */ 7 int 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 }