parse.c revision 19c78dc07fce2d6f39b5e541562afc3ca1ea38ff
1/* 2 * parse.c --- UUID parsing 3 * 4 * Copyright (C) 1996, 1997 Theodore Ts'o. 5 * 6 * %Begin-Header% 7 * This file may be redistributed under the terms of the GNU Public 8 * License. 9 * %End-Header% 10 */ 11 12#include <stdlib.h> 13#include <stdio.h> 14#include <ctype.h> 15 16#include "uuidP.h" 17 18int uuid_parse(char *in, uuid_t uu) 19{ 20 struct uuid uuid; 21 int i; 22 char *cp, buf[3]; 23 24 if (strlen(in) != 36) 25 return -1; 26 for (i=0, cp = in; i <= 36; i++,cp++) { 27 if ((i == 8) || (i == 13) || (i == 18) || 28 (i == 23)) 29 if (*cp == '-') 30 continue; 31 if (i== 36) 32 if (*cp == 0) 33 continue; 34 if (!isxdigit(*cp)) 35 return -1; 36 } 37 uuid.time_low = strtoul(in, NULL, 16); 38 uuid.time_mid = strtoul(in+9, NULL, 16); 39 uuid.time_hi_and_version = strtoul(in+14, NULL, 16); 40 uuid.clock_seq = strtoul(in+19, NULL, 16); 41 cp = in+24; 42 buf[2] = 0; 43 for (i=0; i < 6; i++) { 44 buf[0] = *cp++; 45 buf[1] = *cp++; 46 uuid.node[i] = strtoul(buf, NULL, 16); 47 } 48 49 uuid_pack(&uuid, uu); 50 return 0; 51} 52