cleanup
[psensor.git] / src / lib / hdd_hddtemp.c
index 5c89a1f..e693bf4 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
+
+/* Part of the code in this file is based on GNOME sensors applet code
+ * hddtemp-plugin.c see http://sensors-applet.sourceforge.net/
+ */
+
 #include <locale.h>
 #include <libintl.h>
 #define _(str) gettext(str)
 
-/*
- * Following code is based on GNOME sensors applet code
- * hddtemp-plugin.c see http://sensors-applet.sourceforge.net/
- */
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -38,9 +39,9 @@
 
 static const char *PROVIDER_NAME = "hddtemp";
 
-#define HDDTEMP_SERVER_IP_ADDRESS "127.0.0.1"
-#define HDDTEMP_PORT_NUMBER 7634
-#define HDDTEMP_OUTPUT_BUFFER_LENGTH 4048
+static const char *HDDTEMP_SERVER_IP_ADDRESS = "127.0.0.1";
+static const int HDDTEMP_PORT_NUMBER = 7634;
+static const int HDDTEMP_OUTPUT_BUFFER_LENGTH = 4048;
 
 struct hdd_info {
        char *name;
@@ -58,7 +59,7 @@ static char *fetch()
 
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd == -1) {
-               log_err(_("hddtemp: failed to open socket."));
+               log_err(_("%s: failed to open socket."), PROVIDER_NAME);
                return NULL;
        }
 
@@ -71,7 +72,7 @@ static char *fetch()
        if (connect(sockfd,
                    (struct sockaddr *)&address,
                    (socklen_t) sizeof(address)) == -1) {
-               log_err(_("hddtemp: failed to open connection."));
+               log_err(_("%s: failed to open connection."), PROVIDER_NAME);
        } else {
                buffer = malloc(HDDTEMP_OUTPUT_BUFFER_LENGTH);
 
@@ -173,32 +174,31 @@ static char *next_hdd_info(char *string, struct hdd_info *info)
        return c;
 }
 
-struct psensor **hddtemp_psensor_list_add(struct psensor **sensors,
-                                         int values_max_length)
+void
+hddtemp_psensor_list_append(struct psensor ***sensors, int values_max_length)
 {
-       char *hddtemp_output = fetch();
-       char *c;
+       char *hddtemp_output, *c;
        struct hdd_info info;
-       struct psensor **result;
+
+       hddtemp_output = fetch();
 
        if (!hddtemp_output)
-               return sensors;
+               return;
 
        if (hddtemp_output[0] != '|') {
-               log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+               log_err(_("%s: wrong string: %s."),
+                       PROVIDER_NAME,
+                       hddtemp_output);
 
                free(hddtemp_output);
 
-               return sensors;
+               return;
        }
 
        c = hddtemp_output;
 
-       result = sensors;
-
        while (c && (c = next_hdd_info(c, &info))) {
                struct psensor *sensor;
-               struct psensor **tmp_sensors;
                char *id;
 
                id = malloc(strlen(PROVIDER_NAME) + 1 + strlen(info.name) + 1);
@@ -206,31 +206,22 @@ struct psensor **hddtemp_psensor_list_add(struct psensor **sensors,
 
                sensor = create_sensor(id, info.name, values_max_length);
 
-               tmp_sensors = psensor_list_add(result, sensor);
-
-               if (result != sensors)
-                       free(result);
-
-               result = tmp_sensors;
+               psensor_list_append(sensors, sensor);
        }
 
        free(hddtemp_output);
-
-       return result;
 }
 
 static void update(struct psensor **sensors, struct hdd_info *info)
 {
-       struct psensor **sensor_cur = sensors;
-
-       while (*sensor_cur) {
-               if (!((*sensor_cur)->type & SENSOR_TYPE_REMOTE)
-                   && (*sensor_cur)->type & SENSOR_TYPE_HDDTEMP
-                   && !strcmp((*sensor_cur)->id + 8, info->name))
-                       psensor_set_current_value(*sensor_cur,
-                                                 (float)info->temp);
-
-               sensor_cur++;
+       while (*sensors) {
+               if (!((*sensors)->type & SENSOR_TYPE_REMOTE)
+                   && (*sensors)->type & SENSOR_TYPE_HDDTEMP
+                   && !strcmp((*sensors)->id + 8, info->name))
+                       psensor_set_current_value(*sensors,
+                                                 (double)info->temp);
+
+               sensors++;
        }
 }
 
@@ -257,7 +248,9 @@ void hddtemp_psensor_list_update(struct psensor **sensors)
                        free(info.name);
                }
        } else {
-               log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+               log_err(_("%s: wrong string: %s."),
+                       PROVIDER_NAME,
+                       hddtemp_output);
        }
 
        free(hddtemp_output);