diff options
Diffstat (limited to 'src/rc/rc-misc.c')
-rw-r--r-- | src/rc/rc-misc.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/rc/rc-misc.c b/src/rc/rc-misc.c index 85d7cd76..79db4323 100644 --- a/src/rc/rc-misc.c +++ b/src/rc/rc-misc.c @@ -238,7 +238,7 @@ char **env_filter (void) static bool file_regex (const char *file, const char *regex) { FILE *fp; - char *buffer; + char *line; regex_t re; bool retval = false; int result; @@ -246,23 +246,22 @@ static bool file_regex (const char *file, const char *regex) if (! (fp = fopen (file, "r"))) return (false); - buffer = xmalloc (sizeof (char) * RC_LINEBUFFER); if ((result = regcomp (&re, regex, REG_EXTENDED | REG_NOSUB)) != 0) { fclose (fp); - regerror (result, &re, buffer, RC_LINEBUFFER); - fprintf (stderr, "file_regex: %s", buffer); - free (buffer); + line = xmalloc (sizeof (char) * BUFSIZ); + regerror (result, &re, line, BUFSIZ); + fprintf (stderr, "file_regex: %s", line); + free (line); return (false); } - while (fgets (buffer, RC_LINEBUFFER, fp)) { - if (regexec (&re, buffer, 0, NULL, 0) == 0) - { + while ((line = rc_getline (fp))) { + if (regexec (&re, line, 0, NULL, 0) == 0) retval = true; + free (line); + if (retval) break; - } } - free (buffer); fclose (fp); regfree (&re); |