Debian Codegraph @

Xpjproject/pjlib/src/pj/guid_darwin.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2021-2021 Teluu Inc. (http://www.teluu.com)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include <pj/guid.h>
19 #include <pj/assert.h>
20 #include <pj/os.h>
21 #include <pj/string.h>
22
23 #include <CoreFoundation/CoreFoundation.h>
24
25 PJ_DEF_DATA(const unsigned) PJ_GUID_STRING_LENGTH=36;
26
27 PJ_DEF(unsigned) pj_GUID_STRING_LENGTH()
28 {
29 return PJ_GUID_STRING_LENGTH;
30 }
31
32 PJ_DEF(pj_str_t*) pj_generate_unique_string(pj_str_t *str)
33 {
34 CFUUIDRef uuid_obj;
35 CFStringRef uuid_str;
36 pj_str_t sguid;
37
38 PJ_ASSERT_RETURN(str->ptr != NULL, NULL);
39 PJ_CHECK_STACK();
40
41 /* Create universally unique identifier (object). */
42 uuid_obj = CFUUIDCreate(kCFAllocatorDefault);
43
44 /* Get the string representation of CFUUID object. */
45 uuid_str = CFUUIDCreateString(kCFAllocatorDefault, uuid_obj);
46 CFRelease(uuid_obj);
47
48 sguid.ptr = (char*)CFStringGetCStringPtr(uuid_str, kCFStringEncodingUTF8);
49 pj_assert(sguid.ptr);
50 sguid.slen = pj_ansi_strlen(sguid.ptr);
51
52 pj_strncpy(str, &sguid, PJ_GUID_STRING_LENGTH);
53 CFRelease(uuid_str);
54
55 return str;
56 }