File: scan_hexdump.c

package info (click to toggle)
libowfat 0.28-6
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,068 kB
  • sloc: ansic: 12,863; makefile: 16
file content (20 lines) | stat: -rw-r--r-- 439 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "fmt.h"
#include "textcode.h"
#include "scan.h"

size_t scan_hexdump(const char *src,char *dest,size_t *destlen) {
  register const unsigned char* s=(const unsigned char*) src;
  size_t written=0,i;
  for (i=0; s[i]; ++i) {
    int j=scan_fromhex(s[i]);
    if (j<0) break;
    dest[written]=j<<4;
    j=scan_fromhex(s[i+1]);
    if (j<0) break;
    dest[written]|=j;
    ++i;
    ++written;
  }
  *destlen=written;
  return i;
}