diff --git a/src/tests/system/libroot/posix/Jamfile b/src/tests/system/libroot/posix/Jamfile index b9725e4625..5d5e0c488e 100644 --- a/src/tests/system/libroot/posix/Jamfile +++ b/src/tests/system/libroot/posix/Jamfile @@ -24,6 +24,10 @@ SimpleTest sigsetjmp_test : sigsetjmp_test.c ; +SimpleTest truncate + : truncate.cpp +; + SimpleTest init_rld_after_fork_test : init_rld_after_fork_test.cpp ; diff --git a/src/tests/system/libroot/posix/truncate.cpp b/src/tests/system/libroot/posix/truncate.cpp new file mode 100644 index 0000000000..c0256760d3 --- /dev/null +++ b/src/tests/system/libroot/posix/truncate.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include +#include +#include +#include +#include + + +extern const char *__progname; + + +int +main(int argc, char **argv) +{ + if (argc < 3) { + fprintf(stderr, "usage: %s \n", __progname); + return 1; + } + + struct stat st; + if (stat(argv[1], &st) != 0) { + fprintf(stderr, "%s: cannot stat file \"%s\": %s\n", __progname, + argv[1], strerror(errno)); + return 1; + } + + off_t newSize = strtoll(argv[2], NULL, 0); + + printf("size %10Ld\n", st.st_size); + printf("wanted %10Ld\n", newSize); + printf("Do you really want to truncate the file [y/N]? "); + fflush(stdout); + + char yes[10]; + if (fgets(yes, sizeof(yes), stdin) == NULL || tolower(yes[0]) != 'y') + return 0; + + if (truncate(argv[1], newSize) != 0) { + fprintf(stderr, "%s: cannot truncate file \"%s\": %s\n", __progname, + argv[1], strerror(errno)); + return 1; + } + + return 0; +}