Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  3.  
  4. #include <signal.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. char *sys_siglist[NSIG + 1]; /* initially all-zero */
  9.  
  10. static const char *known_signal[] = {
  11.   "Abort termination",
  12.   "Floating-point exception",
  13.   "Illegal instruction",
  14.   "Segmentation violation",
  15.   "Software termination signal",
  16.   "Alarm clock",
  17.   "Hangup",
  18.   "Interrupt",
  19.   "Kill",
  20.   "Write on pipe with no one to read it",
  21.   "Quit",
  22.   "User-defined signal 1",
  23.   "User-defined signal 2",
  24.   "Floating-point co-processor not present",
  25.   "Debugger/Breakpoint instruction",
  26.   "Timer tick signal",
  27.   "Profiler signal"
  28. };
  29.  
  30. static char unknown_signal[]  = "Unknown signal";
  31.  
  32. static void
  33. put_hex_digits (char *str, int num, size_t idx)
  34. {
  35.   static char xdigits[] = "0123456789ABCDEF";
  36.  
  37.   str[idx] = xdigits[num / 16];
  38.   str[idx + 1] = xdigits[num & 15];
  39. }
  40.  
  41. static char *
  42. xstrdup (const char *src)
  43. {
  44.   if (src)
  45.   {
  46.     size_t src_size = strlen (src) + 1;
  47.     char *new = (char *)malloc (src_size);
  48.  
  49.     if (new)
  50.     {
  51.       memcpy (new, src, src_size);
  52.       return new;
  53.     }
  54.   }
  55.  
  56.   return NULL;
  57. }
  58.  
  59. static int signum;
  60.  
  61. static void
  62. fill_dull_names (const char *template, size_t tpl_size, int count)
  63. {
  64.   int i;
  65.  
  66.   for (i = 0; i < count; i++)
  67.   {
  68.     char *signame = (char *)malloc (tpl_size);
  69.  
  70.     memcpy (signame, template, tpl_size);
  71.     put_hex_digits (signame, i, tpl_size - 3);
  72.     sys_siglist[signum++] = signame;
  73.   }
  74. }
  75.  
  76. static void __attribute__((constructor))
  77. init_sys_siglist (void)
  78. {
  79.   static char int_name[]   = "Interrupt XXh";
  80.   static size_t int_size   = sizeof(int_name);
  81.   static char excpt_name[] = "Exception XXh";
  82.   static size_t excpt_size = sizeof(excpt_name);
  83.   int i;
  84.  
  85.   signum = 0;
  86.  
  87.   fill_dull_names (int_name, int_size, 256);
  88.   fill_dull_names (excpt_name, excpt_size, 32);
  89.  
  90.   for (i = 0; i < 17; i++)
  91.     sys_siglist[signum++] = xstrdup (known_signal[i]);
  92.  
  93.   for (i = 305; i < 320; i++)
  94.     sys_siglist[signum++] = xstrdup (unknown_signal);
  95.  
  96.   sys_siglist[signum] = 0;
  97. }
  98.