OSDN Git Service

2002-11-21 Michael Koch <konqueror@gmx.de>
[pf3gnuchains/gcc-fork.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 /* 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 extern int _Jv_select (int n, fd_set *, fd_set *, fd_set *, struct timeval *);
44 extern jlong _Jv_platform_gettimeofday ();
45 extern void _Jv_platform_initialize (void);
46 extern void _Jv_platform_initProperties (java::util::Properties*);
47
48 static inline int
49 _Jv_socket (int domain, int type, int protocol)
50 {
51   return ::socket (domain, type, protocol);
52 }
53
54 inline int
55 _Jv_connect (jint fd, sockaddr *ptr, int len)
56 {
57    return ::connect (fd, ptr, len);
58 }
59
60 inline int
61 _Jv_close (jint fd)
62 {
63   return ::close (fd);
64 }
65
66 inline void
67 _Jv_platform_close_on_exec (jint fd)
68 {
69   // Ignore errors.
70   ::fcntl (fd, F_SETFD, FD_CLOEXEC);
71 }
72
73 // Avoid macro definitions of bind from system headers, e.g. on
74 // Solaris 7 with _XOPEN_SOURCE.  FIXME
75 inline int
76 _Jv_bind (int fd, struct sockaddr *addr, int addrlen)
77 {
78   return ::bind (fd, addr, addrlen);
79 }
80
81 // Same problem with accept on Tru64 UNIX with _POSIX_PII_SOCKET
82 inline int
83 _Jv_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
84 {
85   return ::accept (fd, addr, addrlen);
86 }
87
88 inline int
89 _Jv_listen (int fd, int backlog)
90 {
91   return ::listen (fd, backlog);
92 }
93
94 inline int
95 _Jv_write(int s, void *buf, int len)
96 {
97   return ::write (s, buf, len);
98 }
99
100 inline int
101 _Jv_read(int s, void *buf, int len)
102 {
103   return ::read (s, buf, len);
104 }
105 #endif