src/java.base/unix/native/libnio/ch/InheritedChannel.c
author michaelm
Fri, 08 Nov 2019 16:22:21 +0000
branchunixdomainchannels
changeset 58988 b88e23c84b23
parent 58295 7973073dd048
child 59003 aaba7cc40951
permissions -rw-r--r--
inherited channels fix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58295
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "net_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "sun_nio_ch_InheritedChannel.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    40
static int matchFamilyInet(SOCKETADDRESS *sa) {
43889
212e765112d4 8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents: 43100
diff changeset
    41
    return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
26207
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    44
JNIEXPORT void JNICALL
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    45
Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla)
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    46
{
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    47
    /* Initialize InetAddress IDs before later use of NET_XXX functions */
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    48
    initInetAddressIDs(env);
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    49
}
a02f6165d5be 8055955: (ch) Remove unnecessary initialization of InetAddress from FileChannel
chegar
parents: 25859
diff changeset
    50
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
JNIEXPORT jobject JNICALL
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    52
Java_sun_nio_ch_InheritedChannel_peerAddressInet(JNIEnv *env, jclass cla, jint fd)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    54
    SOCKETADDRESS sa;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    55
    socklen_t len = sizeof(SOCKETADDRESS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    jobject remote_ia = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    jint remote_port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    59
    if (getpeername(fd, &sa.sa, &len) == 0) {
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    60
        if (matchFamilyInet(&sa)) {
43100
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41380
diff changeset
    61
            remote_ia = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    return remote_ia;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    68
JNIEXPORT jobject JNICALL
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    69
Java_sun_nio_ch_InheritedChannel_peerAddressUnix(JNIEnv *env, jclass cla, jint fd)
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    70
{
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    71
    SOCKETADDRESS sa;
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    72
    socklen_t len = sizeof(SOCKETADDRESS);
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    73
    jobject remote_sa = NULL;
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    74
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    75
    if (sa.sa.sa_family == AF_UNIX) {
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    76
    	remote_sa = NET_SockaddrToUnixAddress(env, &sa);
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    77
    }
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    78
    return remote_sa;
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    79
}
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
{
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    84
    SOCKETADDRESS sa;
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    85
    socklen_t len = sizeof(SOCKETADDRESS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    jint remote_port = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
41380
c27cf95dd7e6 8167295: Further cleanup to the native parts of libnet/libnio
clanger
parents: 26207
diff changeset
    88
    if (getpeername(fd, &sa.sa, &len) == 0) {
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    89
        if (matchFamilyInet(&sa)) {
43100
a7e3457672c7 8170544: Fix code scan findings in libnet
clanger
parents: 41380
diff changeset
    90
            NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
58988
b88e23c84b23 inherited channels fix
michaelm
parents: 58295
diff changeset
    91
	}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    return remote_port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
JNIEXPORT jint JNICALL
58295
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
    98
Java_sun_nio_ch_InheritedChannel_addressFamily(JNIEnv *env, jclass cla, jint fd)
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
    99
{
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   100
    SOCKETADDRESS addr;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   101
    socklen_t addrlen = sizeof(addr);
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   102
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   103
    if (getsockname(fd, (struct sockaddr *)&addr, &addrlen) < 0) {
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   104
        return sun_nio_ch_InheritedChannel_AF_UNKNOWN;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   105
    }
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   106
    if (addr.sa.sa_family == AF_INET) {
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   107
        return sun_nio_ch_InheritedChannel_AF_INET;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   108
    }
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   109
    if (addr.sa.sa_family == AF_INET6) {
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   110
        return sun_nio_ch_InheritedChannel_AF_INET6;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   111
    }
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   112
    if (addr.sa.sa_family == AF_UNIX) {
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   113
        return sun_nio_ch_InheritedChannel_AF_UNIX;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   114
    }
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   115
    return sun_nio_ch_InheritedChannel_AF_UNKNOWN;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   116
}
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   117
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   118
JNIEXPORT jboolean JNICALL
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   119
Java_sun_nio_ch_InheritedChannel_isConnected(JNIEnv *env, jclass cla, jint fd)
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   120
{
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   121
    SOCKETADDRESS addr;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   122
    socklen_t addrlen = sizeof(addr);
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   123
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   124
    if (getpeername(fd, (struct sockaddr *)&addr, &addrlen) < 0) {
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   125
        return JNI_FALSE;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   126
    }
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   127
    return JNI_TRUE;
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   128
}
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   129
7973073dd048 8231187: SelectorProvider.inheritedChannel() returns TCP socket channel for Unix domain socket
michaelm
parents: 47216
diff changeset
   130
JNIEXPORT jint JNICALL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
{
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   133
    int sotype;
43889
212e765112d4 8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents: 43100
diff changeset
   134
    socklen_t arglen = sizeof(sotype);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (sotype == SOCK_STREAM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return sun_nio_ch_InheritedChannel_SOCK_STREAM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (sotype == SOCK_DGRAM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return sun_nio_ch_InheritedChannel_SOCK_DGRAM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    return sun_nio_ch_InheritedChannel_UNKNOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
Java_sun_nio_ch_InheritedChannel_dup(JNIEnv *env, jclass cla, jint fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
   int newfd = dup(fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
   if (newfd < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        JNU_ThrowIOExceptionWithLastError(env, "dup failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
   return (jint)newfd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
Java_sun_nio_ch_InheritedChannel_dup2(JNIEnv *env, jclass cla, jint fd, jint fd2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
   if (dup2(fd, fd2) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        JNU_ThrowIOExceptionWithLastError(env, "dup2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
Java_sun_nio_ch_InheritedChannel_open0(JNIEnv *env, jclass cla, jstring path, jint oflag)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
{
43889
212e765112d4 8174834: nio (ch): Remove #ifdef AF_INET6 guards in native coding
clanger
parents: 43100
diff changeset
   165
    const char *str;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    int oflag_actual;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /* convert to OS specific value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    switch (oflag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        case sun_nio_ch_InheritedChannel_O_RDWR :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            oflag_actual = O_RDWR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        case sun_nio_ch_InheritedChannel_O_RDONLY :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            oflag_actual = O_RDONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        case sun_nio_ch_InheritedChannel_O_WRONLY :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            oflag_actual = O_WRONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            JNU_ThrowInternalError(env, "Unrecognized file mode");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    str = JNU_GetStringPlatformChars(env, path, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    if (str == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return (jint)-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        int fd = open(str, oflag_actual);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (fd < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            JNU_ThrowIOExceptionWithLastError(env, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        JNU_ReleaseStringPlatformChars(env, path, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return (jint)fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
Java_sun_nio_ch_InheritedChannel_close0(JNIEnv *env, jclass cla, jint fd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    if (close(fd) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        JNU_ThrowIOExceptionWithLastError(env, "close failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
}