File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sudo / compat / sig2str.c
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 16:12:54 2014 UTC (10 years, 1 month ago) by misho
Branches: sudo, MAIN
CVS tags: v1_8_10p3_0, v1_8_10p3, HEAD
sudo v 1.8.10p3

    1: /*
    2:  * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com>
    3:  *
    4:  * Permission to use, copy, modify, and distribute this software for any
    5:  * purpose with or without fee is hereby granted, provided that the above
    6:  * copyright notice and this permission notice appear in all copies.
    7:  *
    8:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
    9:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   10:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   11:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   12:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   13:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   14:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   15:  */
   16: 
   17: #include <config.h>
   18: 
   19: #ifndef HAVE_SIG2STR
   20: 
   21: #include <sys/types.h>
   22: 
   23: #include <errno.h>
   24: #include <stdio.h>
   25: #ifdef STDC_HEADERS
   26: # include <stdlib.h>
   27: # include <stddef.h>
   28: #else
   29: # ifdef HAVE_STDLIB_H
   30: #  include <stdlib.h>
   31: # endif
   32: #endif /* STDC_HEADERS */
   33: #ifdef HAVE_STRING_H
   34: # include <string.h>
   35: #endif /* HAVE_STRING_H */
   36: #ifdef HAVE_STRINGS_H
   37: # include <strings.h>
   38: #endif /* HAVE_STRINGS_H */
   39: #include <signal.h>
   40: #include <unistd.h>
   41: 
   42: #include "missing.h"
   43: 
   44: #if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
   45: #  define sudo_sys_signame	sys_signame
   46: #elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
   47: #  define sudo_sys_signame	_sys_signame
   48: #elif defined(HAVE_DECL___SYS_SIGNAME) && HAVE_DECL___SYS_SIGNAME == 1
   49: #  define sudo_sys_signame	__sys_signame
   50: #elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
   51: #  define sudo_sys_signame	sys_sigabbrev
   52: #else
   53: # ifdef HAVE_SYS_SIGABBREV
   54:    /* sys_sigabbrev is not declared by glibc */
   55: #  define sudo_sys_signame	sys_sigabbrev
   56: # endif
   57: extern const char *const sudo_sys_signame[NSIG];
   58: #endif
   59: 
   60: /*
   61:  * Translate signal number to name.
   62:  */
   63: int
   64: sig2str(int signo, char *signame)
   65: {
   66: #if defined(SIGRTMIN) && defined(SIGRTMAX)
   67:     /* Realtime signal support as per Solaris. */
   68:     if (signo >= SIGRTMIN && signo <= SIGRTMAX) {
   69: 	snprintf(signame, SIG2STR_MAX, "RTMIN+%d", (signo - SIGRTMIN));
   70: 	return 0;
   71:     }
   72: #endif
   73:     if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
   74: 	strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);
   75: 	return 0;
   76:     }
   77:     errno = EINVAL;
   78:     return -1;
   79: }
   80: #endif /* HAVE_SIG2STR */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>