Changeset 97

Show
Ignore:
Timestamp:
12/20/98 22:57:39 (10 years ago)
Author:
frodo
Message:

More library stuff

Nice init and cleanup functions.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/lib/Module.mk

    r95 r97  
    3737LIBCSOURCES := $(MODULE_DIR)/data.c $(MODULE_DIR)/general.c \ 
    3838               $(MODULE_DIR)/error.c $(MODULE_DIR)/chips.c \ 
    39                $(MODULE_DIR)/proc.c $(MODULE_DIR)/access.c 
     39               $(MODULE_DIR)/proc.c $(MODULE_DIR)/access.c \ 
     40               $(MODULE_DIR)/init.c 
    4041LIBOTHEROBJECTS := $(MODULE_DIR)/conf-parse.o $(MODULE_DIR)/conf-lex.o 
    4142LIBSHOBJECTS := $(LIBCSOURCES:.c=.lo) $(LIBOTHEROBJECTS:.o=.lo) 
  • lm-sensors/trunk/lib/access.c

    r95 r97  
    142142    for (i = 0; i < chip->labels_count; i++) 
    143143      if (!strcmp(featureptr->name, chip->labels[i].name)) { 
    144         *result = strdup(chip->labels[i].name); 
     144        if (! (*result = strdup(chip->labels[i].name))) 
     145          sensors_fatal_error("sensors_get_label","Allocating label text"); 
    145146        return 0; 
    146147      } 
    147   *result = strdup(featureptr->name); 
     148  if (! (*result = strdup(featureptr->name))) 
     149    sensors_fatal_error("sensors_get_label","Allocating label text"); 
    148150  return 0; 
    149151} 
  • lm-sensors/trunk/lib/data.c

    r95 r97  
    6767  int i; 
    6868 
     69  if (! name) 
     70    sensors_fatal_error("sensors_parse_chip_name","Allocating new name"); 
    6971  /* First split name in upto four pieces. */ 
    7072  if ((part4 = strrchr(name,'-'))) 
     
    156158  if (!strcmp(name,"*")) 
    157159    res->prefix = SENSORS_CHIP_NAME_PREFIX_ANY; 
    158   else 
    159     res->prefix = strdup(name); 
     160  else if (! (res->prefix = strdup(name))) 
     161    sensors_fatal_error("sensors_parse_chip_name","Allocating new name"); 
    160162  goto SUCCES; 
    161163 
  • lm-sensors/trunk/lib/data.h

    r95 r97  
    2323#include "sensors.h" 
    2424 
    25 /* This header file contains all kinds of data structures which are 
    26    internally used. */ 
     25/* This header file contains all kinds of data structures which are used 
     26   for the representation of the config file data and the /proc/.../chips 
     27   data. */ 
    2728 
    2829typedef enum sensors_operation {  
  • lm-sensors/trunk/lib/error.c

    r91 r97  
    4242#define ERROR_LIST_LEN (sizeof(errorlist) / sizeof(char *)) 
    4343 
    44 char *sensors_strerror(int errnum) 
     44const char *sensors_strerror(int errnum) 
    4545{ 
    4646  if (errnum < 0) 
  • lm-sensors/trunk/lib/error.h

    r91 r97  
    2828#define SENSORS_ERR_CHIP_NAME 6 /* Can't parse chip name */ 
    2929#define SENSORS_ERR_BUS_NAME 7  /* Can't parse bus name */ 
     30#define SENSORS_ERR_PARSE 8     /* General parse error */ 
    3031 
    3132/* This function returns a pointer to a string which describes the error. 
    3233   errnum may be negative (the corresponding positive error is returned). 
    3334   You may not modify the result! */ 
    34 extern char *sensors_strerror(int errnum); 
     35extern const char *sensors_strerror(int errnum); 
    3536 
    3637/* This function is called when a parse error is detected. Give it a new 
  • lm-sensors/trunk/lib/sensors.h

    r95 r97  
    3535} sensors_chip_name; 
    3636 
     37/* (Re)load the configuration file and the detected chips list. */ 
     38extern int sensors_init(void); 
     39 
     40/* Strictly optional clean-up function: You can't access anything after 
     41   this, until the next sensors_init() call! */ 
     42extern void sensors_cleanup(void); 
     43 
     44 
    3745/* Parse a chip name to the internal representation. Return 0 on succes, <0 
    3846   on error. */