< prev index next >
src/solaris/native/sun/nio/fs/LinuxNativeDispatcher.c
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -167,26 +167,25 @@
}
return ptr_to_jlong(fp);
}
JNIEXPORT jint JNICALL
-Java_sun_nio_fs_LinuxNativeDispatcher_getmntent(JNIEnv* env, jclass this,
- jlong value, jobject entry)
+Java_sun_nio_fs_LinuxNativeDispatcher_getmntent0(JNIEnv* env, jclass this,
+ jlong value, jobject entry, jlong buffer, jint bufLen)
{
struct mntent ent;
- char buf[1024];
- int buflen = sizeof(buf);
+ char * buf = (char*)jlong_to_ptr(buffer);
struct mntent* m;
FILE* fp = jlong_to_ptr(value);
jsize len;
jbyteArray bytes;
char* name;
char* dir;
char* fstype;
char* options;
- m = getmntent_r(fp, &ent, (char*)&buf, buflen);
+ m = getmntent_r(fp, &ent, buf, (int)bufLen);
if (m == NULL)
return -1;
name = m->mnt_fsname;
dir = m->mnt_dir;
fstype = m->mnt_type;
@@ -228,5 +227,37 @@
{
FILE* fp = jlong_to_ptr(stream);
/* FIXME - man page doesn't explain how errors are returned */
endmntent(fp);
}
+
+/**
+ * This function returns line length without NUL terminator or -1 on EOF.
+ */
+JNIEXPORT jint JNICALL
+Java_sun_nio_fs_LinuxNativeDispatcher_getlinelen(JNIEnv* env, jclass this, jlong stream)
+{
+ FILE* fp = jlong_to_ptr(stream);
+ size_t lineSize = 0;
+ char * lineBuffer = NULL;
+ int saved_errno;
+
+ ssize_t res = getline(&lineBuffer, &lineSize, fp);
+ saved_errno = errno;
+
+ /* Should free lineBuffer no matter result, according to man page */
+ if (lineBuffer != NULL)
+ free(lineBuffer);
+
+ if (feof(fp))
+ return -1;
+
+ /* On successfull return res >= 0, otherwise res is -1 */
+ if (res == -1)
+ throwUnixException(env, saved_errno);
+
+ if (res > INT_MAX)
+ throwUnixException(env, EOVERFLOW);
+
+ return (jint)res;
+}
+
< prev index next >