newlib/winsup/mingw/mingwex/stdio/fseeko64.c
Danny Smith 03ee0ba163 * mingwex/stdio/fseeko64.c (fseeko64): Flush stream before
getting filelength for SEEK_END.
2005-08-25 02:04:59 +00:00

31 lines
668 B
C
Executable File

#include <stdio.h>
#include <io.h>
#include <errno.h>
int __cdecl
fseeko64 (FILE* stream, off64_t offset, int whence)
{
fpos_t pos;
if (whence == SEEK_CUR)
{
/* If stream is invalid, fgetpos sets errno. */
if (fgetpos (stream, &pos))
return (-1);
pos += (fpos_t) offset;
}
else if (whence == SEEK_END)
{
/* If writing, we need to flush before getting file length. */
fflush (stream);
pos = (fpos_t) (_filelengthi64 (_fileno (stream)) + offset);
}
else if (whence == SEEK_SET)
pos = (fpos_t) offset;
else
{
errno = EINVAL;
return (-1);
}
return fsetpos (stream, &pos);
}