mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 14:50:19 +02:00
(scm_ctermid): Use an L_ctermid buf on the stack, for thread safety.
This commit is contained in:
parent
081c1b24fa
commit
0a9d83b0f4
1 changed files with 7 additions and 1 deletions
|
@ -792,6 +792,11 @@ SCM_DEFINE (scm_ttyname, "ttyname", 1, 0, 0,
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
#endif /* HAVE_TTYNAME */
|
#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
|
#ifdef HAVE_CTERMID
|
||||||
SCM_DEFINE (scm_ctermid, "ctermid", 0, 0, 0,
|
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.")
|
"terminal for the current process.")
|
||||||
#define FUNC_NAME s_scm_ctermid
|
#define FUNC_NAME s_scm_ctermid
|
||||||
{
|
{
|
||||||
char *result = ctermid (NULL);
|
char buf[L_ctermid];
|
||||||
|
char *result = ctermid (buf);
|
||||||
if (*result == '\0')
|
if (*result == '\0')
|
||||||
SCM_SYSERROR;
|
SCM_SYSERROR;
|
||||||
return scm_makfrom0str (result);
|
return scm_makfrom0str (result);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue