Mail Archives: cygwin/2004/12/06/05:17:02
Win2kSP4+patches, cygwin1.dll 1.5.11, findutils 4.1.7-4
Test case below.
$ cat >truncate.c <<EOF
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int main(int argc, char **argv) {
off_t size;
char *endptr = argv[2];
if (argc != 3) {
fprintf(stderr, "usage: truncate path size\n");
exit(1);
}
errno = 0;
size = strtoull(argv[2], &endptr, 10);
if (!endptr || endptr == argv[2] || *endptr || size < 0 ||
(size == 0 && errno)) {
fprintf(stderr, "truncate: invalid size\n");
exit(1);
}
printf("truncating %s to %lld bytes\n", argv[1], size);
if (truncate(argv[1], size)) {
int saveerr = errno;
perror("truncate");
fprintf(stderr, "errno was %d\n", saveerr);
exit(1);
}
exit(0);
}
EOF
$ g++ truncate.c -o truncate.exe
$ touch aaa
$ ./truncate.exe aaa 2000000000
truncating aaa to 2000000000 bytes
$ ls -l aaa
-rw-r--r-- 1 sc0rp None 2000000000 Dec 6 10:54 aaa
$ find ./aaa -printf "%10s %p\n"
2000000000 ./aaa
$ ./truncate.exe aaa 3000000000
truncating aaa to 3000000000 bytes
$ ls -l aaa
-rw-r--r-- 1 sc0rp None 3000000000 Dec 6 10:54 aaa
$ find ./aaa -printf "%10s %p\n"
18446744072414584320 ./aaa
$ ./truncate.exe aaa 4700000000
truncating aaa to 4700000000 bytes
$ ls -l aaa
-rw-r--r-- 1 sc0rp None 4700000000 Dec 6 10:54 aaa
$ find ./aaa -printf "%10s %p\n"
405032704 ./aaa
-- Jacek.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -