diff options
author | Richard Hughes <richard@hughsie.com> | 2008-08-01 12:07:56 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2008-08-01 12:07:56 +0100 |
commit | 4f934ad2dfa319c9bdfe0706442833df95cc1129 (patch) | |
tree | 02abd7f403330dc6167889bef9f8688ab6cee644 /src/sysfs-utils.c | |
parent | cbaa6851d4e5c69a9b797c9379446388a989b4b0 (diff) |
convert spaces to tabs, and make sure functions have sensible names
Diffstat (limited to 'src/sysfs-utils.c')
-rw-r--r-- | src/sysfs-utils.c | 244 |
1 files changed, 122 insertions, 122 deletions
diff --git a/src/sysfs-utils.c b/src/sysfs-utils.c index 93aa2a3..8a594f5 100644 --- a/src/sysfs-utils.c +++ b/src/sysfs-utils.c @@ -1,4 +1,4 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- * * Copyright (C) 2008 David Zeuthen <david@fubar.dk> * @@ -44,178 +44,178 @@ double sysfs_get_double (const char *dir, const char *attribute) { - double result; - char *contents; - char *filename; + double result; + char *contents; + char *filename; - result = 0.0; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_get_contents (filename, &contents, NULL, NULL)) { - result = atof (contents); - g_free (contents); - } - g_free (filename); + result = 0.0; + filename = g_build_filename (dir, attribute, NULL); + if (g_file_get_contents (filename, &contents, NULL, NULL)) { + result = atof (contents); + g_free (contents); + } + g_free (filename); - return result; + return result; } gboolean sysfs_file_contains (const char *dir, const char *attribute, const char *string) { - gboolean result; - char *filename; - char *s; + gboolean result; + char *filename; + char *s; - result = FALSE; + result = FALSE; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_get_contents (filename, &s, NULL, NULL)) { - result = (strstr(s, string) != NULL); - g_free (s); - } - g_free (filename); + filename = g_build_filename (dir, attribute, NULL); + if (g_file_get_contents (filename, &s, NULL, NULL)) { + result = (strstr(s, string) != NULL); + g_free (s); + } + g_free (filename); - return result; + return result; } char * sysfs_get_string (const char *dir, const char *attribute) { - char *result; - char *filename; + char *result; + char *filename; - result = NULL; - filename = g_build_filename (dir, attribute, NULL); - if (!g_file_get_contents (filename, &result, NULL, NULL)) { - result = g_strdup (""); - } - g_free (filename); + result = NULL; + filename = g_build_filename (dir, attribute, NULL); + if (!g_file_get_contents (filename, &result, NULL, NULL)) { + result = g_strdup (""); + } + g_free (filename); - return result; + return result; } int sysfs_get_int (const char *dir, const char *attribute) { - int result; - char *contents; - char *filename; - - result = 0; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_get_contents (filename, &contents, NULL, NULL)) { - result = atoi (contents); - g_free (contents); - } - g_free (filename); - - return result; + int result; + char *contents; + char *filename; + + result = 0; + filename = g_build_filename (dir, attribute, NULL); + if (g_file_get_contents (filename, &contents, NULL, NULL)) { + result = atoi (contents); + g_free (contents); + } + g_free (filename); + + return result; } gboolean sysfs_get_bool (const char *dir, const char *attribute) { - gboolean result = FALSE; - char *contents; - char *filename; - - result = 0; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_get_contents (filename, &contents, NULL, NULL)) { - if (strcmp (contents, "1")) - result = TRUE; - g_free (contents); - } - g_free (filename); - - return result; + gboolean result = FALSE; + char *contents; + char *filename; + + result = 0; + filename = g_build_filename (dir, attribute, NULL); + if (g_file_get_contents (filename, &contents, NULL, NULL)) { + if (strcmp (contents, "1")) + result = TRUE; + g_free (contents); + } + g_free (filename); + + return result; } guint64 sysfs_get_uint64 (const char *dir, const char *attribute) { - guint64 result; - char *contents; - char *filename; + guint64 result; + char *contents; + char *filename; - result = 0; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_get_contents (filename, &contents, NULL, NULL)) { - result = atoll (contents); - g_free (contents); - } - g_free (filename); + result = 0; + filename = g_build_filename (dir, attribute, NULL); + if (g_file_get_contents (filename, &contents, NULL, NULL)) { + result = atoll (contents); + g_free (contents); + } + g_free (filename); - return result; + return result; } gboolean sysfs_file_exists (const char *dir, const char *attribute) { - gboolean result; - char *filename; + gboolean result; + char *filename; - result = FALSE; - filename = g_build_filename (dir, attribute, NULL); - if (g_file_test (filename, G_FILE_TEST_EXISTS)) { - result = TRUE; - } - g_free (filename); + result = FALSE; + filename = g_build_filename (dir, attribute, NULL); + if (g_file_test (filename, G_FILE_TEST_EXISTS)) { + result = TRUE; + } + g_free (filename); - return result; + return result; } char * _dupv8 (const char *s) { - const char *end_valid; - - if (!g_utf8_validate (s, - -1, - &end_valid)) { - g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid); - return g_strndup (s, end_valid - s); - } else { - return g_strdup (s); - } + const char *end_valid; + + if (!g_utf8_validate (s, + -1, + &end_valid)) { + g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid); + return g_strndup (s, end_valid - s); + } else { + return g_strdup (s); + } } char * sysfs_resolve_link (const char *dir, const char *attribute) { - char *full_path; - char link_path[PATH_MAX]; - char resolved_path[PATH_MAX]; - ssize_t num; - gboolean found_it; - - found_it = FALSE; - - full_path = g_build_filename (dir, attribute, NULL); - - //g_warning ("attribute='%s'", attribute); - //g_warning ("full_path='%s'", full_path); - num = readlink (full_path, link_path, sizeof (link_path) - 1); - if (num != -1) { - char *absolute_path; - - link_path[num] = '\0'; - - //g_warning ("link_path='%s'", link_path); - absolute_path = g_build_filename (dir, link_path, NULL); - //g_warning ("absolute_path='%s'", absolute_path); - if (realpath (absolute_path, resolved_path) != NULL) { - //g_warning ("resolved_path='%s'", resolved_path); - found_it = TRUE; - } - g_free (absolute_path); - } - g_free (full_path); - - if (found_it) - return g_strdup (resolved_path); - else - return NULL; + char *full_path; + char link_path[PATH_MAX]; + char resolved_path[PATH_MAX]; + ssize_t num; + gboolean found_it; + + found_it = FALSE; + + full_path = g_build_filename (dir, attribute, NULL); + + //g_warning ("attribute='%s'", attribute); + //g_warning ("full_path='%s'", full_path); + num = readlink (full_path, link_path, sizeof (link_path) - 1); + if (num != -1) { + char *absolute_path; + + link_path[num] = '\0'; + + //g_warning ("link_path='%s'", link_path); + absolute_path = g_build_filename (dir, link_path, NULL); + //g_warning ("absolute_path='%s'", absolute_path); + if (realpath (absolute_path, resolved_path) != NULL) { + //g_warning ("resolved_path='%s'", resolved_path); + found_it = TRUE; + } + g_free (absolute_path); + } + g_free (full_path); + + if (found_it) + return g_strdup (resolved_path); + else + return NULL; } |