]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Created new functions for allocating configuration data:
authorMartin Mares <mj@ucw.cz>
Sun, 29 Nov 1998 21:59:37 +0000 (21:59 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 29 Nov 1998 21:59:37 +0000 (21:59 +0000)
   o  cfg_alloc(size) -- generic memory allocation
   o  cfg_allocu(size) -- unaligned memory allocation
   o  cfg_allocz(size) -- zeroed memory allocation
   o  cfg_strcpy(str) -- allocate a copy of a string

Also fixed a bug in lexing of string literals.

conf/cf-lex.l
conf/conf.h

index 66f3038244ac96a12d44be77cd94296332fc90e6..eb1d3300b20db4825ddae0be35ff588f50f8461e 100644 (file)
@@ -107,7 +107,7 @@ WHITE [ \t]
 
 ["][^"\n]*["] {
   cf_lval.t = yytext+1;
-  yytext[yyleng] = 0;
+  yytext[yyleng-1] = 0;
   return TEXT;
 }
 
@@ -172,7 +172,7 @@ cf_find_sym(byte *c, unsigned int h0)
   l = strlen(c);
   if (l > SYM_MAX_LEN)
     cf_error("Symbol too long");
-  s = mp_alloc(cfg_mem, sizeof(struct symbol) + l);
+  s = cfg_alloc(sizeof(struct symbol) + l);
   s->next = sym_hash[h];
   sym_hash[h] = s;
   s->class = SYM_VOID;
@@ -202,7 +202,7 @@ void
 cf_lex_init(int flag)
 {
   if (allow_new_symbols = flag)
-    sym_hash = mp_allocz(cfg_mem, SYM_HASH_SIZE * sizeof(struct keyword *));
+    sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *));
   cf_lino = 1;
   default_counter = 1;
 }
@@ -234,3 +234,12 @@ cf_allocate(void)
   cfg_pool = rp_new(&root_pool, "Config");
   cfg_mem = mp_new(cfg_pool, 1024);
 }
+
+char *
+cfg_strcpy(char *c)
+{
+  int l = strlen(c) + 1;
+  char *z = cfg_allocu(l);
+  memcpy(z, c, l);
+  return z;
+}
index 6a0a328dc7a28b7b6dfbcd7182920efad9895387..93d1edd7d669528dfa4b9417047c8e0c2d513bf5 100644 (file)
 
 #include "lib/resource.h"
 
+/* Pools */
+
 extern pool *cfg_pool;
 extern mempool *cfg_mem;
 
+#define cfg_alloc(size) mp_alloc(cfg_mem, size)
+#define cfg_allocu(size) mp_allocu(cfg_mem, size)
+#define cfg_allocz(size) mp_allocz(cfg_mem, size)
+char *cfg_strcpy(char *c);
+
 /* Lexer */
 
 extern int (*cf_read_hook)(byte *buf, unsigned int max);