OSDN Git Service

ee836e0b809496c115c8a1293daeaf00a9e7531f
[pf3gnuchains/gcc-fork.git] / libjava / include / posix.h
1 // posix.h -- Helper functions for POSIX-flavored OSs.
2
3 /* Copyright (C) 2000, 2002, 2003, 2006  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_POSIX_H__
12 #define __JV_POSIX_H__
13
14 /* Required on Tru64 UNIX V4/V5 so <sys/socket.h> defines prototypes of
15    socket functions with socklen_t instead of size_t.  This must be defined
16    early so <standards.h> defines the correct version of __PIIX.  */
17 #define _POSIX_PII_SOCKET
18
19 #include <time.h>
20 #include <sys/types.h>
21
22 #ifdef HAVE_SYS_TIME_H
23 #include <sys/time.h>
24 #endif
25
26 #ifdef HAVE_SYS_SELECT_H
27 #include <sys/select.h>
28 #endif
29
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
32 #endif
33
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37
38 #include <fcntl.h>
39
40 /* The header file <sys/rw_lock.h> needs to be included before javaprims.h
41    on HP-UX 11 to avoid a compilation error.  */
42 #ifdef HAVE_SYS_RW_LOCK_H
43 #include <sys/rw_lock.h>
44 #endif
45
46 #include <gcj/cni.h>
47 #include <java/util/Properties.h>
48
49 // Prefix and suffix for shared libraries.
50 #define _Jv_platform_solib_prefix "lib"
51 #if defined(__APPLE__) && defined(__MACH__)
52 #define _Jv_platform_solib_suffix ".dylib"
53 #elif defined(HPUX) && defined(HP_PA)
54 #define _Jv_platform_solib_suffix ".sl"
55 #else
56 #define _Jv_platform_solib_suffix ".so"
57 #endif
58
59 // Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here.
60 // Needed in java/io/natFileDescriptorPosix.cc.
61 #if !defined (O_SYNC) && defined (O_FSYNC)
62 #define O_SYNC O_FSYNC
63 #endif
64 #if !defined (O_DSYNC) && defined (O_FSYNC)
65 #define O_DSYNC O_FSYNC
66 #endif
67 // If O_DSYNC is still not defined, use O_SYNC (needed for newlib)
68 #if !defined (O_DSYNC) 
69 #define O_DSYNC O_SYNC
70 #endif
71
72 // Name of the Process implementation.
73 #ifdef ECOS
74 #define _Jv_platform_process ::java::lang::EcosProcess
75 #else
76 #define _Jv_platform_process ::java::lang::PosixProcess
77 #endif
78
79 // Separator for file name components.
80 #define _Jv_platform_file_separator ((jchar) '/')
81 // Separator for path components.
82 #define _Jv_platform_path_separator ((jchar) ':')
83
84 // List of names for `JNI_OnLoad'.
85 #define _Jv_platform_onload_names { "JNI_OnLoad", NULL }
86
87 // Type of libffi ABI used by JNICALL methods.  NOTE: This must agree
88 // with the JNICALL definition in jni.h
89 #define _Jv_platform_ffi_abi FFI_DEFAULT_ABI
90
91 #ifndef DISABLE_JAVA_NET
92 #include <java/net/InetAddress.h>
93 #endif
94
95 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
96 extern jlong _Jv_platform_gettimeofday ();
97 extern jlong _Jv_platform_nanotime ();
98 extern void _Jv_platform_initialize (void);
99 extern void _Jv_platform_initProperties (java::util::Properties*);
100
101 inline void
102 _Jv_platform_close_on_exec (jint fd)
103 {
104   // Ignore errors.
105   ::fcntl (fd, F_SETFD, FD_CLOEXEC);
106 }
107
108 #undef fcntl
109
110 #ifdef JV_HASH_SYNCHRONIZATION
111 #ifndef HAVE_USLEEP_DECL
112 extern "C" int usleep (useconds_t useconds);
113 #endif /* not HAVE_USLEEP_DECL */
114
115 inline void
116 _Jv_platform_usleep (unsigned long usecs)
117 {
118   usleep (usecs);
119 }
120 #endif /* JV_HASH_SYNCHRONIZATION */
121
122 #ifndef DISABLE_JAVA_NET
123
124 #ifndef HAVE_SOCKLEN_T
125 #define socklen_t int
126 #endif
127
128 static inline int
129 _Jv_socket (int domain, int type, int protocol)
130 {
131   return ::socket (domain, type, protocol);
132 }
133
134 #undef socket
135
136 inline int
137 _Jv_connect (jint fd, sockaddr *ptr, int len)
138 {
139    return ::connect (fd, ptr, len);
140 }
141
142 #undef connect
143
144 inline int
145 _Jv_close (jint fd)
146 {
147   return ::close (fd);
148 }
149
150 #undef close
151
152 // Avoid macro definitions of bind from system headers, e.g. on
153 // Solaris 7 with _XOPEN_SOURCE.  FIXME
154 inline int
155 _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
156 {
157   return ::bind (fd, addr, addrlen);
158 }
159
160 #undef bind
161
162 // Same problem with accept on Tru64 UNIX with _POSIX_PII_SOCKET
163 inline int
164 _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
165 {
166   return ::accept (fd, addr, addrlen);
167 }
168
169 #undef accept
170
171 inline int
172 _Jv_listen (int fd, int backlog)
173 {
174   return ::listen (fd, backlog);
175 }
176
177 #undef listen
178
179 inline int
180 _Jv_write(int s, void *buf, int len)
181 {
182   return ::write (s, buf, len);
183 }
184
185 #undef write
186
187 inline int
188 _Jv_read(int s, void *buf, int len)
189 {
190   return ::read (s, buf, len);
191 }
192
193 #undef read
194
195 #endif /* DISABLE_JAVA_NET */
196
197 // Wraps ::pipe
198 static inline int
199 _Jv_pipe (int filedes[2])
200 {
201   return ::pipe (filedes);
202 }
203
204 // Forward declaration.  See java-stack.h for definition.
205 struct _Jv_AddrInfo;
206
207 // Given an address, determine the executable or shared object that defines
208 // it and the nearest named symbol.
209 extern int _Jv_platform_dladdr (void *addr, _Jv_AddrInfo *info);
210
211 #endif /* __JV_POSIX_H__ */