mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
Replace fgetln(3) with POSIX getline(3); inspired by brynet and Ingo.
feedback and ok brynet@
This commit is contained in:
parent
f94fde51fb
commit
d179dfdeb9
21
kbfunc.c
21
kbfunc.c
@ -468,6 +468,7 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
|
|||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
int l;
|
int l;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
ssize_t slen;
|
||||||
|
|
||||||
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
TAILQ_FOREACH(cmd, &Conf.cmdq, entry) {
|
||||||
if (strcmp(cmd->name, "term") == 0)
|
if (strcmp(cmd->name, "term") == 0)
|
||||||
@ -481,20 +482,16 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
lbuf = NULL;
|
lbuf = NULL;
|
||||||
while ((buf = fgetln(fp, &len))) {
|
len = 0;
|
||||||
if (buf[len - 1] == '\n')
|
while ((slen = getline(&lbuf, &len, fp)) != -1) {
|
||||||
buf[len - 1] = '\0';
|
buf = lbuf;
|
||||||
else {
|
if (buf[slen - 1] == '\n')
|
||||||
/* EOF without EOL, copy and add the NUL */
|
buf[slen - 1] = '\0';
|
||||||
lbuf = xmalloc(len + 1);
|
|
||||||
(void)memcpy(lbuf, buf, len);
|
|
||||||
lbuf[len] = '\0';
|
|
||||||
buf = lbuf;
|
|
||||||
}
|
|
||||||
/* skip hashed hosts */
|
/* skip hashed hosts */
|
||||||
if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
|
if (strncmp(buf, HASH_MARKER, strlen(HASH_MARKER)) == 0)
|
||||||
continue;
|
continue;
|
||||||
for (p = buf; *p != ',' && *p != ' ' && p != buf + len; p++) {
|
for (p = buf; *p != ',' && *p != ' ' && p != buf + slen; p++) {
|
||||||
/* do nothing */
|
/* do nothing */
|
||||||
}
|
}
|
||||||
/* ignore badness */
|
/* ignore badness */
|
||||||
@ -504,6 +501,8 @@ kbfunc_menu_ssh(void *ctx, struct cargs *cargs)
|
|||||||
menuq_add(&menuq, NULL, "%s", hostbuf);
|
menuq_add(&menuq, NULL, "%s", hostbuf);
|
||||||
}
|
}
|
||||||
free(lbuf);
|
free(lbuf);
|
||||||
|
if (ferror(fp))
|
||||||
|
err(1, "%s", path);
|
||||||
(void)fclose(fp);
|
(void)fclose(fp);
|
||||||
menu:
|
menu:
|
||||||
if ((mi = menu_filter(sc, &menuq, "ssh", NULL, (CWM_MENU_DUMMY),
|
if ((mi = menu_filter(sc, &menuq, "ssh", NULL, (CWM_MENU_DUMMY),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user