ptsname man page

ptsname, ptsname_r — get the name of the slave pseudoterminal


#include <stdlib.h>

char *ptsname(int fd);
int ptsname_r(int fd, char *buf, size_t buflen);

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):


Since glibc 2.24:
   _XOPEN_SOURCE >= 500 ||
Glibc 2.23 and earlier:



The ptsname() function returns the name of the slave pseudoterminal device corresponding to the master referred to by fd.

The ptsname_r() function is the reentrant equivalent of ptsname(). It returns the name of the slave pseudoterminal device as a null-terminated string in the buffer pointed to by buf. The buflen argument specifies the number of bytes available in buf.

Return Value

On success, ptsname() returns a pointer to a string in static storage which will be overwritten by subsequent calls. This pointer must not be freed. On failure, NULL is returned.

On success, ptsname_r() returns 0. On failure, a nonzero value is returned and errno is set to indicate the error.



(ptsname_r() only) buf is NULL. (This error is returned only for glibc 2.25 and earlier.)


fd does not refer to a pseudoterminal master device.


(ptsname_r() only) buf is too small.


ptsname() is provided in glibc since version 2.1.


For an explanation of the terms used in this section, see attributes(7).

ptsname()Thread safetyMT-Unsafe race:ptsname
ptsname_r()Thread safetyMT-Safe

Conforming to

POSIX.1-2001, POSIX.1-2008.

ptsname() is part of the UNIX 98 pseudoterminal support (see pts(4)).

ptsname_r() is a Linux extension, that is proposed for inclusion in the next major revision of POSIX.1 (Issue 8). A version of this function is documented on Tru64 and HP-UX, but on those implementations, -1 is returned on error, with errno set to indicate the error. Avoid using this function in portable programs.

See Also

grantpt(3), posix_openpt(3), ttyname(3), unlockpt(3), pts(4), pty(7)


This page is part of release 5.04 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at

Referenced By

getpt(3), grantpt(3), ioctl_tty(2), posix_openpt(3), pts(4), pty(7), unlockpt(3).

The man page ptsname_r(3) is an alias of ptsname(3).

2017-09-15 Linux Programmer's Manual