Ignore:
Timestamp:
Aug 13, 2020, 11:49:06 AM (5 years ago)
Author:
bird
Message:

kash: Generate the signal names at compile time rather than lazily at runtime. This should be more efficient, though may cause trouble if cross building.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/kash/strsignal.c

    r3408 r3409  
    11/*
    2  * Fake sys_signame.
     2 * Fake strsignal (for Windows/MSC).
    33 */
    44
    55#include "shinstance.h" /* for MSC */
    66#include <string.h>
    7 #include <stdio.h>
    87
    9 static char sys_signame_initialized = 0;
    10 char sys_signame[NSIG][16];
    11 
    12 void init_sys_signame(void)
    13 {
    14         unsigned i;
    15         if (sys_signame_initialized)
    16                 return;
    17         for (i = 0; i < NSIG; ++i)
    18                 sprintf(sys_signame[i], "%d", i);
    19 #define SET_SIG_STR(sig) strcpy(sys_signame[SIG##sig], #sig);
    20 #ifdef SIGHUP
    21         SET_SIG_STR(HUP);
    22 #endif
    23 #ifdef SIGINT
    24         SET_SIG_STR(INT);
    25 #endif
    26 #ifdef SIGQUIT
    27         SET_SIG_STR(QUIT);
    28 #endif
    29 #ifdef SIGILL
    30         SET_SIG_STR(ILL);
    31 #endif
    32 #ifdef SIGTRAP
    33         SET_SIG_STR(TRAP);
    34 #endif
    35 #ifdef SIGABRT
    36         SET_SIG_STR(ABRT);
    37 #endif
    38 #ifdef SIGIOT
    39         SET_SIG_STR(IOT);
    40 #endif
    41 #ifdef SIGBUS
    42         SET_SIG_STR(BUS);
    43 #endif
    44 #ifdef SIGFPE
    45         SET_SIG_STR(FPE);
    46 #endif
    47 #ifdef SIGKILL
    48         SET_SIG_STR(KILL);
    49 #endif
    50 #ifdef SIGUSR1
    51         SET_SIG_STR(USR1);
    52 #endif
    53 #ifdef SIGSEGV
    54         SET_SIG_STR(SEGV);
    55 #endif
    56 #ifdef SIGUSR2
    57         SET_SIG_STR(USR2);
    58 #endif
    59 #ifdef SIGPIPE
    60         SET_SIG_STR(PIPE);
    61 #endif
    62 #ifdef SIGALRM
    63         SET_SIG_STR(ALRM);
    64 #endif
    65 #ifdef SIGTERM
    66         SET_SIG_STR(TERM);
    67 #endif
    68 #ifdef SIGSTKFLT
    69         SET_SIG_STR(STKFLT);
    70 #endif
    71 #ifdef SIGCHLD
    72         SET_SIG_STR(CHLD);
    73 #endif
    74 #ifdef SIGCONT
    75         SET_SIG_STR(CONT);
    76 #endif
    77 #ifdef SIGSTOP
    78         SET_SIG_STR(STOP);
    79 #endif
    80 #ifdef SIGTSTP
    81         SET_SIG_STR(TSTP);
    82 #endif
    83 #ifdef SIGTTIN
    84         SET_SIG_STR(TTIN);
    85 #endif
    86 #ifdef SIGTTOU
    87         SET_SIG_STR(TTOU);
    88 #endif
    89 #ifdef SIGURG
    90         SET_SIG_STR(URG);
    91 #endif
    92 #ifdef SIGXCPU
    93         SET_SIG_STR(XCPU);
    94 #endif
    95 #ifdef SIGXFSZ
    96         SET_SIG_STR(XFSZ);
    97 #endif
    98 #ifdef SIGVTALRM
    99         SET_SIG_STR(VTALRM);
    100 #endif
    101 #ifdef SIGPROF
    102         SET_SIG_STR(PROF);
    103 #endif
    104 #ifdef SIGWINCH
    105         SET_SIG_STR(WINCH);
    106 #endif
    107 #ifdef SIGIO
    108         SET_SIG_STR(IO);
    109 #endif
    110 #ifdef SIGPWR
    111         SET_SIG_STR(PWR);
    112 #endif
    113 #ifdef SIGSYS
    114         SET_SIG_STR(SYS);
    115 #endif
    116 #ifdef SIGBREAK
    117         SET_SIG_STR(BREAK);
    118 #endif
    119 #undef SET_SIG_STR
    120         sys_signame_initialized = 1;
    121 }
    122 
    123 #if defined(_MSC_VER)
    1248const char *strsignal(int iSig)
    1259{
    126     if (!sys_signame_initialized)
    127         init_sys_signame();
    12810    if (iSig < NSIG)
    12911        return sys_signame(iSig);
    13012    return NULL;
    13113}
    132 #endif
    13314
Note: See TracChangeset for help on using the changeset viewer.