summaryrefslogtreecommitdiff
path: root/app/cwm
diff options
context:
space:
mode:
authorOkan Demirmen <okan@cvs.openbsd.org>2017-07-10 13:36:59 +0000
committerOkan Demirmen <okan@cvs.openbsd.org>2017-07-10 13:36:59 +0000
commit115847adb0d761797d771cad7279a045e368d00d (patch)
tree17fb6bfdc0078bde47e3ce7148d0aad75804d082 /app/cwm
parent46750638651fb5c5ef7a5c1d4e56af4c3876791e (diff)
Replace fgetln(3) with POSIX getline(3); inspired by brynet and Ingo.
feedback and ok brynet@
Diffstat (limited to 'app/cwm')
-rw-r--r--app/cwm/kbfunc.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/app/cwm/kbfunc.c b/app/cwm/kbfunc.c
index c1805ff04..6fe964fe4 100644
--- a/app/cwm/kbfunc.c
+++ b/app/cwm/kbfunc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: kbfunc.c,v 1.145 2017/05/09 13:40:18 okan Exp $
+ * $OpenBSD: kbfunc.c,v 1.146 2017/07/10 13:36:58 okan Exp $
*/
#include <sys/types.h>
@@ -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),