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

Skip to content

Commit b855216

Browse files
committed
Changes to automatically enable large file support on some systems.
I believe this works on Linux (tested both on a system with large file support and one without it), and it may work on Solaris 2.7. The changes are twofold: (1) The configure script now boldly tries to set the two symbols that are recommended (for Solaris and Linux), and then tries a test script that does some simple seeking without writing. (2) The _portable_{fseek,ftell} functions are a little more systematic in how they try the different large file support options: first try fseeko/ftello, but only if off_t is large; then try fseek64/ftell64; then try hacking with fgetpos/fsetpos. I'm keeping my fingers crossed. The meaning of the HAVE_LARGEFILE_SUPPORT macro is not at all clear. I'll see if I can get it to work on Windows as well.
1 parent 2f0047a commit b855216

5 files changed

Lines changed: 496 additions & 374 deletions

File tree

Objects/fileobject.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,15 @@ file_close(PyFileObject *f)
208208
}
209209

210210

211-
/* An 8-byte off_t-like type */
212-
#if defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_OFF_T < 8 && SIZEOF_FPOS_T >= 8
211+
/* Our very own off_t-like type, 64-bit if possible */
212+
#if !defined(HAVE_LARGEFILE_SUPPORT)
213+
typedef off_t Py_off_t;
214+
#elif SIZEOF_OFF_T >= 8
215+
typedef off_t Py_off_t;
216+
#elif SIZEOF_FPOS_T >= 8
213217
typedef fpos_t Py_off_t;
214218
#else
215-
typedef off_t Py_off_t;
219+
#error "Large file support, but neither off_t nor fpos_t is large enough."
216220
#endif
217221

218222

@@ -221,13 +225,15 @@ typedef off_t Py_off_t;
221225
static int
222226
_portable_fseek(FILE *fp, Py_off_t offset, int whence)
223227
{
224-
#if defined(HAVE_FSEEKO)
228+
#if !defined(HAVE_LARGEFILE_SUPPORT)
229+
return fseek(fp, offset, whence);
230+
#elif defined(HAVE_FSEEKO) && SIZEOF_OFF_T >= 8
225231
return fseeko(fp, offset, whence);
226232
#elif defined(HAVE_FSEEK64)
227233
return fseek64(fp, offset, whence);
228234
#elif defined(__BEOS__)
229235
return _fseek(fp, offset, whence);
230-
#elif defined(HAVE_LARGEFILE_SUPPORT) && SIZEOF_FPOS_T >= 8
236+
#elif SIZEOF_FPOS_T >= 8
231237
/* lacking a 64-bit capable fseek(), use a 64-bit capable fsetpos()
232238
and fgetpos() to implement fseek()*/
233239
fpos_t pos;
@@ -245,7 +251,7 @@ _portable_fseek(FILE *fp, Py_off_t offset, int whence)
245251
}
246252
return fsetpos(fp, &offset);
247253
#else
248-
return fseek(fp, offset, whence);
254+
#error "Large file support, but no way to fseek."
249255
#endif
250256
}
251257

@@ -256,17 +262,19 @@ _portable_fseek(FILE *fp, Py_off_t offset, int whence)
256262
static Py_off_t
257263
_portable_ftell(FILE* fp)
258264
{
259-
#if SIZEOF_FPOS_T >= 8 && defined(HAVE_LARGEFILE_SUPPORT)
265+
#if !defined(HAVE_LARGEFILE_SUPPORT)
266+
return ftell(fp);
267+
#elif defined(HAVE_FTELLO) && SIZEOF_OFF_T >= 8
268+
return ftello(fp);
269+
#elif defined(HAVE_FTELL64)
270+
return ftell64(fp);
271+
#elif SIZEOF_FPOS_T >= 8
260272
fpos_t pos;
261273
if (fgetpos(fp, &pos) != 0)
262274
return -1;
263275
return pos;
264-
#elif defined(HAVE_FTELLO) && defined(HAVE_LARGEFILE_SUPPORT)
265-
return ftello(fp);
266-
#elif defined(HAVE_FTELL64) && defined(HAVE_LARGEFILE_SUPPORT)
267-
return ftell64(fp);
268276
#else
269-
return ftell(fp);
277+
#error "Large file support, but no way to ftell."
270278
#endif
271279
}
272280

acconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
/* Defined on Solaris to see additional function prototypes. */
2626
#undef __EXTENSIONS__
2727

28+
/* This must be set to 64 on some systems to enable large file support */
29+
#undef _FILE_OFFSET_BITS
30+
2831
/* Define if getpgrp() must be called as getpgrp(0). */
2932
#undef GETPGRP_HAVE_ARG
3033

@@ -107,6 +110,9 @@
107110
/* Define if the compiler provides a wchar.h header file. */
108111
#undef HAVE_WCHAR_H
109112

113+
/* This must be defined on some systems to enable large file support */
114+
#undef _LARGEFILE_SOURCE
115+
110116
/* Define if you want to have a Unicode type. */
111117
#undef Py_USING_UNICODE
112118

0 commit comments

Comments
 (0)