Changeset: 4acd311cfbc9 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4acd311cfbc9 Modified Files: NT/monetdb_config.h.in clients/Tests/exports.stable.out configure.ag gdk/gdk_posix.c gdk/gdk_posix.h gdk/gdk_storage.c Branch: default Log Message:
merged diffs (169 lines): diff --git a/NT/monetdb_config.h.in b/NT/monetdb_config.h.in --- a/NT/monetdb_config.h.in +++ b/NT/monetdb_config.h.in @@ -148,7 +148,8 @@ #define HAVE_FTIME 1 /* Define to 1 if you have the `ftruncate' function. */ -/* #undef HAVE_FTRUNCATE */ +#define HAVE_FTRUNCATE 1 +#define ftruncate(fd, sz) (_chsize_s((fd), (__int64) (sz)) == 0 ? 0 : -1) /* Does your compiler support function attributes (__attribute__)? */ /* #undef HAVE_FUNCTION_ATTRIBUTES */ diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -421,7 +421,6 @@ int escapedStrlen(const char *src); int fltFromStr(const char *src, int *len, flt **dst); int fltToStr(str *dst, int *len, const flt *src); const flt flt_nil; -int ftruncate(int fd, off_t size); char *get_bin_path(void); int gettimeofday(struct timeval *tv, int *ignore_zone); int gprof_pthread_create(pthread_t *__restrict, __const pthread_attr_t *__restrict, void *( *fcn)(void *), void *__restrict); diff --git a/configure.ag b/configure.ag --- a/configure.ag +++ b/configure.ag @@ -2710,7 +2710,6 @@ AC_CHECK_FUNCS([\ fpclassify \ fsync \ ftime \ - ftruncate \ getexecname \ getlogin \ getopt \ diff --git a/gdk/gdk_posix.c b/gdk/gdk_posix.c --- a/gdk/gdk_posix.c +++ b/gdk/gdk_posix.c @@ -519,7 +519,6 @@ MT_mremap(const char *path, int mode, vo /* size not too big yet or * anonymous, try to make new * anonymous mmap and copy - * data over */ p = mmap(NULL, *new_size, prot, flags, fd, 0); @@ -544,9 +543,7 @@ MT_mremap(const char *path, int mode, vo return NULL; if (write(fd, old_address, old_size) < 0 || - lseek(fd, *new_size - 1, - SEEK_SET) < 0 || - write(fd, "\0", 1) < 0) { + ftruncate(fd, *new_size) < 0) { close(fd); return NULL; } @@ -854,32 +851,6 @@ MT_path_absolute(const char *pathname) } -#ifndef HAVE_FTRUNCATE -int -ftruncate(int fd, off_t size) -{ - HANDLE hfile; - unsigned int curpos; - - if (fd < 0) - return -1; - - hfile = (HANDLE) _get_osfhandle(fd); - curpos = SetFilePointer(hfile, 0, NULL, FILE_CURRENT); - if (curpos == 0xFFFFFFFF || - SetFilePointer(hfile, (LONG) size, NULL, FILE_BEGIN) == 0xFFFFFFFF || - !SetEndOfFile(hfile)) { - int error = GetLastError(); - - if (error && error != ERROR_INVALID_HANDLE) - SetLastError(ERROR_OPEN_FAILED); /* enforce EIO */ - return -1; - } - - return 0; -} -#endif - #ifndef HAVE_GETTIMEOFDAY static int nodays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; diff --git a/gdk/gdk_posix.h b/gdk/gdk_posix.h --- a/gdk/gdk_posix.h +++ b/gdk/gdk_posix.h @@ -252,10 +252,6 @@ gdk_export int win_mkdir(const char *, c #define link win_link #endif -#ifndef HAVE_FTRUNCATE -gdk_export int ftruncate(int fd, off_t size); -#endif - #endif #define _errno win_errno diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c --- a/gdk/gdk_storage.c +++ b/gdk/gdk_storage.c @@ -242,11 +242,8 @@ GDKextendf(int fd, off_t size) return -1; } /* if necessary, extend the underlying file */ - if (stb.st_size < size && - (lseek(fd, size - 1, SEEK_SET) < 0 || - write(fd, "\0", 1) < 0)) { - return -1; - } + if (stb.st_size < size) + return ftruncate(fd, size); return 0; } #endif @@ -254,34 +251,26 @@ GDKextendf(int fd, off_t size) int GDKextend(const char *fn, size_t size) { - FILE *fp; int t0 = 0; IODEBUG t0 = GDKms(); - if ((fp = fopen(fn, "rb+")) == NULL) +#ifdef WIN32 + { + int fd, rt; + + if ((fd = open(fn, O_RDWR)) < 0) + return -1; + rt = _chsize_s(fd, (__int64) size); + close(fd); + if (rt != 0) + return -1; + } +#else + if (truncate(fn, (off_t) size) < 0) return -1; -#if defined(_WIN64) - if (_fseeki64(fp, (ssize_t) size - 1, SEEK_SET) < 0) - goto bailout; -#elif defined(HAVE_FSEEKO) - if (fseeko(fp, (off_t) size - 1, SEEK_SET) < 0) - goto bailout; -#else - if (fseek(fp, size - 1, SEEK_SET) < 0) - goto bailout; #endif - if (fputc('\n', fp) < 0) - goto bailout; - if (fflush(fp) < 0) - goto bailout; - if (fclose(fp) < 0) - return -1; IODEBUG fprintf(stderr, "#GDKextend %s " SZFMT " %dms\n", fn, size, GDKms() - t0); return 0; - bailout: - fclose(fp); - IODEBUG fprintf(stderr, "#GDKextend %s failed " SZFMT " %dms\n", fn, size, GDKms() - t0); - return -1; } /* _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list