1 /* Windows support code to wrap differences between different
2 versions of the Microsoft C libaries.
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
31 /* The D runtime library defines stdin, stdout, and stderr as extern(C) symbols
32 in the core.stdc.stdio module, and require initializing at start-up. */
33 __attribute__((weakref ("stdin")))
34 static FILE *core_stdc_stdin
;
36 __attribute__((weakref ("stdout")))
37 static FILE *core_stdc_stdout
;
39 __attribute__((weakref ("stderr")))
40 static FILE *core_stdc_stderr
;
42 /* Set to 1 if runtime is using libucrt.dll. */
43 unsigned char msvcUsesUCRT
;
48 core_stdc_stdin
= stdin
;
49 core_stdc_stdout
= stdout
;
50 core_stdc_stderr
= stderr
;
52 #if __MSVCRT_VERSION__ >= 0xE00
57 /* Phobos std.stdio module assumes these functions are present at link time,
58 and not absent or macros. */
63 _fgetc_nolock (FILE *fp
)
68 const int c
= *fp
->_ptr
;
76 #endif /* _fgetc_nolock */
82 _fputc_nolock (int c
, FILE *fp
)
92 return _flsbuf (c
, fp
);
95 #endif /* _fputc_nolock */
103 fseek (fp
, 0, SEEK_SET
);
104 fp
->_flag
&= ~_IOERR
;
115 fp
->_flag
&= ~(_IOERR
| _IOEOF
);
118 #endif /* clearerr */
126 return fp
->_flag
& _IOEOF
;
137 return fp
->_flag
& _IOERR
;
153 /* Phobos std.stdio module has a dependency on the UCRT library, so provide
154 stubs that forward to the nearest equivalent. */
155 #if __MSVCRT_VERSION__ < 0x800
158 _fgetwc_nolock (FILE *fp
)
164 _fputwc_nolock (wchar_t c
, FILE *fp
)
166 return fputwc(c
, fp
);
169 #endif /* __MSVCRT_VERSION__ < 0x800*/