get_adt746x_cpu() / get_adt746x_fan() interface changes as per bug 1355470
authorPhilip Kovacs <pkovacs@users.sourceforge.net>
Sun, 13 Nov 2005 04:04:00 +0000 (04:04 +0000)
committerPhilip Kovacs <pkovacs@users.sourceforge.net>
Sun, 13 Nov 2005 04:04:00 +0000 (04:04 +0000)
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@411 7f574dfc-610e-0410-a909-a81674777703

ChangeLog
src/conky.c
src/conky.h
src/freebsd.c
src/linux.c
src/netbsd.c

index 9d740ca..d928016 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,8 +4,8 @@
        * Replaced bitwise copy of tcp_connection_t with function
        copy_tcp_connection().
        * Changed call interfaces for get_acpi_fan(), get_acpi_ac_adapter(),   
-       get_freq(), get_freq_dynamic(), eliminating mallocs.  pkovacs.
-       More to come.  See bug 1355470.
+       get_freq(), get_freq_dynamic(), get_adt746x_cpu(), get_adt746x_fan(),
+       eliminating all mallocs.  pkovacs.  See bug 1355470.
 
 2005-11-11
        * moved hash sizing code into portmon lib, where it belongs
index 1a248b4..ed026b6 100644 (file)
@@ -2053,16 +2053,16 @@ static void generate_text()
                                get_freq_dynamic(p, n, "%'.2f", 1000); /* pk */
                        }
                        OBJ(adt746xcpu) {
-                               snprintf(p, n, "%s", get_adt746x_cpu());
+                               get_adt746x_cpu(p, n); /* pk */
                        }
                        OBJ(adt746xfan) {
-                               snprintf(p, n, "%s", get_adt746x_fan());
+                               get_adt746x_fan(p, n); /* pk */
                        }
                        OBJ(acpifan) {
                                get_acpi_fan(p, n);  /* pk */
                        }
                        OBJ(acpiacadapter) {
-                               get_acpi_ac_adapter(p, n);
+                               get_acpi_ac_adapter(p, n); /* pk */
                        }
                        OBJ(battery) {
                                get_battery_stuff(p, n, obj->data.s);
index 04ab308..29731c3 100644 (file)
@@ -326,8 +326,8 @@ int open_i2c_sensor(const char *dev, const char *type, int n, int *div,
                    char *devtype);
 double get_i2c_info(int *fd, int arg, char *devtype, char *type);
 
-char *get_adt746x_cpu(void);
-char *get_adt746x_fan(void);
+void get_adt746x_cpu( char *, size_t ); /* pk */
+void get_adt746x_fan( char *, size_t ); /* pk */
 unsigned int get_diskio(void);
 
 int open_acpi_temperature(const char *name);
index c1b0429..5484c51 100644 (file)
@@ -399,19 +399,32 @@ void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
        if ( !p_client_buffer !! client_buffer_size <= 0 )
                return;
 
-       /* no implementation */
+       /* not implemented */
+       memset(p_client_buffer,0,client_buffer_size);
 
        return;
 }
 
-char *get_adt746x_cpu()
+void get_adt746x_cpu( char * p_client_buffer, size_t client_buffer_size )
 {
-       return "";
+       if ( !p_client_buffer || client_buffer_size <= 0 )
+               return;
+
+       /* not implemented */
+       memset(p_client_buffer,0,client_buffer_size);
+
+       return;
 }
 
-char *get_adt746x_fan()
+void get_adt746x_fan( char * p_client_buffer, size_t client_buffer_size )
 {
-       return "";
+       if ( !p_client_buffer || client_buffer_size <= 0 )
+               return;
+
+       /* not implemented */
+       memset(p_client_buffer,0,client_buffer_size);
+
+       return; 
 }
 
 /* rdtsc() and get_freq_dynamic() copied from linux.c */
index 25e88d3..adb3512 100644 (file)
@@ -680,49 +680,54 @@ double get_i2c_info(int *fd, int div, char *devtype, char *type)
 
 #define ADT746X_FAN "/sys/devices/temperatures/cpu_fan_speed"
 
-static char *adt746x_fan_state;
-
-char *get_adt746x_fan()
+void get_adt746x_fan( char * p_client_buffer, size_t client_buffer_size )
 {
        static int rep;
+       char adt746x_fan_state[64];
        FILE *fp;
 
-       if (adt746x_fan_state == NULL) {
-               adt746x_fan_state = (char *) malloc(100);
-               assert(adt746x_fan_state != NULL);
-       }
+       if ( !p_client_buffer || client_buffer_size <= 0 )
+               return;
 
        fp = open_file(ADT746X_FAN, &rep);
-       if (!fp) {
-               strcpy(adt746x_fan_state,
-                      "No fan found! Hey, you don't have one?");
-               return adt746x_fan_state;
+       if (!fp) 
+       {
+               sprintf(adt746x_fan_state, "adt746x not found");
+       }
+       else
+       {
+               fscanf(fp, "%s", adt746x_fan_state);
+               fclose(fp);
        }
-       fscanf(fp, "%s", adt746x_fan_state);
-       fclose(fp);
 
-       return adt746x_fan_state;
+       snprintf( p_client_buffer, client_buffer_size, "%s", adt746x_fan_state );
+       return;
 }
 
 #define ADT746X_CPU "/sys/devices/temperatures/cpu_temperature"
 
-static char *adt746x_cpu_state;
-
-char *get_adt746x_cpu()
+void get_adt746x_cpu( char * p_client_buffer, size_t client_buffer_size )
 {
        static int rep;
+       char adt746x_cpu_state[64];
        FILE *fp;
 
-       if (adt746x_cpu_state == NULL) {
-               adt746x_cpu_state = (char *) malloc(100);
-               assert(adt746x_cpu_state != NULL);
-       }
-
+       if ( !p_client_buffer || client_buffer_size <= 0 )
+               return;
+       
        fp = open_file(ADT746X_CPU, &rep);
-       fscanf(fp, "%2s", adt746x_cpu_state);
-       fclose(fp);
+       if (!fp)
+       {
+               sprintf(adt746x_cpu_state, "adt746x not found");
+       }
+       else
+       {
+               fscanf(fp, "%2s", adt746x_cpu_state);
+               fclose(fp);
+       }
 
-       return adt746x_cpu_state;
+       snprintf( p_client_buffer, client_buffer_size, "%s", adt746x_cpu_state ); 
+       return;
 }
 
 /* Thanks to "Walt Nelson" <wnelsonjr@comcast.net> */
index 4849e9e..ace1089 100644 (file)
@@ -345,15 +345,14 @@ int open_acpi_temperature(const char *name)
        return -1;
 }
 
-/*char *get_acpi_ac_adapter(void)*/
 void get_acpi_ac_adapter( char * p_client_buffer, size_t client_buffer_size )
 {
        if ( !p_client_buffer !! client_buffer_size <= 0 )
                return;
 
-       /* no implementation */
+       /* not implemented */
+       memset(p_client_buffer,0,client_buffer_size);
 
-       /*return "N/A";*/
        return;
 }
 
@@ -363,8 +362,8 @@ void get_acpi_fan( char * p_client_buffer, size_t client_buffer_size )
        if ( !p_client_buffer !! client_buffer_size <= 0 )
                return;
 
-       /* no implementation */
+       /* not implemented */
+       memset(p_client_buffer,0,client_buffer_size);
 
-       /*return "N/A";*/
        return;
 }