update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / wsutil / cfutils.c
blob5693411a2bde237b08c2a7af0abac8a927320b10
1 /* cfutils.c
2 * Routines to work around deficiencies in Core Foundation, such as the
3 * lack of a routine to convert a CFString to a C string of arbitrary
4 * size.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2001 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <glib.h>
16 #include <CoreFoundation/CoreFoundation.h>
17 #include <wsutil/cfutils.h>
20 * Convert a CFString to a UTF-8-encoded C string; the resulting string
21 * is allocated with g_malloc(). Returns NULL if the conversion fails.
23 char *
24 CFString_to_C_string(CFStringRef cfstring)
26 CFIndex string_len;
27 char *string;
29 string_len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstring),
30 kCFStringEncodingUTF8);
31 string = (char *)g_malloc(string_len + 1);
32 if (!CFStringGetCString(cfstring, string, string_len + 1,
33 kCFStringEncodingUTF8)) {
34 g_free(string);
35 return NULL;
37 return string;
41 * Editor modelines - https://www.wireshark.org/tools/modelines.html
43 * Local variables:
44 * c-basic-offset: 8
45 * tab-width: 8
46 * indent-tabs-mode: t
47 * End:
49 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
50 * :indentSize=8:tabSize=8:noTabs=false: