mariadb/windows/tests/test-ftruncate.c
Yoni Fogel 5f68cd8242 [t:2216] Merge/windows port of #2216
git-svn-id: file:///svn/toku/tokudb@18191 c7de825b-a66e-492c-adef-691d508d4ae1
2013-04-16 23:59:01 -04:00

60 lines
1.4 KiB
C

#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <toku_assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#if 0 && TOKU_WINDOWS
#include <windows.h>
static int ftruncate(int fd, uint64_t offset) {
HANDLE h = (HANDLE) _get_osfhandle(fd);
printf("%s:%d %p\n", __FILE__, __LINE__, h); fflush(stdout);
if (h == INVALID_HANDLE_VALUE)
return -1;
int r = _lseeki64(fd, 0, SEEK_SET);
printf("%s:%d %d\n", __FILE__, __LINE__, r); fflush(stdout);
if (r != 0)
return -2;
BOOL b = SetEndOfFile(h);
printf("%s:%d %d\n", __FILE__, __LINE__, b); fflush(stdout);
if (!b)
return -3;
return 0;
}
#endif
int test_main(int argc, char *const argv[]) {
int r;
int fd;
fd = open("test-file-truncate", O_CREAT+O_RDWR+O_TRUNC, S_IREAD+S_IWRITE);
assert(fd != -1);
int i;
for (i=0; i<32; i++) {
char junk[4096];
memset(junk, 0, sizeof junk);
toku_os_full_write(fd, junk, sizeof junk);
}
toku_struct_stat filestat;
r = toku_fstat(fd, &filestat);
assert(r == 0);
printf("orig size %lu\n", (unsigned long) filestat.st_size); fflush(stdout);
r = ftruncate(fd, 0);
assert(r == 0);
r = toku_fstat(fd, &filestat);
assert(r == 0);
printf("truncated size %lu\n", (unsigned long) filestat.st_size); fflush(stdout);
assert(filestat.st_size == 0);
return 0;
}