1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Determine name of a terminal.
5 Copyright (C) 2010-2014 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
31 ttyname_r (int fd, char *buf, size_t buflen)
34 /* When ttyname_r exists, use it. */
36 /* This code is multithread-safe. */
37 /* On Solaris, ttyname_r always fails if buflen < 128. On OSF/1 5.1,
38 ttyname_r ignores the buffer size and assumes the buffer is large enough.
39 So provide a buffer that is large enough. */
41 # if HAVE_POSIXDECL_TTYNAME_R
43 (buflen < sizeof (largerbuf)
44 ? ttyname_r (fd, largerbuf, sizeof (largerbuf))
45 : ttyname_r (fd, buf, buflen <= INT_MAX ? buflen : INT_MAX));
48 if (buflen < sizeof (largerbuf))
50 size_t namelen = strlen (largerbuf) + 1;
53 memcpy (buf, largerbuf, namelen);
57 (buflen < sizeof (largerbuf)
58 ? ttyname_r (fd, largerbuf, sizeof (largerbuf))
59 : ttyname_r (fd, buf, buflen <= INT_MAX ? buflen : INT_MAX));
64 size_t namelen = strlen (name) + 1;
67 memmove (buf, name, namelen);
72 /* Note: This is not multithread-safe. */
79 namelen = strlen (name) + 1;
82 memcpy (buf, name, namelen);
85 /* Platforms like mingw: no ttys exist at all. */