mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-28 01:40:17 -05:00
client: allocate current working directory buffer dynamically
This commit is contained in:
parent
bb3c20e284
commit
e751227dc6
1 changed files with 14 additions and 2 deletions
16
client.c
16
client.c
|
|
@ -151,8 +151,19 @@ main(int argc, char *const *argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char cwd[4096];
|
char *cwd = NULL;
|
||||||
getcwd(cwd, sizeof(cwd));
|
{
|
||||||
|
errno = 0;
|
||||||
|
size_t buf_len = 1024;
|
||||||
|
do {
|
||||||
|
cwd = realloc(cwd, buf_len);
|
||||||
|
if (getcwd(cwd, buf_len) == NULL && errno != ERANGE) {
|
||||||
|
LOG_ERRNO("failed to get current working directory");
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
buf_len *= 2;
|
||||||
|
} while (errno == ERANGE);
|
||||||
|
}
|
||||||
const uint16_t cwd_len = strlen(cwd) + 1;
|
const uint16_t cwd_len = strlen(cwd) + 1;
|
||||||
|
|
||||||
const uint16_t term_len = strlen(term) + 1;
|
const uint16_t term_len = strlen(term) + 1;
|
||||||
|
|
@ -232,6 +243,7 @@ main(int argc, char *const *argv)
|
||||||
ret = exit_code;
|
ret = exit_code;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
|
free(cwd);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
log_deinit();
|
log_deinit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue