1 /***************************************************************************
4 * util.h - Various utilities
6 * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
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 **************************************************************************/
30 #include "device_store.h"
33 #define __FUNCTION__ __func__
37 #define __attribute__(x)
40 #define HAL_NAME_MAX 256
41 #define HAL_PATH_MAX 512
42 #define HAL_HELPER_TIMEOUT 10000
44 gboolean
hal_util_remove_trailing_slash (gchar
*path
);
46 const gchar
*hal_util_get_last_element (const gchar
*s
);
48 gchar
*hal_util_get_parent_path (const gchar
*path
);
50 gchar
*hal_util_get_normalized_path (const gchar
*path1
, const gchar
*path2
);
52 gboolean
hal_util_get_int_from_file (const gchar
*directory
, const gchar
*file
, gint
*result
, gint base
);
54 gboolean
hal_util_set_int_from_file (HalDevice
*d
, const gchar
*key
, const gchar
*directory
, const gchar
*file
, gint base
);
56 gboolean
hal_util_get_uint64_from_file (const gchar
*directory
, const gchar
*file
, guint64
*result
, gint base
);
58 gboolean
hal_util_set_uint64_from_file (HalDevice
*d
, const gchar
*key
, const gchar
*directory
, const gchar
*file
, gint base
);
60 gchar
*hal_util_get_string_from_file (const gchar
*directory
, const gchar
*file
);
62 gboolean
hal_util_set_string_from_file (HalDevice
*d
, const gchar
*key
, const gchar
*directory
, const gchar
*file
);
64 gboolean
hal_util_get_bcd2_from_file (const gchar
*directory
, const gchar
*file
, gint
*result
);
66 gboolean
hal_util_set_bcd2_from_file (HalDevice
*d
, const gchar
*key
, const gchar
*directory
, const gchar
*file
);
68 void hal_util_compute_udi (HalDeviceStore
*store
, gchar
*dst
, gsize dstsize
, const gchar
*format
, ...);
70 gboolean
hal_util_path_ascend (gchar
*path
);
72 void hal_util_grep_discard_existing_data (void);
74 gchar
*hal_util_grep_file (const gchar
*directory
, const gchar
*file
, const gchar
*linestart
, gboolean reuse_file
);
76 gint
hal_util_grep_int_elem_from_file (const gchar
*directory
, const gchar
*file
,
77 const gchar
*linestart
, guint elem
, guint base
, gboolean reuse_file
);
79 gchar
*hal_util_grep_string_elem_from_file (const gchar
*directory
, const gchar
*file
,
80 const gchar
*linestart
, guint elem
, gboolean reuse_file
);
82 gboolean
hal_util_set_string_elem_from_file (HalDevice
*d
, const gchar
*key
,
83 const gchar
*directory
, const gchar
*file
,
84 const gchar
*linestart
, guint elem
, gboolean reuse_file
);
86 gboolean
hal_util_set_int_elem_from_file (HalDevice
*d
, const gchar
*key
,
87 const gchar
*directory
, const gchar
*file
,
88 const gchar
*linestart
, guint elem
, guint base
, gboolean reuse_file
);
90 gboolean
hal_util_set_bool_elem_from_file (HalDevice
*d
, const gchar
*key
,
91 const gchar
*directory
, const gchar
*file
,
92 const gchar
*linestart
, guint elem
, const gchar
*expected
,
95 gchar
**hal_util_dup_strv_from_g_slist (GSList
*strlist
);
97 typedef void (*HalCalloutsDone
) (HalDevice
*d
, gpointer userdata1
, gpointer userdata2
);
99 void hal_util_callout_device_add (HalDevice
*d
, HalCalloutsDone callback
, gpointer userdata1
, gpointer userdata2
);
100 void hal_util_callout_device_remove (HalDevice
*d
, HalCalloutsDone callback
, gpointer userdata1
, gpointer userdata2
);
101 void hal_util_callout_device_preprobe (HalDevice
*d
, HalCalloutsDone callback
, gpointer userdata1
, gpointer userdata2
);
103 gchar
*hal_util_strdup_valid_utf8 (const char *str
);
105 void hal_util_hexdump (const void *buf
, unsigned int size
);
107 gboolean
hal_util_is_mounted_by_hald (const char *mount_point
);
110 hal_util_branch_claim (HalDeviceStore
*store
, HalDevice
*root
, dbus_bool_t claimed
, const char *service
, int uid
);
113 is_valid_interface_name (const char *name
);