summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2016-10-29 15:57:20 +0200
committerLars-Dominik Braun <lars@6xq.net>2016-10-29 15:57:20 +0200
commitfd5bbd8d823d8f284c482aa8cace9e09fd1eac78 (patch)
treea04e68af74eeff8e74dce8f4d8dbef17c2c7587f /src
parent79844540a83d7acaf8166b3081913f1968ebf78c (diff)
downloadpianobar-fd5bbd8d823d8f284c482aa8cace9e09fd1eac78.tar.gz
pianobar-fd5bbd8d823d8f284c482aa8cace9e09fd1eac78.tar.bz2
pianobar-fd5bbd8d823d8f284c482aa8cace9e09fd1eac78.zip
Replace getline() with fgets()
Mac OS X 10.6 compatibility, fixes #572.
Diffstat (limited to 'src')
-rw-r--r--src/settings.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/settings.c b/src/settings.c
index 115a71c..5731577 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -201,9 +201,8 @@ void BarSettingsRead (BarSettings_t *settings) {
for (size_t j = 0; j < sizeof (configfiles) / sizeof (*configfiles); j++) {
static const char *formatMsgPrefix = "format_msg_";
FILE *configfd;
- /* getline allocates these on the first run */
- char *line = NULL;
- size_t lineLen = 0, lineNum = 0;
+ char line[512];
+ size_t lineNum = 0;
char * const path = BarGetXdgConfigDir (configfiles[j]);
assert (path != NULL);
@@ -214,11 +213,16 @@ void BarSettingsRead (BarSettings_t *settings) {
while (1) {
++lineNum;
- ssize_t ret = getline (&line, &lineLen, configfd);
- if (ret == -1) {
+ char * const ret = fgets (line, sizeof (line), configfd);
+ if (ret == NULL) {
/* EOF or error */
break;
}
+ if (strchr (line, '\n') == NULL && !feof (configfd)) {
+ BarUiMsg (settings, MSG_INFO, "Line %s:%zu too long, "
+ "ignoring\n", path, lineNum);
+ continue;
+ }
/* parse lines that match "^\s*(.*?)\s?=\s?(.*)$". Windows and Unix
* line terminators are supported. */
char *key = line;
@@ -410,7 +414,6 @@ void BarSettingsRead (BarSettings_t *settings) {
fclose (configfd);
free (path);
- free (line);
}
/* check environment variable if proxy is not set explicitly */