skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

ucspi_get.c (442B)


      1 /* ISC license. */
      2 
      3 #include <errno.h>
      4 #include <string.h>
      5 #include <stdlib.h>
      6 #include <skalibs/env.h>
      7 
      8 char const *ucspi_get (char const *s)
      9 {
     10   char const *x = getenv("PROTO") ;
     11   if (x)
     12   {
     13     size_t len = strlen(s) ;
     14     size_t xlen = strlen(x) ;
     15     char tmp[len + xlen + 1] ;
     16     memcpy(tmp, x, xlen) ;
     17     memcpy(tmp + xlen, s, len + 1) ;
     18     x = getenv(tmp) ;
     19     if (!x) errno = ENOENT ;
     20   }
     21   else errno = EINVAL ;
     22   return x ;
     23 }