Add strsignal(3) to Libcore.os.
Bug: 8322568
Change-Id: Iab9a782181a663719b88f090f474b66d24b69258
diff --git a/luni/src/main/java/libcore/io/ForwardingOs.java b/luni/src/main/java/libcore/io/ForwardingOs.java
index 1c582ca..2de13ae 100644
--- a/luni/src/main/java/libcore/io/ForwardingOs.java
+++ b/luni/src/main/java/libcore/io/ForwardingOs.java
@@ -130,6 +130,7 @@
public StructStat stat(String path) throws ErrnoException { return os.stat(path); }
public StructStatFs statfs(String path) throws ErrnoException { return os.statfs(path); }
public String strerror(int errno) { return os.strerror(errno); }
+ public String strsignal(int signal) { return os.strsignal(signal); }
public void symlink(String oldPath, String newPath) throws ErrnoException { os.symlink(oldPath, newPath); }
public long sysconf(int name) { return os.sysconf(name); }
public void tcdrain(FileDescriptor fd) throws ErrnoException { os.tcdrain(fd); }
diff --git a/luni/src/main/java/libcore/io/Os.java b/luni/src/main/java/libcore/io/Os.java
index 28bf9ea..f3d2383 100644
--- a/luni/src/main/java/libcore/io/Os.java
+++ b/luni/src/main/java/libcore/io/Os.java
@@ -124,6 +124,7 @@
/* TODO: replace statfs with statvfs. */
public StructStatFs statfs(String path) throws ErrnoException;
public String strerror(int errno);
+ public String strsignal(int signal);
public void symlink(String oldPath, String newPath) throws ErrnoException;
public long sysconf(int name);
public void tcdrain(FileDescriptor fd) throws ErrnoException;
diff --git a/luni/src/main/java/libcore/io/Posix.java b/luni/src/main/java/libcore/io/Posix.java
index 147750e..e9d1da3 100644
--- a/luni/src/main/java/libcore/io/Posix.java
+++ b/luni/src/main/java/libcore/io/Posix.java
@@ -174,6 +174,7 @@
public native StructStat stat(String path) throws ErrnoException;
public native StructStatFs statfs(String path) throws ErrnoException;
public native String strerror(int errno);
+ public native String strsignal(int signal);
public native void symlink(String oldPath, String newPath) throws ErrnoException;
public native long sysconf(int name);
public native void tcdrain(FileDescriptor fd) throws ErrnoException;
diff --git a/luni/src/main/native/libcore_io_Posix.cpp b/luni/src/main/native/libcore_io_Posix.cpp
index e73b990..1daa83d 100644
--- a/luni/src/main/native/libcore_io_Posix.cpp
+++ b/luni/src/main/native/libcore_io_Posix.cpp
@@ -1280,6 +1280,10 @@
return env->NewStringUTF(message);
}
+static jstring Posix_strsignal(JNIEnv* env, jobject, jint signal) {
+ return env->NewStringUTF(strsignal(signal));
+}
+
static void Posix_symlink(JNIEnv* env, jobject, jstring javaOldPath, jstring javaNewPath) {
ScopedUtfChars oldPath(env, javaOldPath);
if (oldPath.c_str() == NULL) {
@@ -1451,6 +1455,7 @@
NATIVE_METHOD(Posix, stat, "(Ljava/lang/String;)Llibcore/io/StructStat;"),
NATIVE_METHOD(Posix, statfs, "(Ljava/lang/String;)Llibcore/io/StructStatFs;"),
NATIVE_METHOD(Posix, strerror, "(I)Ljava/lang/String;"),
+ NATIVE_METHOD(Posix, strsignal, "(I)Ljava/lang/String;"),
NATIVE_METHOD(Posix, symlink, "(Ljava/lang/String;Ljava/lang/String;)V"),
NATIVE_METHOD(Posix, sysconf, "(I)J"),
NATIVE_METHOD(Posix, tcdrain, "(Ljava/io/FileDescriptor;)V"),
diff --git a/luni/src/test/java/libcore/io/OsTest.java b/luni/src/test/java/libcore/io/OsTest.java
index a15bbdd..5e0e8c7 100644
--- a/luni/src/test/java/libcore/io/OsTest.java
+++ b/luni/src/test/java/libcore/io/OsTest.java
@@ -129,4 +129,9 @@
private void checkNoSockName(FileDescriptor fd) throws Exception {
checkNoName(Libcore.os.getsockname(fd));
}
+
+ public void test_strsignal() throws Exception {
+ assertEquals("Killed", Libcore.os.strsignal(9));
+ assertEquals("Unknown signal -1", Libcore.os.strsignal(-1));
+ }
}