Fix several warnings that appear in gcc 4.3.2.
[wvstreams.git] / xplc-cxx / strtouuid.cc
blob0cace9188339b91404c6dad23a8c66583d17809b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * XPLC - Cross-Platform Lightweight Components
4 * Copyright (C) 2002-2003, Pierre Phaneuf
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
21 * As a special exception, you may use this file as part of a free
22 * software library without restriction. Specifically, if other files
23 * instantiate templates or use macros or inline functions from this
24 * file, or you compile this file and link it with other files to
25 * produce an executable, this file does not by itself cause the
26 * resulting executable to be covered by the GNU Lesser General Public
27 * License. This exception does not however invalidate any other
28 * reasons why the executable file might be covered by the GNU Lesser
29 * General Public License.
32 #include <stdlib.h>
33 #include <string.h>
34 #include <xplc/uuid.h>
36 const UUID UuidFromString(const char* str) {
37 UUID rv;
38 char tmp[3];
39 char* end;
40 bool format1 = false;
41 bool ok = false;
43 do {
44 if(*str == '{') {
45 format1 = true;
46 ++str;
49 rv.Data1 = strtoul(str, &end, 16);
50 if(end != str + 8)
51 break;
52 str = end;
54 if(*str != '-')
55 break;
56 ++str;
58 rv.Data2 = static_cast<unsigned short>(strtoul(str, &end, 16));
59 if(end != str + 4)
60 break;
61 str = end;
63 if(*str != '-')
64 break;
65 ++str;
67 rv.Data3 = static_cast<unsigned short>(strtoul(str, &end, 16));
68 if(end != str + 4)
69 break;
70 str = end;
72 if(*str != '-')
73 break;
74 ++str;
76 tmp[2] = 0;
78 strncpy(tmp, str, 2);
79 rv.Data4[0] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
80 if(end != tmp + 2)
81 break;
82 str += 2;
84 strncpy(tmp, str, 2);
85 rv.Data4[1] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
86 if(end != tmp + 2)
87 break;
88 str += 2;
90 if(*str != '-')
91 break;
92 ++str;
94 for(int i = 2; i < 8; ++i) {
95 strncpy(tmp, str, 2);
96 rv.Data4[i] = static_cast<unsigned char>(strtoul(tmp, &end, 16));
97 if(end != tmp + 2)
98 break;
99 str += 2;
102 if(format1) {
103 if(*str != '}')
104 break;
105 ++str;
108 if(*str != 0)
109 break;
111 ok = true;
112 } while(0);
114 if(!ok)
115 rv = UUID_null;
117 return rv;