#ifdef UNIX
#include <unistd.h>
#include <sys/mman.h>
+#include <sys/stat.h>
#endif
#include <string.h>
#endif
#ifdef UNIX
- /* No Unix-specific information at this point in time */
+ int fd;
#endif
} mmap_object;
static PyObject *
mmap_write_method (mmap_object * self,
- PyObject * args)
+ PyObject * args)
{
long length;
char * data;
#endif /* MS_WIN32 */
#ifdef UNIX
- return (Py_BuildValue ("l", self->size) );
+ {
+ struct stat buf;
+ if (-1 == fstat(self->fd, &buf)) {
+ PyErr_SetFromErrno(mmap_module_error);
+ return NULL;
+ }
+ return (Py_BuildValue ("l", buf.st_size) );
+ }
#endif /* UNIX */
}
if (m_obj == NULL) {return NULL;}
m_obj->size = (size_t) map_size;
m_obj->pos = (size_t) 0;
+ m_obj->fd = fd;
m_obj->data = mmap(NULL, map_size,
prot, flags,
fd, 0);