master
 1/**
 2 * This file has no copyright assigned and is placed in the Public Domain.
 3 * This file is part of the mingw-w64 runtime package.
 4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 5 */
 6#include <stdio.h>
 7#include <io.h>
 8#include <errno.h>
 9
10int fseeko64 (FILE* stream, _off64_t offset, int whence)
11{
12  fpos_t pos;
13  if (whence == SEEK_CUR)
14    {
15      /* If stream is invalid, fgetpos sets errno. */
16      if (fgetpos (stream, &pos))
17        return (-1);
18      pos += (fpos_t) offset;
19    }
20  else if (whence == SEEK_END)
21    {
22      /* If writing, we need to flush before getting file length.  */
23      fflush (stream);
24      pos = (fpos_t) (_filelengthi64 (_fileno (stream)) + offset);
25    }
26  else if (whence == SEEK_SET)
27    pos = (fpos_t) offset;
28  else
29    {
30      errno = EINVAL;
31      return (-1);
32    }
33  return fsetpos (stream, &pos);
34}