1 #include <windows.h>
2 #include <malloc.h>
3 #include <errno.h>
4 #include <msvcrt.h>
5 #include <io.h>
6
7 static errno_t __cdecl _int_chsize_s (int, long long);
8 static errno_t __cdecl _stub (int, long long);
9
10 errno_t __cdecl (*__MINGW_IMP_SYMBOL(_chsize_s))(int, long long) =
11 _stub;
12
13 static errno_t __cdecl
_stub(int fd,long long sz)14 _stub (int fd, long long sz)
15 {
16 errno_t __cdecl (*f)(int, long long) = __MINGW_IMP_SYMBOL(_chsize_s);
17
18 if (f == _stub)
19 {
20 f = (errno_t __cdecl (*)(int, long long))
21 GetProcAddress (__mingw_get_msvcrt_handle (), "_chsize_s");
22 if (!f)
23 f = _int_chsize_s;
24 __MINGW_IMP_SYMBOL(_chsize_s) = f;
25 }
26 return (*f)(fd, sz);
27 }
28
29 errno_t __cdecl
_chsize_s(int fd,long long sz)30 _chsize_s (int fd, long long sz)
31 {
32 return _stub (fd, sz);
33 }
34
35 static errno_t __cdecl
_int_chsize_s(int fd,long long sz)36 _int_chsize_s (int fd, long long sz)
37 {
38 if (sz > 0x7fffffffll)
39 {
40 /* We can't set file bigger as 2GB, so return EACCES. */
41 return (errno = EACCES);
42 }
43 if (!_chsize (fd, sz))
44 return 0;
45 return errno;
46 }
47