aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-12-25 14:09:21 +0100
committerMax Kellermann <max@duempel.org>2008-12-25 14:09:21 +0100
commit4152c4f6b51f576136f901f13605874d951f5ca1 (patch)
tree02b51f8529b0b39ddbc6bfc5d9e7de274cc8cfd0
parent11ab59f9d7b3c247bf7b2fecafde9e60e96ea60f (diff)
downloadmpd-4152c4f6b51f576136f901f13605874d951f5ca1.tar.gz
mpd-4152c4f6b51f576136f901f13605874d951f5ca1.tar.xz
mpd-4152c4f6b51f576136f901f13605874d951f5ca1.zip
conf: use buffered I/O for reading the config file
Don't read byte by byte until a newline is found. Use fgets() instead.
-rw-r--r--src/conf.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/conf.c b/src/conf.c
index 979fd91c4..27b202428 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -502,35 +502,25 @@ parse_line(char *line)
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';
@@ -551,6 +541,7 @@ read_rc_file(char *filename)
}
}
+ fclose(file);
return 0;
}