1 /* con32s - emulates console under Windows.
2 Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 /* This replaces a few of the Borland C++ library functions. It does
21 not use any of the runtime library header files, so you do not need
22 the runtime library source in order to compile it. */
28 /* 1=It is necessary to emulate the console window. */
31 /* Exported by con32s.c. */
32 extern int _blp_console_read (void *buf, unsigned len);
34 /* Exported by Borland runtime library. */
35 extern long _handles[];
36 extern int __IOerror (int);
37 extern int __NTerror (void);
39 /* Replaces Borland library function. */
41 _rtl_read (int fd, void *buf, unsigned len)
45 if ((unsigned) fd >= _nfile)
46 return __IOerror (ERROR_INVALID_HANDLE);
48 /* Redirect stdin to the faked console window. */
49 if (_emu_console && fd < 3)
50 return _blp_console_read (buf, len);
52 if (ReadFile ((HANDLE) _handles[fd], buf, (DWORD) len, &nread, NULL) != 1)
58 /* Replaces Borland library function. */
60 _rtl_write (int fd, const void *buf, unsigned int len)
64 if ((unsigned) fd >= _nfile)
65 return __IOerror (ERROR_INVALID_HANDLE);
67 /* Redirect stdout, stderr to the faked console window. */
68 if (_emu_console && fd < 3)
69 return _blp_console_write (buf, len);
71 if (WriteFile ((HANDLE) _handles[fd], (PVOID) buf, (DWORD) len, &written,
81 #pragma startup determine_os 64
84 /* Try out a random console function. If it fails then we must not
87 Believe it or not, this seems to be the only way to determine
88 reliably whether we're running under 3.1. If you know a better
90 if (GetNumberOfConsoleMouseButtons (&nButtons))