skalibs

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

ucharn_scan.c (355B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/fmtscan.h>
      4 
      5 size_t ucharn_scan (char const *s, char *key, size_t n)
      6 {
      7   size_t i = 0 ;
      8   for (; i < n ; i++)
      9   {
     10     unsigned char c = fmtscan_num(s[2*i], 16) ;
     11     if (c > 0xF) return 0 ;
     12     key[i] = c << 4 ;
     13     c = fmtscan_num(s[2*i+1], 16) ;
     14     if (c > 0xF) return 0 ;
     15     key[i] += c ;
     16   }
     17   return n << 1 ;
     18 }