sec_vt_header: dissect cont_id + opnum
[wireshark-wip.git] / cfutils.c
blob85085a8884d8004cad3ef1ece35af14947b52182
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 * $Id$
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.
27 #include "config.h"
29 #ifdef HAVE_OS_X_FRAMEWORKS
30 #include <glib.h>
31 #include <CoreFoundation/CoreFoundation.h>
32 #include "cfutils.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.
38 char *
39 CFString_to_C_string(CFStringRef cfstring)
41 CFIndex string_len;
42 char *string;
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)) {
49 g_free(string);
50 return NULL;
52 return string;
54 #endif