File: scan_xlong.c

package info (click to toggle)
ucspi-tcp-src 0.88-15
  • links: PTS
  • area: non-free
  • in suites: lenny, squeeze
  • size: 1,380 kB
  • ctags: 761
  • sloc: ansic: 6,758; makefile: 854; sh: 312
file content (23 lines) | stat: -rw-r--r-- 447 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "scan.h"

static int fromhex(unsigned char c) {
  if (c>='0' && c<='9')
    return c-'0';
  else if (c>='A' && c<='F')
    return c-'A'+10;
  else if (c>='a' && c<='f')
    return c-'a'+10;
  return -1;
}

unsigned int scan_xlong(char *src,unsigned long *dest) {
  register const char *tmp=src;
  register int l=0;
  register unsigned char c;
  while ((c=fromhex(*tmp))<16) {
    l=(l<<4)+c;
    ++tmp;
  }
  *dest=l;
  return tmp-src;
}