diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2021-02-04 22:04:03 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2021-02-15 15:01:23 +0000 |
commit | 4fe938621d528799b31b32952cd1db619df5a9e3 (patch) | |
tree | fbedac62f68e14a8108803c83314d1e031d2ff22 /src/libqmi-glib/qmi-device.c | |
parent | 46a3facf497af52afbd4ea2ab5e98e4b0229d6b5 (diff) |
libqmi-glib,helpers: move sysfs R/W operations to the internal helpers
Diffstat (limited to 'src/libqmi-glib/qmi-device.c')
-rw-r--r-- | src/libqmi-glib/qmi-device.c | 82 |
1 files changed, 8 insertions, 74 deletions
diff --git a/src/libqmi-glib/qmi-device.c b/src/libqmi-glib/qmi-device.c index f1dc83d..dad407a 100644 --- a/src/libqmi-glib/qmi-device.c +++ b/src/libqmi-glib/qmi-device.c @@ -766,72 +766,6 @@ qmi_device_get_wwan_iface (QmiDevice *self) /* Expected data format */ static gboolean -read_sysfs_file (const gchar *sysfs_path, - gchar *out_value, - GError **error) -{ - FILE *f; - gboolean status = FALSE; - - if (!(f = fopen (sysfs_path, "r"))) { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Failed to open sysfs file '%s': %s", - sysfs_path, g_strerror (errno)); - goto out; - } - - if (fread (out_value, 1, 1, f) != 1) { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Failed to read from sysfs file '%s': %s", - sysfs_path, g_strerror (errno)); - goto out; - } - - if (*out_value != 'Y' && *out_value != 'N') { - g_set_error (error, QMI_CORE_ERROR, QMI_CORE_ERROR_FAILED, - "Unexpected sysfs file contents: %c", *out_value); - goto out; - } - - status = TRUE; - - out: - if (f) - fclose (f); - return status; -} - -static gboolean -write_sysfs_file (const gchar *sysfs_path, - gchar value, - GError **error) -{ - gboolean status = FALSE; - FILE *f; - - if (!(f = fopen (sysfs_path, "w"))) { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Failed to open sysfs file '%s' for R/W: %s", - sysfs_path, g_strerror (errno)); - goto out; - } - - if (fwrite (&value, 1, 1, f) != 1) { - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), - "Failed to write to sysfs file '%s': %s", - sysfs_path, g_strerror (errno)); - goto out; - } - - status = TRUE; - - out: - if (f) - fclose (f); - return status; -} - -static gboolean get_expected_data_format (QmiDevice *self, const gchar *raw_ip_sysfs_path, const gchar *pass_through_sysfs_path, @@ -840,13 +774,13 @@ get_expected_data_format (QmiDevice *self, gchar raw_ip_value = '\0'; gchar pass_through_value = '\0'; - if (!read_sysfs_file (raw_ip_sysfs_path, &raw_ip_value, error)) + if (!qmi_helpers_read_sysfs_file (raw_ip_sysfs_path, &raw_ip_value, error)) return QMI_DEVICE_EXPECTED_DATA_FORMAT_UNKNOWN; if (raw_ip_value == 'N') return QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3; - if (read_sysfs_file (pass_through_sysfs_path, &pass_through_value, NULL) && (pass_through_value == 'Y')) + if (qmi_helpers_read_sysfs_file (pass_through_sysfs_path, &pass_through_value, NULL) && (pass_through_value == 'Y')) return QMI_DEVICE_EXPECTED_DATA_FORMAT_QMAP_PASS_THROUGH; return QMI_DEVICE_EXPECTED_DATA_FORMAT_RAW_IP; @@ -860,18 +794,18 @@ set_expected_data_format (QmiDevice *self, GError **error) { if (requested == QMI_DEVICE_EXPECTED_DATA_FORMAT_802_3) { - write_sysfs_file (pass_through_sysfs_path, 'N', NULL); - return write_sysfs_file (raw_ip_sysfs_path, 'N', error); + qmi_helpers_write_sysfs_file (pass_through_sysfs_path, 'N', NULL); + return qmi_helpers_write_sysfs_file (raw_ip_sysfs_path, 'N', error); } if (requested == QMI_DEVICE_EXPECTED_DATA_FORMAT_RAW_IP) { - write_sysfs_file (pass_through_sysfs_path, 'N', NULL); - return write_sysfs_file (raw_ip_sysfs_path, 'Y', error); + qmi_helpers_write_sysfs_file (pass_through_sysfs_path, 'N', NULL); + return qmi_helpers_write_sysfs_file (raw_ip_sysfs_path, 'Y', error); } if (requested == QMI_DEVICE_EXPECTED_DATA_FORMAT_QMAP_PASS_THROUGH) { - return (write_sysfs_file (raw_ip_sysfs_path, 'Y', error) && - write_sysfs_file (pass_through_sysfs_path, 'Y', error)); + return (qmi_helpers_write_sysfs_file (raw_ip_sysfs_path, 'Y', error) && + qmi_helpers_write_sysfs_file (pass_through_sysfs_path, 'Y', error)); } g_assert_not_reached (); |