/*
copyright (c) 2012 Kazuki Iwamoto http://www.maid.org/ iwm@maid.org

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>


typedef int (__cdecl *stat64i32_t)(const char *, struct _stat64i32 *);
extern int (__cdecl *_imp___stat64)(const char *, struct _stat64 *);


static int __cdecl x_stat64i32 (const char *path, struct _stat64i32 *buffer)
{
  int ret;
  struct _stat64 buf;

  ret = (*_imp___stat64)(path, buffer ? &buf : NULL);
  if (ret == 0 && buffer)
    {
      buffer->st_dev = buf.st_dev;
      buffer->st_ino = buf.st_ino;
      buffer->st_mode = buf.st_mode;
      buffer->st_nlink = buf.st_nlink;
      buffer->st_uid = buf.st_uid;
      buffer->st_gid = buf.st_gid;
      buffer->st_rdev = buf.st_rdev;
      buffer->st_size = buf.st_size;
      buffer->st_atime = buf.st_atime;
      buffer->st_mtime = buf.st_mtime;
      buffer->st_ctime = buf.st_ctime;
    }
  return ret;
}


stat64i32_t _imp___stat64i32 = x_stat64i32;
