strip.c (623B)
1 #include <stddef.h> 2 3 char* strip_be(char *value, size_t *len) { 4 int i; 5 char *p; 6 7 p = value; 8 for (i = 0; i < *len; i++) { 9 if (*p & 0xff) { 10 break; 11 } 12 p++; 13 } 14 *len -= i; 15 if (!*len) { 16 *len = 1; 17 p--; 18 } 19 return p; 20 } 21 22 int strap_be(const char *in, size_t in_len, char *out, size_t out_len) { 23 int i; 24 int c; 25 char *p; 26 char mask; 27 28 if (in_len > out_len) { 29 return 1; 30 } 31 if (in_len == 0) { 32 return 1; 33 } 34 35 mask = 0; 36 if (*in & 0x80) { 37 mask = 0xff; 38 } 39 for (i = 0; i < 4; i++) { 40 *(out+i) = mask; 41 } 42 43 c = out_len - in_len; 44 p = out + c; 45 for (i = 0; i < in_len; i++) { 46 *(p+i) = *(in+i); 47 } 48 49 return 0; 50 }