/* Read hex string representation to 'data' repr. * takes an allocated buf for the data and the string * len is the length of buf */ static void read_hex_string (dataptr buf, size_t len, char *string) { size_t str_len = strlen(string); size_t read = (len < str_len/2 ? len : str_len/2); char str[3]; for (int i = 0; i < read; i++) { strncpy(str, string+2*i, 2); str[3] = '\0'; buf[i] = strtol(str, NULL, 16); //fprintf(stderr, "%s = %02x\n", str, strtol(str, NULL, 16)); } }