Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e13a56

Browse files
committed
Enable large file support on Win32 systems.
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).
1 parent 97f4a33 commit 6e13a56

5 files changed

Lines changed: 15 additions & 8 deletions

File tree

Lib/test/test_largefile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
# only run if the current system support large files
15-
f = open(test_support.TESTFN, 'w')
15+
f = open(test_support.TESTFN, 'wb')
1616
try:
1717
# 2**31 == 2147483648
1818
f.seek(2147483649L)
@@ -58,21 +58,21 @@ def expect(got_this, expect_this):
5858

5959
if test_support.verbose:
6060
print 'create large file via seek (may be sparse file) ...'
61-
f = open(name, 'w')
61+
f = open(name, 'wb')
6262
f.seek(size)
6363
f.write('a')
6464
f.flush()
65-
expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
6665
if test_support.verbose:
6766
print 'check file size with os.fstat'
67+
expect(os.fstat(f.fileno())[stat.ST_SIZE], size+1)
6868
f.close()
6969
if test_support.verbose:
7070
print 'check file size with os.stat'
7171
expect(os.stat(name)[stat.ST_SIZE], size+1)
7272

7373
if test_support.verbose:
7474
print 'play around with seek() and read() with the built largefile'
75-
f = open(name, 'r')
75+
f = open(name, 'rb')
7676
expect(f.tell(), 0)
7777
expect(f.read(1), '\000')
7878
expect(f.tell(), 1)

Misc/NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ Tests
155155

156156
Windows
157157

158+
- Large file support is now enabled on Win32 platforms as well as on
159+
Win64. This means that, for example, you can use f.tell() and f.seek()
160+
to manipulate files larger than 2 gigabytes (provided you have enough
161+
disk space, and are using a Windows filesystem that supports large
162+
partitions).
163+
158164
- The w9xpopen hack is now used on Windows NT and 2000 too when COMPSPEC
159165
points to command.com (patch from Brian Quinlan).
160166

Modules/posixmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ extern int lstat(const char *, struct stat *);
264264

265265
/* choose the appropriate stat and fstat functions and return structs */
266266
#undef STAT
267-
#ifdef MS_WIN64
267+
#if defined(MS_WIN64) || defined(MS_WIN32)
268268
# define STAT _stati64
269269
# define FSTAT _fstati64
270270
# define STRUCT_STAT struct _stati64
@@ -3491,7 +3491,7 @@ static PyObject *
34913491
posix_lseek(PyObject *self, PyObject *args)
34923492
{
34933493
int fd, how;
3494-
#ifdef MS_WIN64
3494+
#if defined(MS_WIN64) || defined(MS_WIN32)
34953495
LONG_LONG pos, res;
34963496
#else
34973497
off_t pos, res;
@@ -3518,7 +3518,7 @@ posix_lseek(PyObject *self, PyObject *args)
35183518
return NULL;
35193519

35203520
Py_BEGIN_ALLOW_THREADS
3521-
#ifdef MS_WIN64
3521+
#if defined(MS_WIN64) || defined(MS_WIN32)
35223522
res = _lseeki64(fd, pos, how);
35233523
#else
35243524
res = lseek(fd, pos, how);

Objects/fileobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ file_truncate(PyFileObject *f, PyObject *args)
367367
} else {
368368
Py_BEGIN_ALLOW_THREADS
369369
errno = 0;
370-
ret = _chsize(fileno(f->f_fp), newsize);
370+
ret = _chsize(fileno(f->f_fp), (long)newsize);
371371
Py_END_ALLOW_THREADS
372372
if (ret != 0) goto onioerror;
373373
}

PC/pyconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ typedef int pid_t;
313313
# define HAVE_LARGEFILE_SUPPORT
314314
#elif defined(MS_WIN32)
315315
# define PLATFORM "win32"
316+
# define HAVE_LARGEFILE_SUPPORT
316317
# ifdef _M_ALPHA
317318
# define SIZEOF_VOID_P 8
318319
# define SIZEOF_TIME_T 8

0 commit comments

Comments
 (0)