mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2026-05-05 09:58:06 +02:00
add a convenience function sysfs_get_hex()
This commit is contained in:
parent
4756da4b81
commit
9f9debcf90
2 changed files with 19 additions and 0 deletions
|
|
@ -113,6 +113,24 @@ sysfs_get_int (const char *dir, const char *attribute)
|
|||
return result;
|
||||
}
|
||||
|
||||
guint
|
||||
sysfs_get_hex (const char *dir, const char *attribute)
|
||||
{
|
||||
guint result;
|
||||
char *contents;
|
||||
char *filename;
|
||||
|
||||
result = 0;
|
||||
filename = g_build_filename (dir, attribute, NULL);
|
||||
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
|
||||
result = strtol (contents, (char **) NULL, 16);
|
||||
g_free (contents);
|
||||
}
|
||||
g_free (filename);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gboolean
|
||||
sysfs_get_bool (const char *dir, const char *attribute)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ double sysfs_get_double (const char *dir, const char *attribute);
|
|||
gboolean sysfs_file_contains (const char *dir, const char *attribute, const char *string);
|
||||
char *sysfs_get_string (const char *dir, const char *attribute);
|
||||
int sysfs_get_int (const char *dir, const char *attribute);
|
||||
guint sysfs_get_hex (const char *dir, const char *attribute);
|
||||
gboolean sysfs_get_bool (const char *dir, const char *attribute);
|
||||
guint64 sysfs_get_uint64 (const char *dir, const char *attribute);
|
||||
gboolean sysfs_file_exists (const char *dir, const char *attribute);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue