summaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorMurray Stokely <murray@FreeBSD.org>2000-11-22 03:49:49 +0000
committerMurray Stokely <murray@FreeBSD.org>2000-11-22 03:49:49 +0000
commitf412cc8773dcf42da1369d4c78a24ab6f5d3200d (patch)
tree691bb44dbe817f4ca129d0556167ce92236e7b2b /lib/libutil
parentcaa64ad5481dff7742fbcd96b1c6257e71eaaa3f (diff)
Notes
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/libutil.h3
-rw-r--r--lib/libutil/property.34
-rw-r--r--lib/libutil/property.c22
3 files changed, 19 insertions, 10 deletions
diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h
index 18fb83ff98cf..4125b1ac1cca 100644
--- a/lib/libutil/libutil.h
+++ b/lib/libutil/libutil.h
@@ -31,6 +31,9 @@
#include <sys/cdefs.h>
+#define PROPERTY_MAX_NAME 64
+#define PROPERTY_MAX_VALUE 512
+
/* for properties.c */
typedef struct _property {
struct _property *next;
diff --git a/lib/libutil/property.3 b/lib/libutil/property.3
index 22b6e9998535..6d5cd4ffc72c 100644
--- a/lib/libutil/property.3
+++ b/lib/libutil/property.3
@@ -66,7 +66,9 @@ of error.
.Fn property_find
Returns the associated value string for the property named
.Fa name
-if found, otherwise NULL.
+if found, otherwise NULL. The value returned may be up to
+.Dv PROPERTY_MAX_VALUE
+bytes in length.
.Pp
.Fn properties_free
is used to free the structure returned by
diff --git a/lib/libutil/property.c b/lib/libutil/property.c
index 23714a0c3daf..91189d9d8e09 100644
--- a/lib/libutil/property.c
+++ b/lib/libutil/property.c
@@ -28,6 +28,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
+ * $FreeBSD$
+ *
*/
#include <ctype.h>
@@ -39,9 +41,6 @@
#include <sys/types.h>
#include <libutil.h>
-#define MAX_NAME 64
-#define MAX_VALUE 512
-
static properties
property_alloc(char *name, char *value)
{
@@ -58,8 +57,8 @@ properties
properties_read(int fd)
{
properties head, ptr;
- char hold_n[MAX_NAME + 1];
- char hold_v[MAX_VALUE + 1];
+ char hold_n[PROPERTY_MAX_NAME + 1];
+ char hold_v[PROPERTY_MAX_VALUE + 1];
char buf[BUFSIZ * 4];
int bp, n, v, max;
enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state;
@@ -97,7 +96,7 @@ properties_read(int fd)
continue;
}
else if (isalnum(ch) || ch == '_') {
- if (n >= MAX_NAME) {
+ if (n >= PROPERTY_MAX_NAME) {
n = 0;
state = COMMENT;
}
@@ -134,7 +133,12 @@ properties_read(int fd)
break;
case VALUE:
- if (v == 0 && isspace(ch))
+ if (v == 0 && ch == '\n') {
+ hold_v[v] = '\0';
+ v = n = 0;
+ state = COMMIT;
+ }
+ else if (v == 0 && isspace(ch))
continue;
else if (ch == '{') {
state = MVALUE;
@@ -146,7 +150,7 @@ properties_read(int fd)
state = COMMIT;
}
else {
- if (v >= MAX_VALUE) {
+ if (v >= PROPERTY_MAX_VALUE) {
state = COMMENT;
v = n = 0;
break;
@@ -158,7 +162,7 @@ properties_read(int fd)
case MVALUE:
/* multiline value */
- if (v >= MAX_VALUE) {
+ if (v >= PROPERTY_MAX_VALUE) {
warn("properties_read: value exceeds max length");
state = COMMENT;
n = v = 0;