![]() |
|
|||
File indexing completed on 2025-05-11 08:24:20
0001 /* 0002 * parse.c --- UUID parsing 0003 * 0004 * Copyright (C) 1996, 1997 Theodore Ts'o. 0005 * 0006 * %Begin-Header% 0007 * Redistribution and use in source and binary forms, with or without 0008 * modification, are permitted provided that the following conditions 0009 * are met: 0010 * 1. Redistributions of source code must retain the above copyright 0011 * notice, and the entire permission notice in its entirety, 0012 * including the disclaimer of warranties. 0013 * 2. Redistributions in binary form must reproduce the above copyright 0014 * notice, this list of conditions and the following disclaimer in the 0015 * documentation and/or other materials provided with the distribution. 0016 * 3. The name of the author may not be used to endorse or promote 0017 * products derived from this software without specific prior 0018 * written permission. 0019 * 0020 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 0021 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0022 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF 0023 * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE 0024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 0026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 0027 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 0028 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 0030 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH 0031 * DAMAGE. 0032 * %End-Header% 0033 */ 0034 0035 #ifdef HAVE_CONFIG_H 0036 #include "config.h" 0037 #endif 0038 0039 #include <stdlib.h> 0040 #include <stdio.h> 0041 #include <ctype.h> 0042 #include <string.h> 0043 0044 #include "uuidP.h" 0045 0046 int uuid_parse(const char *in, uuid_t uu) 0047 { 0048 struct uuid uuid; 0049 int i; 0050 const char *cp; 0051 char buf[3]; 0052 0053 if (strlen(in) != 36) 0054 return -1; 0055 for (i=0, cp = in; i <= 36; i++,cp++) { 0056 if ((i == 8) || (i == 13) || (i == 18) || 0057 (i == 23)) { 0058 if (*cp == '-') 0059 continue; 0060 else 0061 return -1; 0062 } 0063 if (i== 36) 0064 if (*cp == 0) 0065 continue; 0066 if (!isxdigit((unsigned char)*cp)) 0067 return -1; 0068 } 0069 uuid.time_low = strtoul(in, NULL, 16); 0070 uuid.time_mid = strtoul(in+9, NULL, 16); 0071 uuid.time_hi_and_version = strtoul(in+14, NULL, 16); 0072 uuid.clock_seq = strtoul(in+19, NULL, 16); 0073 cp = in+24; 0074 buf[2] = 0; 0075 for (i=0; i < 6; i++) { 0076 buf[0] = *cp++; 0077 buf[1] = *cp++; 0078 uuid.node[i] = strtoul(buf, NULL, 16); 0079 } 0080 0081 uuid_pack(&uuid, uu); 0082 return 0; 0083 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |