diff options
Diffstat (limited to 'contrib/cvs/src/myndbm.c')
-rw-r--r-- | contrib/cvs/src/myndbm.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/contrib/cvs/src/myndbm.c b/contrib/cvs/src/myndbm.c index 949ac78..6b15e77 100644 --- a/contrib/cvs/src/myndbm.c +++ b/contrib/cvs/src/myndbm.c @@ -200,27 +200,34 @@ mydbm_load_file (fp, list) List *list; { char *line = NULL; - size_t line_len; + size_t line_size; char *value; size_t value_allocated; char *cp, *vp; - int len, cont; + int cont; int line_length; value_allocated = 1; value = xmalloc (value_allocated); - for (cont = 0; (line_length = getline (&line, &line_len, fp)) >= 0;) + cont = 0; + while ((line_length = getstr (&line, &line_size, fp, '\012', 0)) >= 0) { - if ((cp = strrchr (line, '\012')) != NULL) - *cp = '\0'; /* strip the newline */ - cp = line + strlen (line); - if (cp > line && cp[-1] == '\015') + if (line_length > 0 && line[line_length - 1] == '\012') + { + /* Strip the newline. */ + --line_length; + line[line_length] = '\0'; + } + if (line_length > 0 && line[line_length - 1] == '\015') + { /* If the file (e.g. modules) was written on an NT box, it will contain CRLF at the ends of lines. Strip them (we can't do this by opening the file in text mode because we might be running on unix). */ - cp[-1] = '\0'; + --line_length; + line[line_length] = '\0'; + } /* * Add the line to the value, at the end if this is a continuation @@ -234,15 +241,15 @@ mydbm_load_file (fp, list) * See if the line we read is a continuation line, and strip the * backslash if so. */ - len = strlen (line); - if (len > 0) - cp = &line[len - 1]; + if (line_length > 0) + cp = &line[line_length - 1]; else cp = line; if (*cp == '\\') { cont = 1; *cp = '\0'; + --line_length; } else { @@ -250,7 +257,7 @@ mydbm_load_file (fp, list) } expand_string (&value, &value_allocated, - strlen (value) + strlen (line) + 5); + strlen (value) + line_length + 5); strcat (value, line); if (value[0] == '#') |