summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 11ab59f)
raw | patch | inline | side by side (parent: 11ab59f)
author | Max Kellermann <max@duempel.org> | |
Thu, 25 Dec 2008 13:09:21 +0000 (14:09 +0100) | ||
committer | Max Kellermann <max@duempel.org> | |
Thu, 25 Dec 2008 13:09:21 +0000 (14:09 +0100) |
Don't read byte by byte until a newline is found. Use fgets()
instead.
instead.
src/conf.c | patch | blob | history |
diff --git a/src/conf.c b/src/conf.c
index 979fd91c4bfb8f7c26e877aba9e915dfb10ae021..27b20242807795ca60a8c7caee83671d9eaa8ad6 100644 (file)
--- a/src/conf.c
+++ b/src/conf.c
static int
read_rc_file(char *filename)
{
- int fd;
- int quit = 0;
+ FILE *file;
+ char line[MAX_LINE_LENGTH];
if (filename == NULL)
return -1;
- if ((fd = open(filename,O_RDONLY)) < 0) {
+ file = fopen(filename, "r");
+ if (file == NULL) {
perror(filename);
return -1;
}
- while (!quit) {
+ while (fgets(line, sizeof(line), file) != NULL) {
int i;
int len;
- char line[MAX_LINE_LENGTH];
-
- i = 0;
- /* read a line ending with '\n' */
- do {
- len = read(fd, &line[i], 1);
- if (len == 1)
- i++;
- else
- quit = 1;
- } while (!quit && i < MAX_LINE_LENGTH && line[i-1] != '\n');
+ i = strlen(line);
/* remove trailing whitespace */
- line[i] = '\0';
i--;
while (i >= 0 && g_ascii_isspace(line[i])) {
line[i] = '\0';
}
}
+ fclose(file);
return 0;
}