Skip to content

Commit

Permalink
Add a constant to ErrnoFileStatus for ENODATA initialized from JNI.
Browse files Browse the repository at this point in the history
Rename the intermediate variables used to propagate errno from JNI to conform to the naming style.

PiperOrigin-RevId: 429181816
  • Loading branch information
alexjski authored and copybara-github committed Feb 17, 2022
1 parent 30afc25 commit b3baae9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public class ErrnoFileStatus extends FileStatus {
public static final int ELOOP;
public static final int ENOTDIR;
public static final int ENAMETOOLONG;
public static final int ENODATA;

static {
ErrnoConstants constants = ErrnoConstants.getErrnoConstants();
ENOENT = constants.ENOENT;
EACCES = constants.EACCES;
ELOOP = constants.ELOOP;
ENOTDIR = constants.ENOTDIR;
ENAMETOOLONG = constants.ENAMETOOLONG;
ENOENT = constants.errnoENOENT;
EACCES = constants.errnoEACCES;
ELOOP = constants.errnoELOOP;
ENOTDIR = constants.errnoENOTDIR;
ENAMETOOLONG = constants.errnoENAMETOOLONG;
ENODATA = constants.errnoENODATA;
}

/**
Expand Down Expand Up @@ -73,11 +75,12 @@ public boolean hasError() {
private static class ErrnoConstants {

// These are set in JNI.
private int ENOENT;
private int EACCES;
private int ELOOP;
private int ENOTDIR;
private int ENAMETOOLONG;
private int errnoENOENT;
private int errnoEACCES;
private int errnoELOOP;
private int errnoENOTDIR;
private int errnoENAMETOOLONG;
private int errnoENODATA;

public static ErrnoConstants getErrnoConstants() {
ErrnoConstants constants = new ErrnoConstants();
Expand Down
11 changes: 6 additions & 5 deletions src/main/native/unix_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,12 @@ extern "C" JNIEXPORT void JNICALL
Java_com_google_devtools_build_lib_unix_ErrnoFileStatus_00024ErrnoConstants_initErrnoConstants( // NOLINT
JNIEnv *env, jobject errno_constants) {
jclass clazz = env->GetObjectClass(errno_constants);
SetIntField(env, clazz, errno_constants, "ENOENT", ENOENT);
SetIntField(env, clazz, errno_constants, "EACCES", EACCES);
SetIntField(env, clazz, errno_constants, "ELOOP", ELOOP);
SetIntField(env, clazz, errno_constants, "ENOTDIR", ENOTDIR);
SetIntField(env, clazz, errno_constants, "ENAMETOOLONG", ENAMETOOLONG);
SetIntField(env, clazz, errno_constants, "errnoENOENT", ENOENT);
SetIntField(env, clazz, errno_constants, "errnoEACCES", EACCES);
SetIntField(env, clazz, errno_constants, "errnoELOOP", ELOOP);
SetIntField(env, clazz, errno_constants, "errnoENOTDIR", ENOTDIR);
SetIntField(env, clazz, errno_constants, "errnoENAMETOOLONG", ENAMETOOLONG);
SetIntField(env, clazz, errno_constants, "errnoENODATA", ENODATA);
}

namespace {
Expand Down

0 comments on commit b3baae9

Please sign in to comment.