strsignal.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 648 行 · 第 1/2 页

C
648
字号
#ifndef HAVE_SYS_SIGLIST  /* Now attempt to allocate the sys_siglist table, zero it out, and then     initialize it from the statically initialized signal_table. */  if (sys_siglist == NULL)    {      nbytes = num_signal_names * sizeof (char *);      if ((sys_siglist = (const char **) malloc (nbytes)) != NULL)	{	  memset (sys_siglist, 0, nbytes);	  sys_nsig = num_signal_names;	  for (eip = signal_table; eip -> name != NULL; eip++)	    {	      sys_siglist[eip -> value] = eip -> msg;	    }	}    }#endif}/*NAME	signo_max -- return the max signo valueSYNOPSIS	int signo_max ();DESCRIPTION	Returns the maximum signo value for which a corresponding symbolic	name or message is available.  Note that in the case where	we use the sys_siglist supplied by the system, it is possible for	there to be more symbolic names than messages, or vice versa.	In fact, the manual page for psignal(3b) explicitly warns that one	should check the size of the table (NSIG) before indexing it,	since new signal codes may be added to the system before they are	added to the table.  Thus NSIG might be smaller than value	implied by the largest signo value defined in <signal.h>.	We return the maximum value that can be used to obtain a meaningful	symbolic name or message.*/intsigno_max (){  int maxsize;  if (signal_names == NULL)    {      init_signal_tables ();    }  maxsize = MAX (sys_nsig, num_signal_names);  return (maxsize - 1);}/*NAME	strsignal -- map a signal number to a signal message stringSYNOPSIS	const char *strsignal (int signo)DESCRIPTION	Maps an signal number to an signal message string, the contents of	which are implementation defined.  On systems which have the external	variable sys_siglist, these strings will be the same as the ones used	by psignal().	If the supplied signal number is within the valid range of indices	for the sys_siglist, but no message is available for the particular	signal number, then returns the string "Signal NUM", where NUM is the	signal number.	If the supplied signal number is not a valid index into sys_siglist,	returns NULL.	The returned string is only guaranteed to be valid only until the	next call to strsignal.*/#ifndef HAVE_STRSIGNALconst char *strsignal (signo)  int signo;{  const char *msg;  static char buf[32];#ifndef HAVE_SYS_SIGLIST  if (signal_names == NULL)    {      init_signal_tables ();    }#endif  if ((signo < 0) || (signo >= sys_nsig))    {      /* Out of range, just return NULL */      msg = NULL;    }  else if ((sys_siglist == NULL) || (sys_siglist[signo] == NULL))    {      /* In range, but no sys_siglist or no entry at this index. */      sprintf (buf, "Signal %d", signo);      msg = (const char *) buf;    }  else    {      /* In range, and a valid message.  Just return the message. */      msg = (const char *) sys_siglist[signo];    }    return (msg);}#endif /* ! HAVE_STRSIGNAL *//*NAME	strsigno -- map an signal number to a symbolic name stringSYNOPSIS	const char *strsigno (int signo)DESCRIPTION	Given an signal number, returns a pointer to a string containing	the symbolic name of that signal number, as found in <signal.h>.	If the supplied signal number is within the valid range of indices	for symbolic names, but no name is available for the particular	signal number, then returns the string "Signal NUM", where NUM is	the signal number.	If the supplied signal number is not within the range of valid	indices, then returns NULL.BUGS	The contents of the location pointed to are only guaranteed to be	valid until the next call to strsigno.*/const char *strsigno (signo)  int signo;{  const char *name;  static char buf[32];  if (signal_names == NULL)    {      init_signal_tables ();    }  if ((signo < 0) || (signo >= num_signal_names))    {      /* Out of range, just return NULL */      name = NULL;    }  else if ((signal_names == NULL) || (signal_names[signo] == NULL))    {      /* In range, but no signal_names or no entry at this index. */      sprintf (buf, "Signal %d", signo);      name = (const char *) buf;    }  else    {      /* In range, and a valid name.  Just return the name. */      name = signal_names[signo];    }  return (name);}/*NAME	strtosigno -- map a symbolic signal name to a numeric valueSYNOPSIS	int strtosigno (char *name)DESCRIPTION	Given the symbolic name of a signal, map it to a signal number.	If no translation is found, returns 0.*/intstrtosigno (name)     const char *name;{  int signo = 0;  if (name != NULL)    {      if (signal_names == NULL)	{	  init_signal_tables ();	}      for (signo = 0; signo < num_signal_names; signo++)	{	  if ((signal_names[signo] != NULL) &&	      (strcmp (name, signal_names[signo]) == 0))	    {	      break;	    }	}      if (signo == num_signal_names)	{	  signo = 0;	}    }  return (signo);}/*NAME	psignal -- print message about signal to stderrSYNOPSIS	void psignal (unsigned signo, char *message);DESCRIPTION	Print to the standard error the message, followed by a colon,	followed by the description of the signal specified by signo,	followed by a newline.*/#ifndef HAVE_PSIGNALvoidpsignal (signo, message)  unsigned signo;  char *message;{  if (signal_names == NULL)    {      init_signal_tables ();    }  if ((signo <= 0) || (signo >= sys_nsig))    {      fprintf (stderr, "%s: unknown signal\n", message);    }  else    {      fprintf (stderr, "%s: %s\n", message, sys_siglist[signo]);    }}#endif	/* ! HAVE_PSIGNAL *//* A simple little main that does nothing but print all the signal translations   if MAIN is defined and this file is compiled and linked. */#ifdef MAIN#include <stdio.h>intmain (){  int signo;  int maxsigno;  const char *name;  const char *msg;  maxsigno = signo_max ();  printf ("%d entries in names table.\n", num_signal_names);  printf ("%d entries in messages table.\n", sys_nsig);  printf ("%d is max useful index.\n", maxsigno);  /* Keep printing values until we get to the end of *both* tables, not     *either* table.  Note that knowing the maximum useful index does *not*     relieve us of the responsibility of testing the return pointer for     NULL. */  for (signo = 0; signo <= maxsigno; signo++)    {      name = strsigno (signo);      name = (name == NULL) ? "<NULL>" : name;      msg = strsignal (signo);      msg = (msg == NULL) ? "<NULL>" : msg;      printf ("%-4d%-18s%s\n", signo, name, msg);    }  return 0;}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?