Andreas Wacknitz
2024-01-27 7184c705a6f58435e822ea9de28cfa06dcf7e46f
commit | author | age
c448de 1 --- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c    Thu May 28 11:43:30 2020
NP 2 +++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c    Wed May 20 19:29:11 2020
7184c7 3 @@ -499,7 +499,41 @@
c448de 4      return (jint)res;
NP 5  }
6  
7 +JNIEXPORT jlong JNICALL
8 +Java_sun_nio_fs_UnixNativeDispatcher_fopen0(JNIEnv* env, jclass this,
9 +    jlong pathAddress, jlong modeAddress)
10 +{
11 +    FILE* fp = NULL;
12 +    const char* path = (const char*)jlong_to_ptr(pathAddress);
13 +    const char* mode = (const char*)jlong_to_ptr(modeAddress);
14 +
15 +    do {
16 +        fp = fopen(path, mode);
17 +    } while (fp == NULL && errno == EINTR);
18 +
19 +    if (fp == NULL) {
20 +        throwUnixException(env, errno);
21 +    }
22 +
23 +    return ptr_to_jlong(fp);
24 +}
25 +
26  JNIEXPORT void JNICALL
27 +Java_sun_nio_fs_UnixNativeDispatcher_fclose(JNIEnv* env, jclass this, jlong stream)
28 +{
29 +    FILE* fp = jlong_to_ptr(stream);
30 +
31 +    /* NOTE: fclose() wrapper is only used with read-only streams.
32 +     * If it ever is used with write streams, it might be better to add
33 +     * RESTARTABLE(fflush(fp)) before closing, to make sure the stream
34 +     * is completely written even if fclose() failed.
35 +     */
36 +    if (fclose(fp) == EOF && errno != EINTR) {
37 +        throwUnixException(env, errno);
38 +    }
39 +}
40 +
41 +JNIEXPORT void JNICALL
42  Java_sun_nio_fs_UnixNativeDispatcher_rewind(JNIEnv* env, jclass this, jlong stream)
43  {
44      FILE* fp = jlong_to_ptr(stream);
7184c7 45 @@ -1262,6 +1296,33 @@
c448de 46      }
NP 47  }
48  
49 +JNIEXPORT jlong JNICALL
50 +Java_sun_nio_fs_UnixNativeDispatcher_pathconf0(JNIEnv* env, jclass this,
51 +    jlong pathAddress, jint name)
52 +{
53 +    long err;
54 +    const char* path = (const char*)jlong_to_ptr(pathAddress);
55 +
56 +    err = pathconf(path, (int)name);
57 +    if (err == -1) {
58 +        throwUnixException(env, errno);
59 +    }
60 +    return (jlong)err;
61 +}
62 +
63 +JNIEXPORT jlong JNICALL
64 +Java_sun_nio_fs_UnixNativeDispatcher_fpathconf(JNIEnv* env, jclass this,
65 +    jint fd, jint name)
66 +{
67 +    long err;
68 +
69 +    err = fpathconf((int)fd, (int)name);
70 +    if (err == -1) {
71 +        throwUnixException(env, errno);
72 +    }
73 +    return (jlong)err;
74 +}
75 +
76  JNIEXPORT void JNICALL
77  Java_sun_nio_fs_UnixNativeDispatcher_mknod0(JNIEnv* env, jclass this,
78      jlong pathAddress, jint mode, jlong dev)