diff options
| author | John Baldwin <jhb@FreeBSD.org> | 2005-11-28 16:30:16 +0000 |
|---|---|---|
| committer | John Baldwin <jhb@FreeBSD.org> | 2005-11-28 16:30:16 +0000 |
| commit | a54bb702d77b01653ff82e9f000dcafd10a9ec13 (patch) | |
| tree | 018eda33e27ac8d4eba87ae0559d4c54116168ec /lib/libutil | |
| parent | 8fa1d32e68f21378bdbb252154b498d884607ec1 (diff) | |
Notes
Diffstat (limited to 'lib/libutil')
| -rw-r--r-- | lib/libutil/property.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/libutil/property.c b/lib/libutil/property.c index f2c3917e9296..a944f9d2fb23 100644 --- a/lib/libutil/property.c +++ b/lib/libutil/property.c @@ -75,17 +75,18 @@ properties_read(int fd) 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; + enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state, last_state; int ch = 0, blevel = 0; n = v = bp = max = 0; head = ptr = NULL; - state = LOOK; + state = last_state = LOOK; while (state != STOP) { if (state != COMMIT) { - if (bp == max) + if (bp == max) { + last_state = state; state = FILL; - else + } else ch = buf[bp++]; } switch(state) { @@ -96,13 +97,19 @@ properties_read(int fd) } if (max == 0) { state = STOP; - break; } else { - state = LOOK; + /* + * Restore the state from before the fill (which will be + * initialised to LOOK for the first FILL). This ensures that + * if we were part-way through eg., a VALUE state, when the + * buffer ran out, that the previous operation will be allowed + * to complete. + */ + state = last_state; ch = buf[0]; - bp = 1; + bp = 0; } - /* FALLTHROUGH deliberately since we already have a character and state == LOOK */ + continue; case LOOK: if (isspace((unsigned char)ch)) |
