9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

fromstring.c (422B)


      1 #include <string.h>
      2 
      3 #include <deserialize.h>
      4 
      5 char *
      6 fromstring(unsigned char *p, int *n, int max, char *s, int size)
      7 {
      8         int len;
      9 
     10 	if (*n == -1)
     11 		goto error;
     12 
     13 	len = frombytes(p, n, max, 2);
     14 	if (len == -1)
     15 		goto error;
     16 
     17 	if (*n + len > max)
     18 		goto error;
     19 
     20 	if (len >= size)
     21 		goto error;
     22 
     23 	if (s) {
     24 		memcpy(s, p + *n, len);
     25 		s[len] = '\0';
     26 	}
     27 	*n += len;
     28 
     29         return s;
     30 
     31 error:
     32 	*n = -1;
     33 	return NULL;
     34 }