ttyname (BPX1TYN, BPX4TYN) (POSIX version) — Get the name of a terminal

Function

The ttyname callable service obtains the pathname of the terminal that is associated with the file descriptor.

Requirements

Operation Environment
Authorization: Supervisor or problem state, any PSW key
Dispatchable unit mode: Task
Cross memory mode: PASN = HASN
AMODE (BPX1TYN): 31-bit
AMODE (BPX4TYN): 64-bit
ASC mode: Primary mode
Interrupt status: Enabled for interrupts
Locks: Unlocked
Control parameters: All parameters must be addressable by the caller and in the primary address space.

Format

CALL BPX1TYN,(File_descriptor,
              Terminal_name_length,
              Terminal_name)

AMODE 64 callers use BPX4TYN with the same parameters.

Parameters

File_descriptor
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a fullword that contains the file descriptor.

Terminal_name_length
Parameter supplied and returned
Type:
Integer
Length:
Fullword

The name of a fullword that contains the size, in bytes, of the buffer that is referred to by Terminal_name. The size of this field should be less than 4096 bytes (4KB) in length. The size of the buffer that is specified should be the maximum length that the terminal_name could be on output.

Terminal_name
Returned parameter
Type:
Character string
Character set:
No restriction
Length:
Specified by the Terminal_name_length parameter

The name of an area to which ttyname returns either the pathname of the terminal, terminated by a X'00', or a single byte of X'00' (null string), if the file descriptor is not valid or does not represent a terminal.

The length of Terminal_name should be 1024 bytes long (PATH_MAX+1), unless the pathname is known to be shorter.

Usage notes

  1. This service does not return -1 to indicate a failure. If the file descriptor is incorrect, it returns a null string.
  2. If Terminal_name is an area smaller than the actual pathname of the terminal, the name is truncated.

Related services

Characteristics and restrictions

There are no restrictions on the use of the ttyname service.

Examples

For an example using this callable service, see BPX1TYN (ttyname) example.