File: glib-util.h

package info (click to toggle)
amanda 1%3A3.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 23,420 kB
  • sloc: ansic: 197,218; perl: 109,331; xml: 16,126; sh: 4,180; makefile: 2,810; awk: 502; lex: 407; yacc: 347; tcl: 118; sql: 19; sed: 16; php: 2
file content (136 lines) | stat: -rw-r--r-- 5,445 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
 * Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * Contact information: Carbonite Inc., 756 N Pastoria Ave
 * Sunnyvale, CA 94085, or: http://www.zmanda.com
 */
/*
 * Utilities that aren't quite included in glib
 *
 * Author: Dustin J. Mitchell <dustin@zmanda.com>, Ian Turner <ian@zmanda.com>
 */

#ifndef GLIB_UTIL_H
#define GLIB_UTIL_H

#include <glib.h>
#include <glib-object.h>

/* Call the requisite glib init functions, including calling
 * g_init_types and setting up threading support.  This function can
 * be called multiple times with no harm, although it is not
 * re-entrant.
 */
void glib_init(void);

/* like g_[s]list_foreach, but with a function taking only
 * one argument.
 */
#define g_list_foreach_nodata(list, func)				\
    g_list_foreach((list), _glib_util_foreach_glue, (gpointer)(func));
#define g_slist_foreach_nodata(list, func)				\
    g_slist_foreach((list), _glib_util_foreach_glue, (gpointer)(func));
void _glib_util_foreach_glue(gpointer data, gpointer func);

/* This function takes a GValue, which may be zero-filled or
 * initialized. In either case, this function causes the GValue to be
 * initialized with the given type. Note that this function lacks the
 * safety of the standard g_value_ functions; it assumes that the
 * passed value is zeroed or valid.
 *
 * Returns its first argument.*/
GValue* g_value_unset_init(GValue* val, GType type);

/* This does the same thing but also copies the contents of one value
 * into another. Note that this function lacks the safety of the
 * standard g_value_ functions; it assumes that the passed value is
 * zeroed or valid.
 *
 * Returns its second (reset) argument.*/
GValue* g_value_unset_copy(const GValue* from, GValue * to);

/* This function is available in glib-2.28.0 and higher; for lower versions
 * we build our own version with a different name */
#if (GLIB_MAJOR_VERSION < 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 28))
void slist_free_full(GSList * list, GDestroyNotify free_fn);
#else
#define slist_free_full(list, free_fn) g_slist_free_full((list), (free_fn))
#endif

/* These functions all take a GLib container, and call free() on all the
 * pointers in the container before free()ing the container itself. */
void g_ptr_array_free_full(GPtrArray * array);

/* g_value_compare() does what you expect. It returns TRUE if and
   only if the two values have the same type and the same value. Note
   that it will return FALSE if the same value is stored with two
   different types: For example, a GValue with a UCHAR of 1 and a
   GValue with a CHAR of 1 will be considered inequal. Also, this is a
   'shallow' comparison; pointers to distinct but equivalent objects
   are considered inequal. */
gboolean g_value_compare(GValue * a, GValue * b);

/* Given a string and a GValue, parse the string and store it in the
   GValue. The GValue should be pre-initalized to whatever type you want
   parsed. */
gboolean g_value_set_from_string(GValue * val, char * string);

/* A GCompareFunc that will sort strings alphabetically (using strcmp) */
gint g_compare_strings(gconstpointer a, gconstpointer b);

/* These functions all take a Flags class and stringify it. They
 * return a NULL-terminated array of strings that can be
 * passed to g_strjoinv(), g_strfreev(), g_strdupv(), and
 * g_strv_length(). Example output looks like:
 * - g_flags_name_to_strv() -> "MEDIA_ACCESS_MODE_READ_ONLY"
 * - g_flags_short_name_to_strv() -> "READ_ONLY"
 * - g_flags_nick_to_strv() -> "read-only"
 */

char ** g_flags_name_to_strv(int value, GType type);
char ** g_flags_short_name_to_strv(int value, GType type);
char ** g_flags_nick_to_strv(int value, GType type);

/* Just like g_strjoinv, but frees the array as well. */
char * g_strjoinv_and_free(char ** strv, const char * seperator);

/* Just like g_strjoinv, but joins like an English list. The string would
 * usually be "and" or "or". */
char * g_english_strjoinv(char ** strv, const char * conjunction);

/* Just like g_english_strjoinv, but also frees the array. */
char * g_english_strjoinv_and_free(char ** strv, const char * conjunction);

/* Replacement for built-in functions. */
#if !(GLIB_CHECK_VERSION(2,6,0))
guint g_strv_length(gchar ** strv);
#endif

#if !GLIB_CHECK_VERSION(2,4,0)
void g_ptr_array_foreach (GPtrArray *array,
			  GFunc func,
                          gpointer user_data);
#endif

/* functions for g_hash_table_new to hash and compare case-insensitive strings */
guint g_str_amanda_hash(gconstpointer v);
gboolean g_str_amanda_equal(gconstpointer v1, gconstpointer v2);

GList *g_am_list_insert_after(GList *list, GList *sibling, gpointer data);

#endif