summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-13 04:36:23 +0200
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2013-04-13 12:43:55 +0200
commit5a6fe0574c77342f29370219fb9010b72d6d3a00 (patch)
tree43f26dcea697728352120ba950653351b00dbbb8
parentb202c4e9385ec4d9a9f67a006ee363a2618051d9 (diff)
downloadratpoison-5a6fe0574c77342f29370219fb9010b72d6d3a00.zip
read_rc_file: use getline(3) instead of emulating it
-rw-r--r--src/main.c49
1 files changed, 11 insertions, 38 deletions
diff --git a/src/main.c b/src/main.c
index ea72f67..de2a793 100644
--- a/src/main.c
+++ b/src/main.c
@@ -365,56 +365,29 @@ set_close_on_exec (FILE *fd)
void
read_rc_file (FILE *file)
{
- size_t n = 256;
- char *partial;
char *line;
- size_t linesize = n;
+ size_t linesize = 256;
- partial = (char*)xmalloc(n);
- line = (char*)xmalloc(linesize);
+ line = xmalloc (linesize);
- *line = '\0';
- while (fgets (partial, n, file) != NULL)
+ while (getline (&line, &linesize, file) != -1)
{
- if ((strlen (line) + strlen (partial)) >= linesize)
- {
- linesize *= 2;
- line = (char*) xrealloc (line, linesize);
- }
+ line[strcspn (line, "\n")] = '\0';
- strcat (line, partial);
+ PRINT_DEBUG (("rcfile line: %s\n", line));
- if (feof(file) || (*(line + strlen(line) - 1) == '\n'))
+ if (*line != '\0' && *line != '#')
{
- /* FIXME: this is a hack, command() should properly parse
- the command and args (ie strip whitespace, etc)
-
- We should not care if there is a newline (or vertical
- tabs or linefeeds for that matter) at the end of the
- command (or anywhere between tokens). */
- if (*(line + strlen(line) - 1) == '\n')
- *(line + strlen(line) - 1) = '\0';
+ cmdret *result;
+ result = command (0, line);
- PRINT_DEBUG (("rcfile line: %s\n", line));
-
- /* do it */
- if (*line != '#')
- {
- cmdret *result;
- result = command (0, line);
-
- /* Gobble the result. */
- if (result)
- cmdret_free (result);
- }
-
- *line = '\0';
+ /* Gobble the result. */
+ if (result)
+ cmdret_free (result);
}
}
-
free (line);
- free (partial);
}
static void