9os

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

frombytes.c (339B)


      1 #include <deserialize.h>
      2 
      3 long long
      4 frombytes(unsigned char *bp, int *n, int max, int nbytes)
      5 {
      6 	unsigned i;
      7 	unsigned long long v;
      8 
      9 	if (*n == -1)
     10 		return 0;
     11 
     12 	if (*n + nbytes > max) {
     13 		*n = -1;
     14 		return -1;
     15 	}
     16 
     17 	bp += *n;
     18 	*n += nbytes;
     19 	v = 0;
     20 	for (i = 0; i < nbytes; i++)
     21 		v |= (unsigned long long) bp[i] << (8 * i);
     22 
     23 	return v;
     24 }