roken: Use ptsname_r() if we have it

This commit is contained in:
Nicolas Williams
2021-11-29 17:32:37 -06:00
committed by Jeffrey Altman
parent ed6f3f1786
commit beae9c3c43
3 changed files with 13 additions and 5 deletions

View File

@@ -123,7 +123,18 @@ open_pty(void)
#ifdef HAVE_UNLOCKPT
unlockpt(master);
#endif
strlcpy(line, ptsname(master), sizeof(line));
#ifdef HAVE_PTSNAME_R
if (ptsname_r(master, line, sizeof(line)) == -1)
err("Failed to open the pty master %s", *q);
#else
{
char *s = ptsname(master);
if (s == NULL)
err("Failed to open the pty master %s", *q);
strlcpy(line, s, sizeof(line));
}
#endif
slave = open(line, O_RDWR);
if (slave < 0)
errx(1, "failed to open slave when using %s", *q);