diff options
author | rcyeske <rcyeske> | 2001-02-25 00:21:34 +0000 |
---|---|---|
committer | rcyeske <rcyeske> | 2001-02-25 00:21:34 +0000 |
commit | 610e5411c20c1dcf5c599067fe00585140e79841 (patch) | |
tree | f5893f114dbdcfd27c520784f8d8d1b8f69d5a39 /src/main.c | |
parent | 854ddcaf13f857e969bf24a966ea1647a011c42f (diff) | |
download | ratpoison-610e5411c20c1dcf5c599067fe00585140e79841.zip |
removed dependancy on gnu extension: getline()
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 44 |
1 files changed, 30 insertions, 14 deletions
@@ -31,6 +31,7 @@ #include <signal.h> #include <unistd.h> #include <getopt.h> +#include <string.h> #include "ratpoison.h" @@ -181,30 +182,45 @@ load_rc_file (char *filename) { FILE *rcfile; - char *lineptr; - size_t n; - - n = 0; - lineptr = NULL; - if ((rcfile = fopen (filename, "r")) == NULL) { fprintf (stderr, "ratpoison: could not open %s\n", filename); } else { - size_t retval; - n = 256; - lineptr = (char*)malloc(n); - - while ((retval = getline (&lineptr, &n, rcfile)) != EOF) + size_t n = 256; + char *partial; + char *line; + int linesize = n; + + partial = (char*)malloc(n); + line = (char*)malloc(linesize); + + *line = '\0'; + while (fgets (partial, n, rcfile) != NULL) { - fprintf (stderr, "read command: %s\n", lineptr); + if ((strlen (line) + strlen (partial)) <= linesize) + { + linesize *= 2; + line = (char*) realloc (line, linesize); + } + + strcat (line, partial); - command (lineptr); + if (feof(rcfile) || (*(line + strlen(line) - 1) == '\n')) + { + fprintf (stderr, "read line: %s\n", line); + + /* do it */ + command (line); + + *line = '\0'; + } } - free (lineptr); + + free (line); + free (partial); } } |