libphobos: Fix misspelling of msvcUsesUCRT (PR104659)
[official-gcc.git] / libphobos / libdruntime / config / mingw / msvc.c
blob348b2237ed5976f773e2dcb2fe8f42c18c6924a2
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
10 version.
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
15 for more details.
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/>. */
26 #ifdef __MINGW32__
27 #include <_mingw.h>
28 #endif
29 #include <stdio.h>
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;
45 void
46 init_msvc (void)
48 core_stdc_stdin = stdin;
49 core_stdc_stdout = stdout;
50 core_stdc_stderr = stderr;
52 #if __MSVCRT_VERSION__ >= 0xE00
53 msvcUsesUCRT = 1;
54 #endif
57 /* Phobos std.stdio module assumes these functions are present at link time,
58 and not absent or macros. */
59 #ifdef _fgetc_nolock
60 #undef _fgetc_nolock
62 int
63 _fgetc_nolock (FILE *fp)
65 fp->_cnt--;
66 if (fp->_cnt >= 0)
68 const int c = *fp->_ptr;
69 fp->_ptr++;
70 return c & 0xff;
72 else
73 return _filbuf (fp);
76 #endif /* _fgetc_nolock */
78 #ifdef _fputc_nolock
79 #undef _fputc_nolock
81 int
82 _fputc_nolock (int c, FILE *fp)
84 fp->_cnt--;
85 if (fp->_cnt >= 0)
87 *fp->_ptr = (char) c;
88 fp->_ptr++;
89 return c & 0xff;
91 else
92 return _flsbuf (c, fp);
95 #endif /* _fputc_nolock */
97 #ifdef rewind
98 #undef rewind
100 void
101 rewind (FILE *fp)
103 fseek (fp, 0, SEEK_SET);
104 fp->_flag &= ~_IOERR;
107 #endif /* rewind */
109 #ifdef clearerr
110 #undef clearerr
112 void
113 clearerr (FILE *fp)
115 fp->_flag &= ~(_IOERR | _IOEOF);
118 #endif /* clearerr */
120 #ifdef feof
121 #undef feof
124 feof (FILE *fp)
126 return fp->_flag & _IOEOF;
129 #endif /* feof */
131 #ifdef ferror
132 #undef ferror
135 ferror (FILE *fp)
137 return fp->_flag & _IOERR;
140 #endif /* ferror */
142 #ifdef fileno
143 #undef fileno
146 fileno (FILE *fp)
148 return fp->_file;
151 #endif /* fileno */
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
157 wint_t
158 _fgetwc_nolock (FILE *fp)
160 return fgetwc (fp);
163 wint_t
164 _fputwc_nolock (wchar_t c, FILE *fp)
166 return fputwc(c, fp);
169 #endif /* __MSVCRT_VERSION__ < 0x800*/