Clean up some compiler warnings for unix_jni, and some C++ code formatting issues. PiperOrigin-RevId: 402584581
diff --git a/src/main/native/unix_jni.cc b/src/main/native/unix_jni.cc index e16e7f2..fa01f35 100644 --- a/src/main/native/unix_jni.cc +++ b/src/main/native/unix_jni.cc
@@ -1175,7 +1175,7 @@ Java_com_google_devtools_build_lib_unix_NativePosixSystem_sysctlbynameGetLong( JNIEnv *env, jclass clazz, jstring name) { const char *name_chars = GetStringLatin1Chars(env, name); - long r; + int64_t r; size_t len = sizeof(r); if (portable_sysctlbyname(name_chars, &r, &len) == -1) { PostException(env, errno, std::string("sysctlbyname(") + name_chars + ")");
diff --git a/src/main/native/unix_jni.h b/src/main/native/unix_jni.h index bdc8ef8..4138f8c 100644 --- a/src/main/native/unix_jni.h +++ b/src/main/native/unix_jni.h
@@ -93,7 +93,7 @@ size_t size, bool *attr_not_found); // Run sysctlbyname(3), only available on darwin -int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep); +int portable_sysctlbyname(const char *name_chars, void *mibp, size_t *sizep); // Used to surround an region that we want sleep disabled for. // push_disable_sleep to start the area.
diff --git a/src/main/native/unix_jni_bsd.cc b/src/main/native/unix_jni_bsd.cc index f043013..c4166ff 100644 --- a/src/main/native/unix_jni_bsd.cc +++ b/src/main/native/unix_jni_bsd.cc
@@ -109,7 +109,7 @@ #endif } -int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) { +int portable_sysctlbyname(const char *name_chars, void *mibp, size_t *sizep) { #if defined(HAVE_SYSCTLBYNAME) return sysctlbyname(name_chars, mibp, sizep, nullptr, 0); #else
diff --git a/src/main/native/unix_jni_darwin.cc b/src/main/native/unix_jni_darwin.cc index 48ce07b..10e52bc 100644 --- a/src/main/native/unix_jni_darwin.cc +++ b/src/main/native/unix_jni_darwin.cc
@@ -12,13 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/main/native/unix_jni.h" - +#include <IOKit/IOMessage.h> +#include <IOKit/pwr_mgt/IOPMLib.h> #include <assert.h> #include <errno.h> #include <fcntl.h> -#include <IOKit/IOMessage.h> -#include <IOKit/pwr_mgt/IOPMLib.h> #include <os/log.h> #include <stdlib.h> #include <string.h> @@ -34,6 +32,8 @@ #include <mutex> // NOLINT #include <string> +#include "src/main/native/unix_jni.h" + namespace blaze_jni { const int PATH_MAX2 = PATH_MAX * 2; @@ -50,9 +50,8 @@ return string(buf); } - -int portable_fstatat( - int dirfd, char *name, portable_stat_struct *statbuf, int flags) { +int portable_fstatat(int dirfd, char *name, portable_stat_struct *statbuf, + int flags) { char dirPath[PATH_MAX2]; // Have enough room for relative path // No fstatat under darwin, simulate it @@ -70,13 +69,13 @@ return -1; } int l = strlen(dirPath); - if (dirPath[l-1] != '/') { + if (dirPath[l - 1] != '/') { // dirPath is twice the PATH_MAX size, we always have room for the extra / dirPath[l] = '/'; - dirPath[l+1] = 0; + dirPath[l + 1] = 0; l++; } - strncat(dirPath, name, PATH_MAX2-l-1); + strncat(dirPath, name, PATH_MAX2 - l - 1); char *newpath = realpath(dirPath, nullptr); // this resolve the relative path if (newpath == nullptr) { return -1; @@ -126,7 +125,7 @@ return result; } -int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) { +int portable_sysctlbyname(const char *name_chars, void *mibp, size_t *sizep) { return sysctlbyname(name_chars, mibp, sizep, nullptr, 0); }
diff --git a/src/main/native/unix_jni_linux.cc b/src/main/native/unix_jni_linux.cc index 19cf162..e54c180 100644 --- a/src/main/native/unix_jni_linux.cc +++ b/src/main/native/unix_jni_linux.cc
@@ -89,7 +89,7 @@ return result; } -int portable_sysctlbyname(const char *name_chars, long *mibp, size_t *sizep) { +int portable_sysctlbyname(const char *name_chars, void *mibp, size_t *sizep) { errno = ENOSYS; return -1; }