Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/nio/fs/UnixCopyFile.c
32288 views
/*1* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jni_util.h"27#include "jlong.h"2829#include <unistd.h>30#include <errno.h>3132#include "sun_nio_fs_UnixCopyFile.h"3334#define RESTARTABLE(_cmd, _result) do { \35do { \36_result = _cmd; \37} while((_result == -1) && (errno == EINTR)); \38} while(0)3940static void throwUnixException(JNIEnv* env, int errnum) {41jobject x = JNU_NewObjectByName(env, "sun/nio/fs/UnixException",42"(I)V", errnum);43if (x != NULL) {44(*env)->Throw(env, x);45}46}4748/**49* Transfer all bytes from src to dst via user-space buffers50*/51JNIEXPORT void JNICALL52Java_sun_nio_fs_UnixCopyFile_transfer53(JNIEnv* env, jclass this, jint dst, jint src, jlong cancelAddress)54{55char buf[8192];56volatile jint* cancel = (jint*)jlong_to_ptr(cancelAddress);5758for (;;) {59ssize_t n, pos, len;60RESTARTABLE(read((int)src, &buf, sizeof(buf)), n);61if (n <= 0) {62if (n < 0)63throwUnixException(env, errno);64return;65}66if (cancel != NULL && *cancel != 0) {67throwUnixException(env, ECANCELED);68return;69}70pos = 0;71len = n;72do {73char* bufp = buf;74bufp += pos;75RESTARTABLE(write((int)dst, bufp, len), n);76if (n == -1) {77throwUnixException(env, errno);78return;79}80pos += n;81len -= n;82} while (len > 0);83}84}858687