Skip to content

Instantly share code, notes, and snippets.

Created October 25, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ade9ed29fdcd9cbcb185a9303524c1a0 to your computer and use it in GitHub Desktop.
Save anonymous/ade9ed29fdcd9cbcb185a9303524c1a0 to your computer and use it in GitHub Desktop.
diff --git a/src/settings.c b/src/settings.c
index 115a71c..493e835 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[1024];
+ size_t lineNum = 0;
char * const path = BarGetXdgConfigDir (configfiles[j]);
assert (path != NULL);
@@ -214,8 +213,8 @@ 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;
}
@@ -410,7 +409,6 @@ void BarSettingsRead (BarSettings_t *settings) {
fclose (configfd);
free (path);
- free (line);
}
/* check environment variable if proxy is not set explicitly */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment