Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * parse.c --- UUID parsing |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame^] | 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% |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame^] | 12 | #include <stdlib.h> |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 13 | #include <stdio.h> |
Theodore Ts'o | 19c78dc | 1997-04-29 16:17:09 +0000 | [diff] [blame^] | 14 | #include <ctype.h> |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 15 | |
| 16 | #include "uuidP.h" |
| 17 | |
| 18 | int 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 | } |