static jint harmony_io_openImpl(JNIEnv* env, jobject, jbyteArray pathByteArray, jint jflags) { int flags = 0; int mode = 0; // BEGIN android-changed // don't want default permissions to allow global access. switch(jflags) { case 0: flags = HyOpenRead; mode = 0; break; case 1: flags = HyOpenCreate | HyOpenWrite | HyOpenTruncate; mode = 0600; break; case 16: flags = HyOpenRead | HyOpenWrite | HyOpenCreate; mode = 0600; break; case 32: flags = HyOpenRead | HyOpenWrite | HyOpenCreate | HyOpenSync; mode = 0600; break; case 256: flags = HyOpenWrite | HyOpenCreate | HyOpenAppend; mode = 0600; break; } // BEGIN android-changed flags = EsTranslateOpenFlags(flags); ScopedByteArray path(env, pathByteArray); jint rc = TEMP_FAILURE_RETRY(open(&path[0], flags, mode)); if (rc == -1) { // Get the human-readable form of errno. char buffer[80]; const char* reason = jniStrError(errno, &buffer[0], sizeof(buffer)); // Construct a message that includes the path and the reason. // (pathByteCount already includes space for our trailing NUL.) size_t pathByteCount = env->GetArrayLength(pathByteArray); LocalArray<128> message(pathByteCount + 2 + strlen(reason) + 1); snprintf(&message[0], message.size(), "%s (%s)", &path[0], reason); // We always throw FileNotFoundException, regardless of the specific // failure. (This appears to be true of the RI too.) jniThrowException(env, "java/io/FileNotFoundException", &message[0]); } return rc; }
_fastvm_FileDescriptor__syncImpl( java_io_FileDescriptor_p self ) { int fd = self->m_descriptor; int rc = fsync(fd); if (rc == -1) { /* * If fd is a socket, then fsync(fd) is defined to fail with * errno EINVAL. This isn't actually cause for concern. * TODO: Look into not bothering to call fsync() at all if * we know we are dealing with a socket. */ if (errno != EINVAL) { char buf[BUFSIZ]; jniThrowException(env, "java/io/SyncFailedException", jniStrError(errno, buf, sizeof(buf))); } } }
static jstring roottools_strerror(JNIEnv* env, jint errorCode) { char buffer[256]; return env->NewStringUTF(jniStrError(errorCode, buffer, 256)); }
/* * Throw a java.io.IOException, generating the message from errno. */ int jniThrowIOException(JNIEnv* env, int errnum) { char buffer[80]; const char* message = jniStrError(errnum, buffer, sizeof(buffer)); return jniThrowException(env, "java/io/IOException", message); }