/**
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is part of the mingw-w64 runtime package.
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 */
#include <stdio.h>
#include <io.h>
#include <errno.h>

static int __cdecl emu__fseeki64(FILE *stream, __int64 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);
}

#define RETT int
#define FUNC _fseeki64
#define ARGS FILE *stream, __int64 offset, int whence
#define CALL stream, offset, whence
#include "msvcrt_or_emu_glue.h"

int __attribute__ ((alias ("_fseeki64"))) __cdecl fseeko64(FILE *stream, _off64_t offset, int whence);
extern int __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(_fseeki64))))) (__cdecl *__MINGW_IMP_SYMBOL(fseeko64))(FILE *stream, _off64_t offset, int whence);
