mirror of
git://sourceware.org/git/glibc.git
synced 2025-03-06 20:58:33 +01:00
ctermid: return string literal, document MT-Safety pitfall
for ChangeLog * sysdeps/posix/ctermid.c (ctermid): Return a pointer to a string literal if not passed a buffer. * manual/job.texi (ctermid): Update reasoning, note deviation from posix, suggest mtasurace when not passed a buffer, for future non-preliminary safety notes.
This commit is contained in:
parent
a4ea5e2809
commit
7729e0e91a
3 changed files with 21 additions and 11 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2014-11-21 Alexandre Oliva <aoliva@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/posix/ctermid.c (ctermid): Return a pointer to a
|
||||||
|
string literal if not passed a buffer.
|
||||||
|
* manual/job.texi (ctermid): Update reasoning, note deviation
|
||||||
|
from posix, suggest mtasurace when not passed a buffer, for
|
||||||
|
future non-preliminary safety notes.
|
||||||
|
|
||||||
2014-11-21 Alexandre Oliva <aoliva@redhat.com>
|
2014-11-21 Alexandre Oliva <aoliva@redhat.com>
|
||||||
|
|
||||||
* manual/users.texi (cuserid): Fix MT-Safety note for the case
|
* manual/users.texi (cuserid): Fix MT-Safety note for the case
|
||||||
|
|
|
@ -1039,10 +1039,12 @@ The function @code{ctermid} is declared in the header file
|
||||||
@comment stdio.h
|
@comment stdio.h
|
||||||
@comment POSIX.1
|
@comment POSIX.1
|
||||||
@deftypefun {char *} ctermid (char *@var{string})
|
@deftypefun {char *} ctermid (char *@var{string})
|
||||||
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
|
@safety{@prelim{}@mtsafe{@mtsposix{/!string}}@assafe{}@acsafe{}}
|
||||||
@c This function is a stub by default; the actual implementation, for
|
@c This function is a stub by default; the actual implementation, for
|
||||||
@c posix systems, returns an internal buffer if passed a NULL string,
|
@c posix systems, returns a pointer to a string literal if passed a NULL
|
||||||
@c but the internal buffer is always set to /dev/tty.
|
@c string. It's not clear we want to commit to being MT-Safe in the
|
||||||
|
@c !string case, so maybe add mtasurace{:ctermid/!string} when we take
|
||||||
|
@c prelim out, to make room for using a static buffer in the future.
|
||||||
The @code{ctermid} function returns a string containing the file name of
|
The @code{ctermid} function returns a string containing the file name of
|
||||||
the controlling terminal for the current process. If @var{string} is
|
the controlling terminal for the current process. If @var{string} is
|
||||||
not a null pointer, it should be an array that can hold at least
|
not a null pointer, it should be an array that can hold at least
|
||||||
|
|
|
@ -19,17 +19,17 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
/* Return the name of the controlling terminal.
|
/* Return the name of the controlling terminal. If S is not NULL, the
|
||||||
If S is not NULL, the name is copied into it (it should be at
|
name is copied into it (it should be at least L_ctermid bytes
|
||||||
least L_ctermid bytes long), otherwise a static buffer is used. */
|
long), otherwise we return a pointer to a non-const but read-only
|
||||||
|
string literal, that POSIX states the caller must not modify. */
|
||||||
char *
|
char *
|
||||||
ctermid (s)
|
ctermid (char *s)
|
||||||
char *s;
|
|
||||||
{
|
{
|
||||||
static char name[L_ctermid];
|
char *name = (char /*drop const*/ *) "/dev/tty";
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
s = name;
|
return name;
|
||||||
|
|
||||||
return strcpy (s, "/dev/tty");
|
return strcpy (s, name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue