configure.in: Added new MinGW-specific configure flag --with-win32-nlsapi.
[gcc.git] / libjava / include / win32.h
1 // win32.h -- Helper functions for Microsoft-flavored OSs.
2
3 /* Copyright (C) 2002, 2003 Free Software Foundation
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 #ifndef __JV_WIN32_H__
12 #define __JV_WIN32_H__
13
14 // Enable UNICODE Support.?
15
16 #ifdef MINGW_LIBGCJ_UNICODE
17 #define UNICODE
18 #define _UNICODE
19 #endif // MINGW_LIBGCJ_UNICODE
20
21 #include <tchar.h>
22
23 // Includes
24 #define WIN32_LEAN_AND_MEAN
25 #include <windows.h>
26 #undef WIN32_LEAN_AND_MEAN
27 #undef STRICT
28
29 #include <ws2tcpip.h>
30 #include <gcj/cni.h>
31 #include <jvm.h>
32 #include <java/util/Properties.h>
33
34 #include <io.h>
35
36 /* Begin UNICODE Support Classes and Functions */
37
38 /* Helper class which creates a temporary, null-terminated,
39 wide-character C string. */
40 class _Jv_Win32TempString
41 {
42 public:
43 _Jv_Win32TempString(jstring jstr);
44 ~_Jv_Win32TempString();
45
46 // Accessors
47 operator LPCTSTR() const
48 {
49 return buf_;
50 }
51 LPCTSTR buf() const
52 {
53 return buf_;
54 }
55 LPTSTR buf()
56 {
57 return buf_;
58 }
59
60 private:
61 TCHAR stackbuf_[500];
62 LPTSTR buf_;
63 };
64
65 // Mimics the JV_TEMP_STRING_UTF macro in jvm.h
66 #define JV_TEMP_STRING_WIN32(x,y) _Jv_Win32TempString x(y);
67
68 // Creates a jstring from a LPCTSTR
69 extern jstring _Jv_Win32NewString (LPCTSTR pcsz);
70
71 /* End UNICODE Helpers */
72
73 // Prefix and suffix for shared libraries.
74 #define _Jv_platform_solib_prefix ""
75 #define _Jv_platform_solib_suffix ".dll"
76
77 // Separator for file name components.
78 #define _Jv_platform_file_separator ((jchar) '\\')
79 // Separator for path components.
80 #define _Jv_platform_path_separator ((jchar) ';')
81
82 // List of names for `JNI_OnLoad'. On Win32, JNI_OnLoad is an
83 // "stdcall" function taking two pointers (8 bytes) as arguments. It
84 // could also have been exported as "JNI_OnLoad@8" (MinGW) or
85 // "_JNI_OnLoad@8" (MSVC).
86 #define _Jv_platform_onload_names \
87 { "JNI_OnLoad", "JNI_OnLoad@8", "_JNI_OnLoad@8", NULL }
88
89 // Type of libffi ABI used by JNICALL methods. NOTE: This must agree
90 // with the JNICALL definition in jni.h
91 #define _Jv_platform_ffi_abi FFI_STDCALL
92
93 /* Useful helper classes and methods. */
94
95 /* A C++ wrapper around a WSAEVENT which closes the event
96 in its destructor. If dwSelFlags is non-zero, we also
97 issue an WSAEventSelect on the socket descriptor with
98 the given flags; this is undone by a corresponding call
99 to WSAEventSelect(fd, 0, 0) in our destructor. */
100 class WSAEventWrapper
101 {
102 public:
103 WSAEventWrapper(int fd, DWORD dwSelFlags);
104 ~WSAEventWrapper();
105
106 WSAEVENT getEventHandle()
107 {
108 return m_hEvent;
109 }
110
111 private:
112 WSAEVENT m_hEvent;
113 int m_fd;
114 DWORD m_dwSelFlags;
115 };
116
117 // Error string text. The int argument is compatible
118 // with both int WSAGetLastError() and DWORD GetLastError()
119 // I tried avoiding having to pass the error explicitly, but
120 // it didn't work this was invoked with say
121 // throw new SomeException(_Jv_WinStrError()).
122 extern jstring
123 _Jv_WinStrError (LPCTSTR lpszPrologue, int nErrorCode);
124
125 extern jstring
126 _Jv_WinStrError (int nErrorCode);
127
128 extern void
129 _Jv_ThrowIOException (DWORD dwErrorCode);
130
131 extern void
132 _Jv_ThrowIOException ();
133
134 extern void
135 _Jv_ThrowSocketException (DWORD dwErrorCode);
136
137 extern void
138 _Jv_ThrowSocketException ();
139
140 // Platform implementation
141 extern void _Jv_platform_initialize (void);
142 extern void _Jv_platform_initProperties (java::util::Properties*);
143 extern jlong _Jv_platform_gettimeofday ();
144 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
145 extern int _Jv_pipe (int filedes[2]);
146
147 extern void
148 _Jv_platform_close_on_exec (HANDLE h);
149
150 #ifdef JV_HASH_SYNCHRONIZATION
151 /* Suspends the execution of the current thread for the specified
152 number of microseconds. Tries to emulate the behaviour of usleep()
153 on UNIX and provides a granularity of 1 millisecond. */
154 inline void
155 _Jv_platform_usleep (unsigned long usecs)
156 {
157 if (usecs > 0UL)
158 {
159 unsigned long millis = ((usecs + 999UL) / 1000UL);
160 Sleep (millis);
161 }
162 }
163 #endif /* JV_HASH_SYNCHRONIZATION */
164
165 /* Store up to SIZE return address of the current program state in
166 ARRAY and return the exact number of values stored. */
167 extern int backtrace (void **__array, int __size);
168
169 #endif /* __JV_WIN32_H__ */