summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/ttyname.3
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2005-05-13 16:27:30 +0000
committerdelphij <delphij@FreeBSD.org>2005-05-13 16:27:30 +0000
commit4c5083a81ce14f96f4193b746c54f7e17d94e21b (patch)
tree4f6f760d66637df39c7d6d860807b7c5aeb6bf2e /lib/libc/gen/ttyname.3
parent1a9b6b826f2931676b4a4a507bd8120dee017699 (diff)
downloadFreeBSD-src-4c5083a81ce14f96f4193b746c54f7e17d94e21b.zip
FreeBSD-src-4c5083a81ce14f96f4193b746c54f7e17d94e21b.tar.gz
Provide more POSIX-complaint ttyname_r(3) interface[1], which is slightly
different from what has been offered in libc_r (the one spotted in the original PR which is found in libthr has already been removed by David's commit, which is rev. 1.44 of lib/libthr/thread/thr_private.h): - Use POSIX standard prototype for ttyname_r, which is, int ttyname_r(int, char *, size_t); Instead of: char *ttyname_r(int, char *, size_t); This is to conform IEEE Std 1003.1, 2004 Edition [1]. - Since we need to use standard errno for return code, include errno.h in ttyname.c - Update ttyname(3) implementation according to reflect the API change. - Document new ttyname_r(3) behavior - Since we already make use of a thread local storage for ttyname(3), remove the BUGS section. - Remove conflicting ttyname_r related declarations found in libc_r. Hopefully this change should not have changed the API/ABI, as the ttyname_r symbol was never introduced before the last unistd.h change which happens a couple of days before. [1] http://www.opengroup.org/onlinepubs/009695399/functions/ttyname.html Requested by: Tom McLaughlin <tmclaugh sdf lonestar org> Through PR: threads/76938 Patched by: Craig Rodrigues <rodrigc crodrigues org> (with minor changes) Prompted by: mezz@
Diffstat (limited to 'lib/libc/gen/ttyname.3')
-rw-r--r--lib/libc/gen/ttyname.337
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/libc/gen/ttyname.3 b/lib/libc/gen/ttyname.3
index dcea14a..db67314 100644
--- a/lib/libc/gen/ttyname.3
+++ b/lib/libc/gen/ttyname.3
@@ -32,11 +32,12 @@
.\" @(#)ttyname.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd May 14, 2005
.Dt TTYNAME 3
.Os
.Sh NAME
.Nm ttyname ,
+.Nm ttyname_r ,
.Nm isatty ,
.Nm ttyslot
.Nd get name of associated terminal (tty) from file descriptor
@@ -46,7 +47,7 @@
.In unistd.h
.Ft char *
.Fn ttyname "int fd"
-.Ft char *
+.Ft int
.Fn ttyname_r "int fd" "char *buf" "size_t len"
.Ft int
.Fn isatty "int fd"
@@ -82,7 +83,13 @@ function
gets the related device name of
a file descriptor for which
.Fn isatty
-is true
+is true.
+.Pp
+.Fn ttyname
+returns the name stored in a static buffer which will be overwritten
+on subsequent calls.
+.Fn ttyname_r
+takes a buffer and length as arguments to avoid this problem.
.Pp
The
.Fn ttyslot
@@ -100,12 +107,25 @@ is true; otherwise
a
.Dv NULL
pointer is returned.
+The
+.Fn ttyname_r
+function returns 0 if successful. Otherwise an error number is returned.
.Pp
The
.Fn ttyslot
function
returns the unit number of the device file if found; otherwise
the value zero is returned.
+.Sh ERRORS
+.Fn ttyname_r
+may return the following error codes:
+.Bl -tag -width Er
+.It Bq Er ENOTTY
+.Fa fd
+is not a valid file descriptor.
+.It Bq Er ERANGE
+.Fa bufsize
+is smaller than the length of the string to be returned.
.Sh FILES
.Bl -tag -width /etc/ttys -compact
.It Pa /dev/\(**
@@ -123,11 +143,6 @@ and
function
appeared in
.At v7 .
-.Sh BUGS
-The
-.Fn ttyname
-function leaves its result in an internal static object and returns
-a pointer to that object.
-Subsequent calls to
-.Fn ttyname
-will modify the same object.
+.Fn ttyname_r
+appeared in
+.Fx 6.0 .
OpenPOWER on IntegriCloud