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
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 2001 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #ifdef HAVE_OS_X_FRAMEWORKS
31 #include <CoreFoundation/CoreFoundation.h>
35 * Convert a CFString to a UTF-8-encoded C string; the resulting string
36 * is allocated with g_malloc(). Returns NULL if the conversion fails.
39 CFString_to_C_string(CFStringRef cfstring
)
44 string_len
= CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstring
),
45 kCFStringEncodingUTF8
);
46 string
= (char *)g_malloc(string_len
+ 1);
47 if (!CFStringGetCString(cfstring
, string
, string_len
+ 1,
48 kCFStringEncodingUTF8
)) {