From 79aacf1ea290d55de264342853be65d76ca1fd99 Mon Sep 17 00:00:00 2001 From: Philip Kovacs Date: Sun, 13 Nov 2005 04:04:00 +0000 Subject: [PATCH] get_adt746x_cpu() / get_adt746x_fan() interface changes as per bug 1355470 git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@411 7f574dfc-610e-0410-a909-a81674777703 --- ChangeLog | 4 ++-- src/conky.c | 6 +++--- src/conky.h | 4 ++-- src/freebsd.c | 23 ++++++++++++++++----- src/linux.c | 55 ++++++++++++++++++++++++++++----------------------- src/netbsd.c | 9 ++++----- 6 files changed, 59 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d740ca0..d9280167 100644 --- 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 diff --git a/src/conky.c b/src/conky.c index 1a248b4e..ed026b66 100644 --- a/src/conky.c +++ b/src/conky.c @@ -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); diff --git a/src/conky.h b/src/conky.h index 04ab3083..29731c3a 100644 --- a/src/conky.h +++ b/src/conky.h @@ -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); diff --git a/src/freebsd.c b/src/freebsd.c index c1b04297..5484c519 100644 --- a/src/freebsd.c +++ b/src/freebsd.c @@ -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 */ diff --git a/src/linux.c b/src/linux.c index 25e88d33..adb3512a 100644 --- a/src/linux.c +++ b/src/linux.c @@ -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); + if (!fp) + { + sprintf(adt746x_cpu_state, "adt746x not found"); + } + else + { + fscanf(fp, "%2s", adt746x_cpu_state); + fclose(fp); } - fp = open_file(ADT746X_CPU, &rep); - 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" */ diff --git a/src/netbsd.c b/src/netbsd.c index 4849e9e8..ace1089d 100644 --- a/src/netbsd.c +++ b/src/netbsd.c @@ -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; }