diff options
author | Elliott Hughes <enh@google.com> | 2014-01-31 11:19:40 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-01-31 11:19:40 -0800 |
commit | 081c0de9231d6fc2aa5e24bdcc21b5cde8a30f2b (patch) | |
tree | 097c1df16f5a8fa709e19cb1fcde9589cbb60294 /luni/src | |
parent | a4dc1a17120058d1604cf9c4fc4586cd044105ee (diff) | |
download | libcore-081c0de9231d6fc2aa5e24bdcc21b5cde8a30f2b.zip libcore-081c0de9231d6fc2aa5e24bdcc21b5cde8a30f2b.tar.gz libcore-081c0de9231d6fc2aa5e24bdcc21b5cde8a30f2b.tar.bz2 |
Rename our 'realpath' because it isn't the same as realpath(3).
Change-Id: I7b830d485c1ff769993233b7ea69e36b354f3259
Diffstat (limited to 'luni/src')
-rw-r--r-- | luni/src/main/java/java/io/File.java | 7 | ||||
-rw-r--r-- | luni/src/main/native/canonicalize_path.cpp (renamed from luni/src/main/native/realpath.cpp) | 2 | ||||
-rw-r--r-- | luni/src/main/native/java_io_File.cpp | 196 | ||||
-rw-r--r-- | luni/src/main/native/sub.mk | 120 |
4 files changed, 163 insertions, 162 deletions
diff --git a/luni/src/main/java/java/io/File.java b/luni/src/main/java/java/io/File.java index 123109b..9c6de0b 100644 --- a/luni/src/main/java/java/io/File.java +++ b/luni/src/main/java/java/io/File.java @@ -411,14 +411,15 @@ public class File implements Serializable, Comparable<File> { * if an I/O error occurs. */ public String getCanonicalPath() throws IOException { - return realpath(getAbsolutePath()); + return canonicalizePath(getAbsolutePath()); } + private static native String canonicalizePath(String path); + /** - * TODO: move this stuff to libcore.os. + * TODO: move this to libcore.os. * @hide */ - private static native String realpath(String path); private static native String readlink(String path); /** diff --git a/luni/src/main/native/realpath.cpp b/luni/src/main/native/canonicalize_path.cpp index d1960a4..b2a2a01 100644 --- a/luni/src/main/native/realpath.cpp +++ b/luni/src/main/native/canonicalize_path.cpp @@ -45,7 +45,7 @@ * * This implementation also removes all the fixed-length buffers of the C original. */ -bool realpath(const char* path, std::string& resolved) { +bool canonicalize_path(const char* path, std::string& resolved) { // 'path' must be an absolute path. if (path[0] != '/') { errno = EINVAL; diff --git a/luni/src/main/native/java_io_File.cpp b/luni/src/main/native/java_io_File.cpp index c217ea2..386231d 100644 --- a/luni/src/main/native/java_io_File.cpp +++ b/luni/src/main/native/java_io_File.cpp @@ -40,95 +40,95 @@ #include <utime.h> static jstring File_readlink(JNIEnv* env, jclass, jstring javaPath) { - ScopedUtfChars path(env, javaPath); - if (path.c_str() == NULL) { - return NULL; - } - - std::string result; - if (!readlink(path.c_str(), result)) { - jniThrowIOException(env, errno); - return NULL; - } - return env->NewStringUTF(result.c_str()); + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return NULL; + } + + std::string result; + if (!readlink(path.c_str(), result)) { + jniThrowIOException(env, errno); + return NULL; + } + return env->NewStringUTF(result.c_str()); } -static jstring File_realpath(JNIEnv* env, jclass, jstring javaPath) { - ScopedUtfChars path(env, javaPath); - if (path.c_str() == NULL) { - return NULL; - } - - extern bool realpath(const char* path, std::string& resolved); - std::string result; - if (!realpath(path.c_str(), result)) { - jniThrowIOException(env, errno); - return NULL; - } - return env->NewStringUTF(result.c_str()); +static jstring File_canonicalizePath(JNIEnv* env, jclass, jstring javaPath) { + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return NULL; + } + + extern bool canonicalize_path(const char* path, std::string& resolved); + std::string result; + if (!canonicalize_path(path.c_str(), result)) { + jniThrowIOException(env, errno); + return NULL; + } + return env->NewStringUTF(result.c_str()); } static jboolean File_setLastModifiedImpl(JNIEnv* env, jclass, jstring javaPath, jlong ms) { - ScopedUtfChars path(env, javaPath); - if (path.c_str() == NULL) { - return JNI_FALSE; - } - - // We want to preserve the access time. - struct stat sb; - if (stat(path.c_str(), &sb) == -1) { - return JNI_FALSE; - } - - // TODO: we could get microsecond resolution with utimes(3), "legacy" though it is. - utimbuf times; - times.actime = sb.st_atime; - times.modtime = static_cast<time_t>(ms / 1000); - return (utime(path.c_str(), ×) == 0); + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return JNI_FALSE; + } + + // We want to preserve the access time. + struct stat sb; + if (stat(path.c_str(), &sb) == -1) { + return JNI_FALSE; + } + + // TODO: we could get microsecond resolution with utimes(3), "legacy" though it is. + utimbuf times; + times.actime = sb.st_atime; + times.modtime = static_cast<time_t>(ms / 1000); + return (utime(path.c_str(), ×) == 0); } // Iterates over the filenames in the given directory. class ScopedReaddir { -public: - ScopedReaddir(const char* path) { - mDirStream = opendir(path); - mIsBad = (mDirStream == NULL); + public: + ScopedReaddir(const char* path) { + mDirStream = opendir(path); + mIsBad = (mDirStream == NULL); + } + + ~ScopedReaddir() { + if (mDirStream != NULL) { + closedir(mDirStream); } + } - ~ScopedReaddir() { - if (mDirStream != NULL) { - closedir(mDirStream); - } + // Returns the next filename, or NULL. + const char* next() { + if (mIsBad) { + return NULL; } - - // Returns the next filename, or NULL. - const char* next() { - if (mIsBad) { - return NULL; - } - errno = 0; - dirent* result = readdir(mDirStream); - if (result != NULL) { - return result->d_name; - } - if (errno != 0) { - mIsBad = true; - } - return NULL; + errno = 0; + dirent* result = readdir(mDirStream); + if (result != NULL) { + return result->d_name; } - - // Has an error occurred on this stream? - bool isBad() const { - return mIsBad; + if (errno != 0) { + mIsBad = true; } + return NULL; + } -private: - DIR* mDirStream; - bool mIsBad; + // Has an error occurred on this stream? + bool isBad() const { + return mIsBad; + } - // Disallow copy and assignment. - ScopedReaddir(const ScopedReaddir&); - void operator=(const ScopedReaddir&); + private: + DIR* mDirStream; + bool mIsBad; + + // Disallow copy and assignment. + ScopedReaddir(const ScopedReaddir&); + void operator=(const ScopedReaddir&); }; typedef std::vector<std::string> DirEntries; @@ -136,38 +136,38 @@ typedef std::vector<std::string> DirEntries; // Reads the directory referred to by 'pathBytes', adding each directory entry // to 'entries'. static bool readDirectory(JNIEnv* env, jstring javaPath, DirEntries& entries) { - ScopedUtfChars path(env, javaPath); - if (path.c_str() == NULL) { - return false; - } - - ScopedReaddir dir(path.c_str()); - const char* filename; - while ((filename = dir.next()) != NULL) { - if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) { - // TODO: this hides allocation failures from us. Push directory iteration up into Java? - entries.push_back(filename); - } + ScopedUtfChars path(env, javaPath); + if (path.c_str() == NULL) { + return false; + } + + ScopedReaddir dir(path.c_str()); + const char* filename; + while ((filename = dir.next()) != NULL) { + if (strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) { + // TODO: this hides allocation failures from us. Push directory iteration up into Java? + entries.push_back(filename); } - return !dir.isBad(); + } + return !dir.isBad(); } static jobjectArray File_listImpl(JNIEnv* env, jclass, jstring javaPath) { - // Read the directory entries into an intermediate form. - DirEntries entries; - if (!readDirectory(env, javaPath, entries)) { - return NULL; - } - // Translate the intermediate form into a Java String[]. - return toStringArray(env, entries); + // Read the directory entries into an intermediate form. + DirEntries entries; + if (!readDirectory(env, javaPath, entries)) { + return NULL; + } + // Translate the intermediate form into a Java String[]. + return toStringArray(env, entries); } static JNINativeMethod gMethods[] = { - NATIVE_METHOD(File, listImpl, "(Ljava/lang/String;)[Ljava/lang/String;"), - NATIVE_METHOD(File, readlink, "(Ljava/lang/String;)Ljava/lang/String;"), - NATIVE_METHOD(File, realpath, "(Ljava/lang/String;)Ljava/lang/String;"), - NATIVE_METHOD(File, setLastModifiedImpl, "(Ljava/lang/String;J)Z"), + NATIVE_METHOD(File, canonicalizePath, "(Ljava/lang/String;)Ljava/lang/String;"), + NATIVE_METHOD(File, listImpl, "(Ljava/lang/String;)[Ljava/lang/String;"), + NATIVE_METHOD(File, readlink, "(Ljava/lang/String;)Ljava/lang/String;"), + NATIVE_METHOD(File, setLastModifiedImpl, "(Ljava/lang/String;J)Z"), }; void register_java_io_File(JNIEnv* env) { - jniRegisterNativeMethods(env, "java/io/File", gMethods, NELEM(gMethods)); + jniRegisterNativeMethods(env, "java/io/File", gMethods, NELEM(gMethods)); } diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk index 4e10cc7..e8b6e4a 100644 --- a/luni/src/main/native/sub.mk +++ b/luni/src/main/native/sub.mk @@ -4,69 +4,69 @@ # or BUILD_*_LIBRARY. LOCAL_SRC_FILES := \ - AsynchronousSocketCloseMonitor.cpp \ - ExecStrings.cpp \ - IcuUtilities.cpp \ - JniException.cpp \ - NetworkUtilities.cpp \ - Register.cpp \ - ZipUtilities.cpp \ - cbigint.cpp \ - java_io_Console.cpp \ - java_io_File.cpp \ - java_io_ObjectStreamClass.cpp \ - java_lang_Character.cpp \ - java_lang_Double.cpp \ - java_lang_Float.cpp \ - java_lang_Math.cpp \ - java_lang_ProcessManager.cpp \ - java_lang_RealToString.cpp \ - java_lang_StrictMath.cpp \ - java_lang_StringToReal.cpp \ - java_lang_System.cpp \ - java_math_NativeBN.cpp \ - java_nio_ByteOrder.cpp \ - java_nio_charset_Charsets.cpp \ - java_text_Bidi.cpp \ - java_util_jar_StrictJarFile.cpp \ - java_util_regex_Matcher.cpp \ - java_util_regex_Pattern.cpp \ - java_util_zip_Adler32.cpp \ - java_util_zip_CRC32.cpp \ - java_util_zip_Deflater.cpp \ - java_util_zip_Inflater.cpp \ - libcore_icu_AlphabeticIndex.cpp \ - libcore_icu_DateIntervalFormat.cpp \ - libcore_icu_ICU.cpp \ - libcore_icu_NativeBreakIterator.cpp \ - libcore_icu_NativeCollation.cpp \ - libcore_icu_NativeConverter.cpp \ - libcore_icu_NativeDecimalFormat.cpp \ - libcore_icu_NativeIDN.cpp \ - libcore_icu_NativeNormalizer.cpp \ - libcore_icu_NativePluralRules.cpp \ - libcore_icu_TimeZoneNames.cpp \ - libcore_icu_Transliterator.cpp \ - libcore_io_AsynchronousCloseMonitor.cpp \ - libcore_io_Memory.cpp \ - libcore_io_OsConstants.cpp \ - libcore_io_Posix.cpp \ - org_apache_harmony_xml_ExpatParser.cpp \ - readlink.cpp \ - realpath.cpp \ - sun_misc_Unsafe.cpp \ - valueOf.cpp + AsynchronousSocketCloseMonitor.cpp \ + ExecStrings.cpp \ + IcuUtilities.cpp \ + JniException.cpp \ + NetworkUtilities.cpp \ + Register.cpp \ + ZipUtilities.cpp \ + canonicalize_path.cpp \ + cbigint.cpp \ + java_io_Console.cpp \ + java_io_File.cpp \ + java_io_ObjectStreamClass.cpp \ + java_lang_Character.cpp \ + java_lang_Double.cpp \ + java_lang_Float.cpp \ + java_lang_Math.cpp \ + java_lang_ProcessManager.cpp \ + java_lang_RealToString.cpp \ + java_lang_StrictMath.cpp \ + java_lang_StringToReal.cpp \ + java_lang_System.cpp \ + java_math_NativeBN.cpp \ + java_nio_ByteOrder.cpp \ + java_nio_charset_Charsets.cpp \ + java_text_Bidi.cpp \ + java_util_jar_StrictJarFile.cpp \ + java_util_regex_Matcher.cpp \ + java_util_regex_Pattern.cpp \ + java_util_zip_Adler32.cpp \ + java_util_zip_CRC32.cpp \ + java_util_zip_Deflater.cpp \ + java_util_zip_Inflater.cpp \ + libcore_icu_AlphabeticIndex.cpp \ + libcore_icu_DateIntervalFormat.cpp \ + libcore_icu_ICU.cpp \ + libcore_icu_NativeBreakIterator.cpp \ + libcore_icu_NativeCollation.cpp \ + libcore_icu_NativeConverter.cpp \ + libcore_icu_NativeDecimalFormat.cpp \ + libcore_icu_NativeIDN.cpp \ + libcore_icu_NativeNormalizer.cpp \ + libcore_icu_NativePluralRules.cpp \ + libcore_icu_TimeZoneNames.cpp \ + libcore_icu_Transliterator.cpp \ + libcore_io_AsynchronousCloseMonitor.cpp \ + libcore_io_Memory.cpp \ + libcore_io_OsConstants.cpp \ + libcore_io_Posix.cpp \ + org_apache_harmony_xml_ExpatParser.cpp \ + readlink.cpp \ + sun_misc_Unsafe.cpp \ + valueOf.cpp \ LOCAL_C_INCLUDES += \ - external/icu4c/common \ - external/icu4c/i18n \ - external/openssl/include \ - external/zlib \ - system/core/include + external/icu4c/common \ + external/icu4c/i18n \ + external/openssl/include \ + external/zlib \ + system/core/include \ LOCAL_STATIC_LIBRARIES += \ - libfdlibm + libfdlibm \ LOCAL_SHARED_LIBRARIES += \ - liblog \ - libnativehelper + liblog \ + libnativehelper \ |