Browse Source

feat(gblibc): add strsignal()

greatbridf 2 years ago
parent
commit
2252c898bf
3 changed files with 36 additions and 0 deletions
  1. 17 0
      gblibc/include/signal.h
  2. 2 0
      gblibc/include/string.h
  3. 17 0
      gblibc/src/string.c

+ 17 - 0
gblibc/include/signal.h

@@ -0,0 +1,17 @@
+#ifndef __GBLIBC_SIGNAL_H_
+#define __GBLIBC_SIGNAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define SIGINT 2
+#define SIGQUIT 3
+#define SIGPIPE 13
+#define SIGSTOP 19
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 2 - 0
gblibc/include/string.h

@@ -41,6 +41,8 @@ char* stpncpy(char* dst, const char* src, size_t n);
 char* strdup(const char* str);
 char* strndup(const char* str, size_t n);
 
+char* strsignal(int sig);
+
 #ifdef __cplusplus
 }
 #endif

+ 17 - 0
gblibc/src/string.c

@@ -1,5 +1,6 @@
 #include <ctype.h>
 #include <errno.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -274,3 +275,19 @@ char* strdup(const char* str)
 {
     return strndup(str, __SIZE_MAX__);
 }
+
+char* strsignal(int sig)
+{
+    switch (sig) {
+    default:
+        return "Unknown signal";
+    case SIGINT:
+        return "Interrupt";
+    case SIGQUIT:
+        return "Quit";
+    case SIGSTOP:
+        return "Stopped (signal)";
+    case SIGPIPE:
+        return "Broken pipe";
+    }
+}