提交 3e7e23be 编写于 作者: A alanb

7030624: size_t usages in src/windows/native/java/io/io_util_md.c need to be re-visited

Reviewed-by: lancea, chegar
上级 039d858a
...@@ -44,7 +44,7 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) { ...@@ -44,7 +44,7 @@ readSingle(JNIEnv *env, jobject this, jfieldID fid) {
JNU_ThrowIOException(env, "Stream Closed"); JNU_ThrowIOException(env, "Stream Closed");
return -1; return -1;
} }
nread = (jint)IO_Read(fd, &ret, 1); nread = IO_Read(fd, &ret, 1);
if (nread == 0) { /* EOF */ if (nread == 0) { /* EOF */
return -1; return -1;
} else if (nread == JVM_IO_ERR) { /* error */ } else if (nread == JVM_IO_ERR) { /* error */
...@@ -108,7 +108,7 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes, ...@@ -108,7 +108,7 @@ readBytes(JNIEnv *env, jobject this, jbyteArray bytes,
JNU_ThrowIOException(env, "Stream Closed"); JNU_ThrowIOException(env, "Stream Closed");
nread = -1; nread = -1;
} else { } else {
nread = (jint)IO_Read(fd, buf, len); nread = IO_Read(fd, buf, len);
if (nread > 0) { if (nread > 0) {
(*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf); (*env)->SetByteArrayRegion(env, bytes, off, nread, (jbyte *)buf);
} else if (nread == JVM_IO_ERR) { } else if (nread == JVM_IO_ERR) {
...@@ -137,9 +137,9 @@ writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid) ...@@ -137,9 +137,9 @@ writeSingle(JNIEnv *env, jobject this, jint byte, jboolean append, jfieldID fid)
return; return;
} }
if (append == JNI_TRUE) { if (append == JNI_TRUE) {
n = (jint)IO_Append(fd, &c, 1); n = IO_Append(fd, &c, 1);
} else { } else {
n = (jint)IO_Write(fd, &c, 1); n = IO_Write(fd, &c, 1);
} }
if (n == JVM_IO_ERR) { if (n == JVM_IO_ERR) {
JNU_ThrowIOExceptionWithLastError(env, "Write error"); JNU_ThrowIOExceptionWithLastError(env, "Write error");
...@@ -190,9 +190,9 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes, ...@@ -190,9 +190,9 @@ writeBytes(JNIEnv *env, jobject this, jbyteArray bytes,
break; break;
} }
if (append == JNI_TRUE) { if (append == JNI_TRUE) {
n = (jint)IO_Append(fd, buf+off, len); n = IO_Append(fd, buf+off, len);
} else { } else {
n = (jint)IO_Write(fd, buf+off, len); n = IO_Write(fd, buf+off, len);
} }
if (n == JVM_IO_ERR) { if (n == JVM_IO_ERR) {
JNU_ThrowIOExceptionWithLastError(env, "Write error"); JNU_ThrowIOExceptionWithLastError(env, "Write error");
......
...@@ -478,7 +478,7 @@ handleSetLength(jlong fd, jlong length) { ...@@ -478,7 +478,7 @@ handleSetLength(jlong fd, jlong length) {
} }
JNIEXPORT JNIEXPORT
size_t jint
handleRead(jlong fd, void *buf, jint len) handleRead(jlong fd, void *buf, jint len)
{ {
DWORD read = 0; DWORD read = 0;
...@@ -499,10 +499,10 @@ handleRead(jlong fd, void *buf, jint len) ...@@ -499,10 +499,10 @@ handleRead(jlong fd, void *buf, jint len)
} }
return -1; return -1;
} }
return read; return (jint)read;
} }
static size_t writeInternal(jlong fd, const void *buf, jint len, jboolean append) static jint writeInternal(jlong fd, const void *buf, jint len, jboolean append)
{ {
BOOL result = 0; BOOL result = 0;
DWORD written = 0; DWORD written = 0;
...@@ -527,16 +527,16 @@ static size_t writeInternal(jlong fd, const void *buf, jint len, jboolean append ...@@ -527,16 +527,16 @@ static size_t writeInternal(jlong fd, const void *buf, jint len, jboolean append
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) { if ((h == INVALID_HANDLE_VALUE) || (result == 0)) {
return -1; return -1;
} }
return (size_t)written; return (jint)written;
} }
JNIEXPORT JNIEXPORT
size_t handleWrite(jlong fd, const void *buf, jint len) { jint handleWrite(jlong fd, const void *buf, jint len) {
return writeInternal(fd, buf, len, JNI_FALSE); return writeInternal(fd, buf, len, JNI_FALSE);
} }
JNIEXPORT JNIEXPORT
size_t handleAppend(jlong fd, const void *buf, jint len) { jint handleAppend(jlong fd, const void *buf, jint len) {
return writeInternal(fd, buf, len, JNI_TRUE); return writeInternal(fd, buf, len, JNI_TRUE);
} }
......
...@@ -39,9 +39,9 @@ void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags); ...@@ -39,9 +39,9 @@ void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
int handleAvailable(jlong fd, jlong *pbytes); int handleAvailable(jlong fd, jlong *pbytes);
JNIEXPORT int handleSync(jlong fd); JNIEXPORT int handleSync(jlong fd);
int handleSetLength(jlong fd, jlong length); int handleSetLength(jlong fd, jlong length);
JNIEXPORT size_t handleRead(jlong fd, void *buf, jint len); JNIEXPORT jint handleRead(jlong fd, void *buf, jint len);
JNIEXPORT size_t handleWrite(jlong fd, const void *buf, jint len); JNIEXPORT jint handleWrite(jlong fd, const void *buf, jint len);
JNIEXPORT size_t handleAppend(jlong fd, const void *buf, jint len); JNIEXPORT jint handleAppend(jlong fd, const void *buf, jint len);
jint handleClose(JNIEnv *env, jobject this, jfieldID fid); jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
jlong handleLseek(jlong fd, jlong offset, jint whence); jlong handleLseek(jlong fd, jlong offset, jint whence);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册