1 /***************************************************************************
4 * utils.c - Some utils for the hald runner
6 * Copyright (C) 2006 Sjoerd Simons, <sjoerd@luon.net>
8 * Licensed under the Academic Free License version 2.1
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 **************************************************************************/
27 #define DBUS_API_SUBJECT_TO_CHANGE
28 #include <dbus/dbus-glib-lowlevel.h>
34 get_string_array(DBusMessageIter
*iter
, char *extra
)
38 array
= g_array_new(TRUE
, FALSE
, sizeof(char *));
40 while (dbus_message_iter_get_arg_type(iter
) == DBUS_TYPE_STRING
) {
43 dbus_message_iter_get_basic(iter
, &value
);
45 g_array_append_vals(array
, &t
, 1);
46 dbus_message_iter_next(iter
);
49 g_array_append_vals(array
, &extra
, 1);
50 result
= (char **) array
->data
;
51 g_array_free(array
, FALSE
);
56 get_string_array_from_fd(int fd
)
65 array
= g_array_new(TRUE
, FALSE
, sizeof(char *));
66 str
= g_string_new("");
67 io
= g_io_channel_unix_new(fd
);
68 while (g_io_channel_read_line_string(io
, str
, &pos
, NULL
) == G_IO_STATUS_NORMAL
&& (i
++ < 128)) {
71 /* Remove the terminting char aka \n */
72 g_string_erase(str
, pos
, 1);
73 t
= g_strdup(str
->str
);
74 g_array_append_vals(array
, &t
, 1);
76 g_string_free(str
, TRUE
);
77 g_io_channel_unref(io
);
78 result
= (char **) array
->data
;
79 g_array_free(array
, FALSE
);
84 free_string_array(char **array
)
88 for (p
= array
; p
!= NULL
&& *p
!= NULL
; p
++)