From fd5bbd8d823d8f284c482aa8cace9e09fd1eac78 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <lars@6xq.net>
Date: Sat, 29 Oct 2016 15:57:20 +0200
Subject: Replace getline() with fgets()

Mac OS X 10.6 compatibility, fixes #572.
---
 src/settings.c | 15 +++++++++------
 1 file 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 */
-- 
cgit v1.2.3