posic.h: Moved new functions into a #ifndef DISABLE_JAVA_NET
[gcc.git] / libjava / include / posix.h
1 // posix.h -- Helper functions for POSIX-flavored OSs.
2
3 /* Copyright (C) 2000, 2002 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 #ifndef DISABLE_JAVA_NET
15
16 /* Required on Tru64 UNIX V4/V5 so <sys/socket.h> defines prototypes of
17 socket functions with socklen_t instead of size_t. This must be defined
18 early so <standards.h> defines the correct version of __PIIX. */
19 #define _POSIX_PII_SOCKET
20
21 #include <time.h>
22 #include <sys/types.h>
23
24 #ifdef HAVE_SYS_TIME_H
25 #include <sys/time.h>
26 #endif
27
28 #ifdef HAVE_SYS_SELECT_H
29 #include <sys/select.h>
30 #endif
31
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
34 #endif
35
36 #ifdef HAVE_UNISTD_H
37 #include <unistd.h>
38 #endif
39
40 #include <fcntl.h>
41
42 #include <gcj/cni.h>
43 #include <java/util/Properties.h>
44
45 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
46 extern jlong _Jv_platform_gettimeofday ();
47 extern void _Jv_platform_initialize (void);
48 extern void _Jv_platform_initProperties (java::util::Properties*);
49
50 static inline int
51 _Jv_socket (int domain, int type, int protocol)
52 {
53 return ::socket (domain, type, protocol);
54 }
55
56 inline int
57 _Jv_connect (jint fd, sockaddr *ptr, int len)
58 {
59 return ::connect (fd, ptr, len);
60 }
61
62 inline int
63 _Jv_close (jint fd)
64 {
65 return ::close (fd);
66 }
67
68 inline void
69 _Jv_platform_close_on_exec (jint fd)
70 {
71 // Ignore errors.
72 ::fcntl (fd, F_SETFD, FD_CLOEXEC);
73 }
74
75 // Avoid macro definitions of bind from system headers, e.g. on
76 // Solaris 7 with _XOPEN_SOURCE. FIXME
77 inline int
78 _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
79 {
80 return ::bind (fd, addr, addrlen);
81 }
82
83 // Same problem with accept on Tru64 UNIX with _POSIX_PII_SOCKET
84 inline int
85 _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
86 {
87 return ::accept (fd, addr, addrlen);
88 }
89
90 inline int
91 _Jv_listen (int fd, int backlog)
92 {
93 return ::listen (fd, backlog);
94 }
95
96 inline int
97 _Jv_write(int s, void *buf, int len)
98 {
99 return ::write (s, buf, len);
100 }
101
102 inline int
103 _Jv_read(int s, void *buf, int len)
104 {
105 return ::read (s, buf, len);
106 }
107
108 #endif /* DISABLE_JAVA_NET */
109
110 #endif /* __JV_POSIX_H__ */