about summary refs log tree commit diff
path: root/kbfunc.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-07-11 13:15:08 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-07-11 13:15:08 +0200
commit1ceb2dd795ccf5b4129947957ab69e46572f9b1c (patch)
treeea5f498687e23805a5237f8ccbf54561ae5c9b3d /kbfunc.c
parent4040f112e11c844e1226ac5c66c4da6e8ae72cc6 (diff)
parentd179dfdeb97d1f4d16d56ae5783044770d87898c (diff)
downloadcwm-1ceb2dd795ccf5b4129947957ab69e46572f9b1c.tar.gz
cwm-1ceb2dd795ccf5b4129947957ab69e46572f9b1c.tar.xz
cwm-1ceb2dd795ccf5b4129947957ab69e46572f9b1c.zip
cvsimport
* refs/heads/master:
  Replace fgetln(3) with POSIX getline(3); inspired by brynet and Ingo.
  fix a few WARNINGS (new sentence, new line and extraneous Pp macro) found with mandoc -Tlint
  from src, by espie@: no need to generate y.tab.h if nothing uses it, set YFLAGS to nothing
Diffstat (limited to 'kbfunc.c')
-rw-r--r--kbfunc.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/kbfunc.c b/kbfunc.c
index 5e3a458..2b93ed5 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -468,6 +468,7 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
 	char			 path[PATH_MAX];
 	int			 l;
 	size_t			 len;
+	ssize_t			 slen;
 
 	TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
 		if (strcmp(cmd->name, "term") == 0)
@@ -481,20 +482,16 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
 	}
 
 	lbuf = NULL;
-	while ((buf = fgetln(fp, &len))) {
-		if (buf[len - 1] == '\n')
-			buf[len - 1] = '\0';
-		else {
-			/* EOF without EOL, copy and add the NUL */
-			lbuf = xmalloc(len + 1);
-			(void)memcpy(lbuf, buf, len);
-			lbuf[len] = '\0';
-			buf = lbuf;
-		}
+	len = 0;
+	while ((slen = getline(&lbuf, &len, fp)) != -1) {
+		buf = lbuf;
+		if (buf[slen - 1] == '\n')
+			buf[slen - 1] = '\0';
+		
 		/* skip hashed hosts */
 		if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
 			continue;
-		for (p = buf; *p != ',' && *p != ' ' && p != buf + len; p++) {
+		for (p = buf; *p != ',' && *p != ' ' && p != buf + slen; p++) {
 			/* do nothing */
 		}
 		/* ignore badness */
@@ -504,6 +501,8 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
 		menuq_add(&menuq, NULL, "%s", hostbuf);
 	}
 	free(lbuf);
+	if (ferror(fp))
+		err(1, "%s", path);
 	(void)fclose(fp);
 menu:
 	if ((mi = menu_filter(sc, &menuq, "ssh", NULL, (CWM_MENU_DUMMY),