61a02891918caca2bff1ac942a1804f4f446c9a6
[debian/amanda] / perl / amglue / ghashtable.c
1 /*
2  * Copyright (c) 2005 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1 as
6  * published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
11  * License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  *
17  * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 #include "amglue.h"
22
23 static void 
24 foreach_fn(gpointer key_p, gpointer value_p, gpointer user_data_p)
25 {
26     char *key = key_p;
27     char *value = value_p;
28     HV *hv = user_data_p;
29     hv_store(hv, key, strlen(key), newSVpv(value, 0), 0);
30 }
31
32 SV *
33 g_hash_table_to_hashref(GHashTable *hash)
34 {
35     HV *hv = (HV *)sv_2mortal((SV *)newHV());
36
37     g_hash_table_foreach(hash, foreach_fn, hv);
38
39     return newRV((SV *)hv);
40 }