diff options
author | Alexandre Oliva <aoliva@redhat.com> | 2014-11-21 02:06:22 -0200 |
---|---|---|
committer | Alexandre Oliva <aoliva@redhat.com> | 2014-11-21 02:16:02 -0200 |
commit | 7729e0e91afbf8d45bb322d7e2d53f417fab01ed (patch) | |
tree | b081908ff729dc647b179cb425fbe721e857cbe8 /sysdeps/posix/ctermid.c | |
parent | a4ea5e2809a20521e4300725d5062768883ffc50 (diff) | |
download | glibc-7729e0e91afbf8d45bb322d7e2d53f417fab01ed.tar.gz glibc-7729e0e91afbf8d45bb322d7e2d53f417fab01ed.tar.xz glibc-7729e0e91afbf8d45bb322d7e2d53f417fab01ed.zip |
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.
Diffstat (limited to 'sysdeps/posix/ctermid.c')
-rw-r--r-- | sysdeps/posix/ctermid.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sysdeps/posix/ctermid.c b/sysdeps/posix/ctermid.c index 0ef9a3fe23..9714285224 100644 --- a/sysdeps/posix/ctermid.c +++ b/sysdeps/posix/ctermid.c @@ -19,17 +19,17 @@ #include <string.h> -/* Return the name of the controlling terminal. - If S is not NULL, the name is copied into it (it should be at - least L_ctermid bytes long), otherwise a static buffer is used. */ +/* Return the name of the controlling terminal. If S is not NULL, the + name is copied into it (it should be at least L_ctermid bytes + long), otherwise we return a pointer to a non-const but read-only + string literal, that POSIX states the caller must not modify. */ char * -ctermid (s) - char *s; +ctermid (char *s) { - static char name[L_ctermid]; + char *name = (char /*drop const*/ *) "/dev/tty"; if (s == NULL) - s = name; + return name; - return strcpy (s, "/dev/tty"); + return strcpy (s, name); } |