add a convenience function sysfs_get_hex()

This commit is contained in:
Richard Hughes 2008-08-08 13:46:17 +01:00
parent 4756da4b81
commit 9f9debcf90
2 changed files with 19 additions and 0 deletions

View file

@ -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)
{

View file

@ -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);