windows file truncate

svn path=/trunk/boinc/; revision=9264
This commit is contained in:
David Anderson 2006-01-18 22:54:24 +00:00
parent ba9ba5ff01
commit 60ac02c663
2 changed files with 20 additions and 1 deletions

View File

@ -588,3 +588,9 @@ David 18 Jan 2006
error_numbers.h error_numbers.h
filesys.C,h filesys.C,h
util.C util.C
David 18 Jan 2006
- implement boinc_truncate() for Windows
lib/
filesys.C

View File

@ -276,7 +276,20 @@ int file_size(const char* path, double& size) {
} }
int boinc_truncate(const char* path, double size) { int boinc_truncate(const char* path, double size) {
int retval = truncate(path, (off_t)size); int retval;
#ifdef _WIN32
// the usual Windows nightmare.
// There's another function, SetEndOfFile(),
// that supposedly works with files over 2GB,
// but it uses HANDLES
//
int fd = _open(path, _O_RDWR, 0);
if (fd == -1) return ERR_TRUNCATE;
retval = _chsize(fd, (long)size);
_close(fd);
#else
retval = truncate(path, (off_t)size);
#endif
if (retval) return ERR_TRUNCATE; if (retval) return ERR_TRUNCATE;
return 0; return 0;
} }