2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
16 extern const char *__progname
;
20 main(int argc
, char **argv
)
23 fprintf(stderr
, "usage: %s <file> <size>\n", __progname
);
28 if (stat(argv
[1], &st
) != 0) {
29 fprintf(stderr
, "%s: cannot stat file \"%s\": %s\n", __progname
,
30 argv
[1], strerror(errno
));
34 off_t newSize
= strtoll(argv
[2], NULL
, 0);
36 printf("size %10Ld\n", st
.st_size
);
37 printf("wanted %10Ld\n", newSize
);
38 printf("Do you really want to truncate the file [y/N]? ");
42 if (fgets(yes
, sizeof(yes
), stdin
) == NULL
|| tolower(yes
[0]) != 'y')
45 if (truncate(argv
[1], newSize
) != 0) {
46 fprintf(stderr
, "%s: cannot truncate file \"%s\": %s\n", __progname
,
47 argv
[1], strerror(errno
));