tutil.c - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
tutil.c (786B)
---
     1 #include "std.h"
     2 #include "dat.h"
     3 
     4 static int
     5 unhex(char c)
     6 {
     7         if('0' <= c && c <= '9')
     8                 return c-'0';
     9         if('a' <= c && c <= 'f')
    10                 return c-'a'+10;
    11         if('A' <= c && c <= 'F')
    12                 return c-'A'+10;
    13         abort();
    14         return -1;
    15 }
    16 
    17 int
    18 hexparse(char *hex, uchar *dat, int ndat)
    19 {
    20         int i, n;
    21 
    22         n = strlen(hex);
    23         if(n%2)
    24                 return -1;
    25         n /= 2;
    26         if(n > ndat)
    27                 return -1;
    28         if(hex[strspn(hex, "0123456789abcdefABCDEF")] != '\0')
    29                 return -1;
    30         for(i=0; i