Debian Codegraph @

Xpjproject/pjlib/src/pj/guid_bsd.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 #include <uuid.h>
23
24 PJ_DEF_DATA(const unsigned) PJ_GUID_STRING_LENGTH = 36;
25
26 PJ_DEF(unsigned) pj_GUID_STRING_LENGTH()
27 {
28 return PJ_GUID_STRING_LENGTH;
29 }
30
31 PJ_DEF(pj_str_t *) pj_generate_unique_string(pj_str_t *str)
32 {
33 uint32_t status;
34 uuid_t u;
35 char *s = NULL;
36 pj_str_t sguid;
37
38 PJ_ASSERT_RETURN(str && str->ptr, NULL);
39 PJ_CHECK_STACK();
40
41 uuid_create(&u, &status);
42 PJ_ASSERT_RETURN(status == uuid_s_ok, NULL);
43 uuid_to_string(&u, &s, &status);
44 PJ_ASSERT_RETURN(status == uuid_s_ok, NULL);
45 sguid = pj_str(s);
46 pj_strncpy(str, &sguid, PJ_GUID_STRING_LENGTH);
47 free(s);
48
49 return str;
50 }