summaryrefslogtreecommitdiffstats
path: root/release/sysinstall/attr.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1996-12-11 18:23:19 +0000
committerjkh <jkh@FreeBSD.org>1996-12-11 18:23:19 +0000
commit17cc23f57886f93c187a29f8994632dac71ebf7b (patch)
treeb4559797b88382d69ce7830e112c0f922eafa0ba /release/sysinstall/attr.c
parente1e9e3aa19b00c35016cddf8a23e2b7fc0d9f4e0 (diff)
downloadFreeBSD-src-17cc23f57886f93c187a29f8994632dac71ebf7b.zip
FreeBSD-src-17cc23f57886f93c187a29f8994632dac71ebf7b.tar.gz
Be more efficient in how we use memory (stumbled across while looking for
something else) for attributes and variables. Remove stack-stomper in sstrncpy().
Diffstat (limited to 'release/sysinstall/attr.c')
-rw-r--r--release/sysinstall/attr.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/release/sysinstall/attr.c b/release/sysinstall/attr.c
index 7b2df73..2310d3c 100644
--- a/release/sysinstall/attr.c
+++ b/release/sysinstall/attr.c
@@ -4,7 +4,7 @@
* This is probably the last attempt in the `sysinstall' line, the next
* generation being slated to essentially a complete rewrite.
*
- * $Id: attr.c,v 1.9 1996/12/09 08:22:10 jkh Exp $
+ * $Id: attr.c,v 1.10 1996/12/11 09:34:53 jkh Exp $
*
* Copyright (c) 1995
* Jordan Hubbard. All rights reserved.
@@ -63,7 +63,7 @@ attr_parse(Attribs *attr, FILE *fp)
int n, v;
enum { LOOK, COMMENT, NAME, VALUE, COMMIT } state;
int lno, num_attribs;
- char ch;
+ int ch;
n = v = lno = num_attribs = 0;
state = LOOK;
@@ -137,19 +137,20 @@ attr_parse(Attribs *attr, FILE *fp)
break;
case COMMIT:
- SAFE_STRCPY(attr[num_attribs].name, hold_n);
- SAFE_STRCPY(attr[num_attribs].value, hold_v);
+ attr[num_attribs].name = strdup(hold_n);
+ attr[num_attribs].value = strdup(hold_v);
state = LOOK;
v = n = 0;
- ++num_attribs;
+ if (++num_attribs >= MAX_ATTRIBS)
+ msgFatal("Attribute limit overflow; encountered a bad attributes file!");
break;
default:
msgFatal("Unknown state at line %d??", lno);
}
}
- attr[num_attribs].name[0] = '\0'; /* end marker */
- attr[num_attribs].value[0] = '\0'; /* end marker */
+ attr[num_attribs].name = NULL; /* end marker */
+ attr[num_attribs].value = NULL; /* end marker */
if (isDebug())
msgDebug("Finished parsing %d attributes.\n", num_attribs);
@@ -164,7 +165,7 @@ attr_match(Attribs *attr, char *name)
if (isDebug())
msgDebug("Trying to match attribute `%s'\n", name);
- for (n = 0; attr[n].name[0] && strcasecmp(attr[n].name, name) != 0; n++) {
+ for (n = 0; attr[n].name && strcasecmp(attr[n].name, name) != 0; n++) {
if (isDebug())
msgDebug("Skipping attribute %u\n", n);
}
@@ -172,7 +173,7 @@ attr_match(Attribs *attr, char *name)
if (isDebug())
msgDebug("Stopped on attribute %u\n", n);
- if (attr[n].name[0]) {
+ if (attr[n].name) {
if (isDebug())
msgDebug("Returning `%s'\n", attr[n].value);
return(attr[n].value);
@@ -180,3 +181,16 @@ attr_match(Attribs *attr, char *name)
return NULL;
}
+
+void
+attr_free(Attribs *attr)
+{
+ int i;
+
+ for (i = 0; attr[i].name; i++) {
+ free(attr[i].name);
+ free(attr[i].value);
+ attr[i].name = attr[i].value = NULL;
+ }
+ free(attr);
+}
OpenPOWER on IntegriCloud