Skip to content

Commit

Permalink
Added _bytes_seek and _bytes_tell XDR methods
Browse files Browse the repository at this point in the history
On error xtc_seek now returns the system errno value, which is printed as
is. This is more informative and fixes an IndexError looking up the error
message, that occurred when xtc_seek failed and returned exdrNR.

Added testing for _bytes_seek and _bytes_tell, also beyond 4GB filesize
limits.
  • Loading branch information
mnmelo committed Jan 28, 2016
1 parent 00885ad commit 4b634b2
Show file tree
Hide file tree
Showing 5 changed files with 1,455 additions and 931 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ API Changes

Enhancement

* XDR file seeking errors now report system errno. (PR #678)
* Offsets reading for xtc/trr files has been sped up. (Issue #441)
* select_atoms now implicitly ORs multiple values after a keyword for
many types of selections (Issue #345)
Expand Down
11 changes: 9 additions & 2 deletions package/MDAnalysis/lib/formats/src/xdrfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <string.h>
#include <math.h>
#include <limits.h>
#include <errno.h>

/* get fixed-width types if we are using ANSI C99 */
#ifdef HAVE_STDINT_H
Expand Down Expand Up @@ -2607,7 +2608,13 @@ xdrstdio_getpos (XDR *xdrs)
static int
xdrstdio_setpos (XDR *xdrs, off_t pos, int whence)
{
return fseeko((FILE *) xdrs->x_private, pos, whence) < 0 ? exdrNR : exdrOK;
/* A reason for failure can be filesystem limits on allocation units,
* before the actual off_t overflow (ext3, with a 4K clustersize,
* has a 16TB limit).*/
/* We return errno relying on the fact that it is never set to 0 on
* success, which means that if an error occurrs it'll never be the same
* as exdrOK, and xdr_seek won't be confused.*/
return fseeko((FILE *) xdrs->x_private, pos, whence) < 0 ? errno : exdrOK;
}


Expand All @@ -2621,7 +2628,7 @@ int xdr_seek(XDRFILE *xd, int64_t pos, int whence)
/* Seeks to position in file */
{
int result;
if ((result = xdrstdio_setpos(xd->xdr, (off_t) pos, whence)) != exdrOK)
if ((result = xdrstdio_setpos(xd->xdr, (off_t) pos, whence)) != 0)
return result;

return exdrOK;
Expand Down
Loading

0 comments on commit 4b634b2

Please sign in to comment.