* 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
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);
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);
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 */
#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> */
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;
}
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;
}