]> mj.ucw.cz Git - libucw.git/commitdiff
memory pool for everything about configuration added
authorRobert Spalek <robert@ucw.cz>
Sun, 21 Jan 2001 19:14:46 +0000 (19:14 +0000)
committerRobert Spalek <robert@ucw.cz>
Sun, 21 Jan 2001 19:14:46 +0000 (19:14 +0000)
value of CT_FUNCTION callback is now cfg_stralloc()'ed

lib/conf.c
lib/conf.h

index 34cede8feb8e007606465a21dea3554134b24a01..b6cf5237297953fe2a6b04ab133e0815aff8639d 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "lib/chartype.h"
 #include "lib/fastbuf.h"
-#include "lib/lfs.h"
+#include "lib/pools.h"
 
 #include "lib/conf.h"
 
 #define        MAX_LEVEL       8
 
 static struct cfitem *cfsection;
+static struct mempool *cfpool;
+
+static void CONSTRUCTOR
+conf_init(void)
+{
+       cfpool = mp_new(4096);
+}
+
+void *
+cfg_malloc(uns size)
+{
+       return mp_alloc(cfpool, size);
+}
+
+byte *
+cfg_stralloc(byte *s)
+{
+  uns l = strlen(s);
+  byte *k = cfg_malloc(l + 1);
+  strcpy(k, s);
+  return k;
+}
 
 void cf_register(struct cfitem *items)
 {
@@ -58,10 +80,10 @@ byte *cf_set_item(byte *sect, byte *name, byte *value)
                                break;
                        }
                case CT_STRING:
-                       *((byte **) item->var) = stralloc(value);
+                       *((byte **) item->var) = cfg_stralloc(value);
                        break;
                case CT_FUNCTION:
-                       msg = ((ci_func) item->var)(item, value);
+                       msg = ((ci_func) item->var)(item, cfg_stralloc(value));
                        break;
                default:
                        msg = "Unknown keyword";
@@ -84,7 +106,7 @@ static int cf_subread(byte *filename,int level)
                return 0;
        }
                
-       fd=sh_open(filename,O_RDONLY, 0666);
+       fd=open(filename,O_RDONLY, 0666);
        if(fd<0){
                log(L_ERROR,"Cannot open configuration file %s: %m",filename);
                return 0;
index d2a56af5b30b877bf1eede49fa683bcc7fb74254..2cee8f651a8b068cf337b98c8effaadd0d5f0422 100644 (file)
@@ -6,6 +6,16 @@
 
 #include <getopt.h>
 
+/*
+ * Allocation in configuration memory pool.
+ */
+
+void *
+cfg_malloc(uns size);
+
+byte *
+cfg_stralloc(byte *s);
+
 /*
  * Every module places its configuration setting into some section.  Section is
  * an array of cfitem, whose first record is of type CT_SECTION and contains