]> granicus.if.org Git - python/commitdiff
Enable large file support on Win32 systems.
authorTim Peters <tim.peters@gmail.com>
Thu, 6 Sep 2001 00:32:15 +0000 (00:32 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 6 Sep 2001 00:32:15 +0000 (00:32 +0000)
Curious:  the MS docs say stati64 etc are supported even on Win95, but
Win95 doesn't support a filesystem that allows partitions > 2 Gb.

test_largefile:  This was opening its test file in text mode.  I have no
idea how that worked under Win64, but it sure needs binary mode on Win98.
BTW, on Win98 test_largefile runs quickly (under a second).

Lib/test/test_largefile.py
Misc/NEWS
Modules/posixmodule.c
Objects/fileobject.c
PC/pyconfig.h

index 54fd274bcad397a343f01b0914d5d85d4996b171..3f3b8f16fc0c222852b7ebea18938f6f885bf5dd 100644 (file)
@@ -12,7 +12,7 @@ import os, struct, stat, sys
 
 
 # only run if the current system support large files
-f = open(test_support.TESTFN, 'w')
+f = open(test_support.TESTFN, 'wb')
 try:
     # 2**31 == 2147483648
     f.seek(2147483649L)
@@ -58,13 +58,13 @@ def expect(got_this, expect_this):
 
 if test_support.verbose:
     print 'create large file via seek (may be sparse file) ...'
-f = open(name, 'w')
+f = open(name, 'wb')
 f.seek(size)
 f.write('a')
 f.flush()
-expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
 if test_support.verbose:
     print 'check file size with os.fstat'
+expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
 f.close()
 if test_support.verbose:
     print 'check file size with os.stat'
@@ -72,7 +72,7 @@ expect(os.stat(name)[stat.ST_SIZE], size+1)
 
 if test_support.verbose:
     print 'play around with seek() and read() with the built largefile'
-f = open(name, 'r')
+f = open(name, 'rb')
 expect(f.tell(), 0)
 expect(f.read(1), '\000')
 expect(f.tell(), 1)
index 50ec64f581315e643c42d6129ee63da9f26e3c91..3fa2cb6b6f5fb3f88848635e58fc180ec5fd29ce 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -155,6 +155,12 @@ Tests
 
 Windows
 
+- Large file support is now enabled on Win32 platforms as well as on
+  Win64.  This means that, for example, you can use f.tell() and f.seek()
+  to manipulate files larger than 2 gigabytes (provided you have enough
+  disk space, and are using a Windows filesystem that supports large
+  partitions).
+
 - The w9xpopen hack is now used on Windows NT and 2000 too when COMPSPEC
   points to command.com (patch from Brian Quinlan).
 
index 5f6f21d39f9d0b232d23f22532505647aa59edec..0b4b76562c5eb228c6f495d93aa418d88338ce2e 100644 (file)
@@ -264,7 +264,7 @@ extern int lstat(const char *, struct stat *);
 
 /* choose the appropriate stat and fstat functions and return structs */
 #undef STAT
-#ifdef MS_WIN64
+#if defined(MS_WIN64) || defined(MS_WIN32)
 #      define STAT _stati64
 #      define FSTAT _fstati64
 #      define STRUCT_STAT struct _stati64
@@ -3491,7 +3491,7 @@ static PyObject *
 posix_lseek(PyObject *self, PyObject *args)
 {
        int fd, how;
-#ifdef MS_WIN64
+#if defined(MS_WIN64) || defined(MS_WIN32)
        LONG_LONG pos, res;
 #else
        off_t pos, res;
@@ -3518,7 +3518,7 @@ posix_lseek(PyObject *self, PyObject *args)
                return NULL;
 
        Py_BEGIN_ALLOW_THREADS
-#ifdef MS_WIN64
+#if defined(MS_WIN64) || defined(MS_WIN32)
        res = _lseeki64(fd, pos, how);
 #else
        res = lseek(fd, pos, how);
index f592e7af60bdb2456813f06c5910ff50150efed4..5909e99f47f75afdef1e46bce884f832c56cbbb3 100644 (file)
@@ -367,7 +367,7 @@ file_truncate(PyFileObject *f, PyObject *args)
        } else {
                Py_BEGIN_ALLOW_THREADS
                errno = 0;
-               ret = _chsize(fileno(f->f_fp), newsize);
+               ret = _chsize(fileno(f->f_fp), (long)newsize);
                Py_END_ALLOW_THREADS
                if (ret != 0) goto onioerror;
        }
index f2876056b9e9fbbae50e3889fdcdf9bdd01756a2..370b518a5e211b753b544ba618eb62230fccfc93 100644 (file)
@@ -313,6 +313,7 @@ typedef int pid_t;
 #      define HAVE_LARGEFILE_SUPPORT
 #elif defined(MS_WIN32)
 #      define PLATFORM "win32"
+#      define HAVE_LARGEFILE_SUPPORT
 #      ifdef _M_ALPHA
 #              define SIZEOF_VOID_P 8
 #              define SIZEOF_TIME_T 8