PR tree-optimization/27639
[official-gcc.git] / libjava / include / posix.h
blob63fc135d4d8ea15f267832f8c6882a0e87e1f2a1
1 // posix.h -- Helper functions for POSIX-flavored OSs.
3 /* Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
11 #ifndef __JV_POSIX_H__
12 #define __JV_POSIX_H__
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
19 #include <time.h>
20 #include <sys/types.h>
22 #ifdef HAVE_SYS_TIME_H
23 #include <sys/time.h>
24 #endif
26 #ifdef HAVE_SYS_SELECT_H
27 #include <sys/select.h>
28 #endif
30 #ifdef HAVE_SYS_SOCKET_H
31 #include <sys/socket.h>
32 #endif
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
38 #include <fcntl.h>
40 #include <gcj/cni.h>
41 #include <java/util/Properties.h>
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 #elif defined(HPUX) && defined(HP_PA)
48 #define _Jv_platform_solib_suffix ".sl"
49 #else
50 #define _Jv_platform_solib_suffix ".so"
51 #endif
53 // Some POSIX systems don't have O_SYNC and O_DYSNC so we define them here.
54 // Needed in java/io/natFileDescriptorPosix.cc.
55 #if !defined (O_SYNC) && defined (O_FSYNC)
56 #define O_SYNC O_FSYNC
57 #endif
58 #if !defined (O_DSYNC) && defined (O_FSYNC)
59 #define O_DSYNC O_FSYNC
60 #endif
61 // If O_DSYNC is still not defined, use O_SYNC (needed for newlib)
62 #if !defined (O_DSYNC)
63 #define O_DSYNC O_SYNC
64 #endif
66 // Separator for file name components.
67 #define _Jv_platform_file_separator ((jchar) '/')
68 // Separator for path components.
69 #define _Jv_platform_path_separator ((jchar) ':')
71 // List of names for `JNI_OnLoad'.
72 #define _Jv_platform_onload_names { "JNI_OnLoad", NULL }
74 // Type of libffi ABI used by JNICALL methods. NOTE: This must agree
75 // with the JNICALL definition in jni.h
76 #define _Jv_platform_ffi_abi FFI_DEFAULT_ABI
78 #ifndef DISABLE_JAVA_NET
79 #include <java/net/InetAddress.h>
80 #endif
82 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
83 extern jlong _Jv_platform_gettimeofday ();
84 extern jlong _Jv_platform_nanotime ();
85 extern void _Jv_platform_initialize (void);
86 extern void _Jv_platform_initProperties (java::util::Properties*);
88 inline void
89 _Jv_platform_close_on_exec (jint fd)
91 // Ignore errors.
92 ::fcntl (fd, F_SETFD, FD_CLOEXEC);
95 #undef fcntl
97 #ifdef JV_HASH_SYNCHRONIZATION
98 #ifndef HAVE_USLEEP_DECL
99 extern "C" int usleep (useconds_t useconds);
100 #endif /* not HAVE_USLEEP_DECL */
102 inline void
103 _Jv_platform_usleep (unsigned long usecs)
105 usleep (usecs);
107 #endif /* JV_HASH_SYNCHRONIZATION */
109 #ifndef DISABLE_JAVA_NET
111 #ifndef HAVE_SOCKLEN_T
112 #define socklen_t int
113 #endif
115 static inline int
116 _Jv_socket (int domain, int type, int protocol)
118 return ::socket (domain, type, protocol);
121 #undef socket
123 inline int
124 _Jv_connect (jint fd, sockaddr *ptr, int len)
126 return ::connect (fd, ptr, len);
129 #undef connect
131 inline int
132 _Jv_close (jint fd)
134 return ::close (fd);
137 #undef close
139 // Avoid macro definitions of bind from system headers, e.g. on
140 // Solaris 7 with _XOPEN_SOURCE. FIXME
141 inline int
142 _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
144 return ::bind (fd, addr, addrlen);
147 #undef bind
149 // Same problem with accept on Tru64 UNIX with _POSIX_PII_SOCKET
150 inline int
151 _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
153 return ::accept (fd, addr, addrlen);
156 #undef accept
158 inline int
159 _Jv_listen (int fd, int backlog)
161 return ::listen (fd, backlog);
164 #undef listen
166 inline int
167 _Jv_write(int s, void *buf, int len)
169 return ::write (s, buf, len);
172 #undef write
174 inline int
175 _Jv_read(int s, void *buf, int len)
177 return ::read (s, buf, len);
180 #undef read
182 #endif /* DISABLE_JAVA_NET */
184 // Wraps ::pipe
185 static inline int
186 _Jv_pipe (int filedes[2])
188 return ::pipe (filedes);
191 #endif /* __JV_POSIX_H__ */