OSDN Git Service

2006-05-02 Bryce McKinlay <mckinlay@redhat.com>
[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 #include <gcj/cni.h>
41 #include <java/util/Properties.h>
42
43 // Prefix and suffix for shared libraries.
44 #define _Jv_platform_solib_prefix "lib"
45 #if defined(__APPLE__) && defined(__MACH__)
46 #define _Jv_platform_solib_suffix ".dylib"
47 #else
48 #define _Jv_platform_solib_suffix ".so"
49 #endif
50
51 // Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here.
52 // Needed in java/io/natFileDescriptorPosix.cc.
53 #if !defined (O_SYNC) && defined (O_FSYNC)
54 #define O_SYNC O_FSYNC
55 #endif
56 #if !defined (O_DSYNC) && defined (O_FSYNC)
57 #define O_DSYNC O_FSYNC
58 #endif
59 // If O_DSYNC is still not defined, use O_SYNC (needed for newlib)
60 #if !defined (O_DSYNC) 
61 #define O_DSYNC O_SYNC
62 #endif
63
64 // Separator for file name components.
65 #define _Jv_platform_file_separator ((jchar) '/')
66 // Separator for path components.
67 #define _Jv_platform_path_separator ((jchar) ':')
68
69 // List of names for `JNI_OnLoad'.
70 #define _Jv_platform_onload_names { "JNI_OnLoad", NULL }
71
72 // Type of libffi ABI used by JNICALL methods.  NOTE: This must agree
73 // with the JNICALL definition in jni.h
74 #define _Jv_platform_ffi_abi FFI_DEFAULT_ABI
75
76 #ifndef DISABLE_JAVA_NET
77 #include <java/net/InetAddress.h>
78 #endif
79
80 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
81 extern jlong _Jv_platform_gettimeofday ();
82 extern jlong _Jv_platform_nanotime ();
83 extern void _Jv_platform_initialize (void);
84 extern void _Jv_platform_initProperties (java::util::Properties*);
85
86 inline void
87 _Jv_platform_close_on_exec (jint fd)
88 {
89   // Ignore errors.
90   ::fcntl (fd, F_SETFD, FD_CLOEXEC);
91 }
92
93 #undef fcntl
94
95 #ifdef JV_HASH_SYNCHRONIZATION
96 #ifndef HAVE_USLEEP_DECL
97 extern "C" int usleep (useconds_t useconds);
98 #endif /* not HAVE_USLEEP_DECL */
99
100 inline void
101 _Jv_platform_usleep (unsigned long usecs)
102 {
103   usleep (usecs);
104 }
105 #endif /* JV_HASH_SYNCHRONIZATION */
106
107 #ifndef DISABLE_JAVA_NET
108
109 #ifndef HAVE_SOCKLEN_T
110 #define socklen_t int
111 #endif
112
113 static inline int
114 _Jv_socket (int domain, int type, int protocol)
115 {
116   return ::socket (domain, type, protocol);
117 }
118
119 #undef socket
120
121 inline int
122 _Jv_connect (jint fd, sockaddr *ptr, int len)
123 {
124    return ::connect (fd, ptr, len);
125 }
126
127 #undef connect
128
129 inline int
130 _Jv_close (jint fd)
131 {
132   return ::close (fd);
133 }
134
135 #undef close
136
137 // Avoid macro definitions of bind from system headers, e.g. on
138 // Solaris 7 with _XOPEN_SOURCE.  FIXME
139 inline int
140 _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
141 {
142   return ::bind (fd, addr, addrlen);
143 }
144
145 #undef bind
146
147 // Same problem with accept on Tru64 UNIX with _POSIX_PII_SOCKET
148 inline int
149 _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
150 {
151   return ::accept (fd, addr, addrlen);
152 }
153
154 #undef accept
155
156 inline int
157 _Jv_listen (int fd, int backlog)
158 {
159   return ::listen (fd, backlog);
160 }
161
162 #undef listen
163
164 inline int
165 _Jv_write(int s, void *buf, int len)
166 {
167   return ::write (s, buf, len);
168 }
169
170 #undef write
171
172 inline int
173 _Jv_read(int s, void *buf, int len)
174 {
175   return ::read (s, buf, len);
176 }
177
178 #undef read
179
180 #endif /* DISABLE_JAVA_NET */
181
182 // Wraps ::pipe
183 static inline int
184 _Jv_pipe (int filedes[2])
185 {
186   return ::pipe (filedes);
187 }
188
189 #endif /* __JV_POSIX_H__ */