1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2009 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
27 #include <glib/gprintf.h>
37 void log_write(const gchar
*fmt
, ...);
39 gboolean
strv_printf(gchar
***array
, const gchar
*fmt
, ...)
44 gint len
= *array
? g_strv_length(*array
) : 0;
50 if ((a
= g_realloc(*array
, (len
+ 2) * sizeof(gchar
*))) == NULL
) {
51 log_write("%s(%i): %s", __FILE__
, __LINE__
, strerror(ENOMEM
));
56 ret
= g_vasprintf(&buf
, fmt
, ap
);
60 log_write("%s(%i): %s", __FILE__
, __LINE__
, strerror(ENOMEM
));
70 gchar
**strvcatv(gchar
**dst
, gchar
**src
)
86 for (p
= src
; *p
; p
++) {
89 pa
= g_realloc(d
, (i
+ 2) * sizeof(gchar
*));
110 gboolean
valid_filename(const gchar
*filename
)
114 if (!filename
|| !*filename
)
117 if (!strcmp(filename
, "-"))
120 for (p
= filename
; *p
; p
++) {
121 if (*p
== '/' || isspace(*p
))
128 gchar
*print_fmt(gchar
*buf
, gsize len
, const char *fmt
, ...)
133 g_vsnprintf(buf
, len
, fmt
, ap
);
138 gboolean
contains_whitespace(const gchar
*str
)
140 const gchar
*p
= str
;
144 len
= g_utf8_strlen(p
++, -1) -1;
147 c
= g_utf8_get_char(p
++);
149 if (g_unichar_isspace(c
))
156 gchar
*expand_homedir(gchar
*str
)
161 return g_strdup_printf("%s%s", g_get_home_dir(), p
);
163 return g_strdup(str
);
166 gchar
*strip_char(gchar
*str
, gchar c
)
170 for (p
= p2
= str
; *p
; p
++) {
181 gchar
*tohex(const guchar
*str
, gsize len
)
186 if (!str
|| len
<= 0)
189 p
= g_malloc0(len
*2+1);
194 for (i
= 0; i
< len
; i
++) {
197 g_sprintf(buf
, "%02x", str
[i
]);