I've been trying to manage large binary data(7GB
) within python x86 original extension library.
But fseek
with SEEK_END
doesn't work well.
I put _FILE_OFFSET_BITS 64
macro. I also tried fseeko64
, but it raises an error.
With Less than 2GB files or using SEEK_CUR, SEEK_SET it's works fine.
I've been stuck for a couple of days. Could anybody give me ideas?
#define _GNU_SOURCE
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64
#include <Python.h>
#include "structmember.h"
#include <stdio.h>
static PyObject *
MyClass_load(MyClass* self, PyObject *args)
{
const char* file_path;
if (!PyArg_ParseTuple(args, "s", &file_path))
return NULL;
self->fp = fopen(file_path ,"rb");
if (self->fp == NULL) {
PyErr_SetString(PyExc_IOError, "File does not exist.");
return NULL;
}
off_t offset = 0;
if(fseek(self->fp, offset, SEEK_END) != 0){
printf("%s\n", strerror(errno)); // show "Invalid argument"
PyErr_SetString(PyExc_IOError, "Seek failed.");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
Environment:
- Windows 7 x64
- Python 2.7 x86
- MinGW GCC