1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-11 06:20:23 +02:00

(scm_ctermid): Use an L_ctermid buf on the stack, for thread safety.

This commit is contained in:
Kevin Ryde 2004-07-27 23:10:35 +00:00
parent 081c1b24fa
commit 0a9d83b0f4

View file

@ -792,6 +792,11 @@ SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
#undef FUNC_NAME
#endif /* HAVE_TTYNAME */
/* For thread safety "buf" is used instead of NULL for the ctermid static
buffer. Actually it's unlikely the controlling terminal will change
during program execution, and indeed on glibc (2.3.2) it's always just
"/dev/tty", but L_ctermid on the stack is easy and fast and guarantees
safety everywhere. */
#ifdef HAVE_CTERMID
SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
(),
@ -799,7 +804,8 @@ SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
"terminal for the current process.")
#define FUNC_NAME s_scm_ctermid
{
char *result = ctermid (NULL);
char buf[L_ctermid];
char *result = ctermid (buf);
if (*result == '\0')
SCM_SYSERROR;
return scm_makfrom0str (result);