chdir (BPX1CHD, BPX4CHD) — Change the working directory

Function

The chdir service changes your working directory from the current one to a new one. The working directory is the starting point for path searches of pathnames that do not begin with a slash.

Requirements

Operation Environment
Authorization: Supervisor state or problem state, any PSW key
Dispatchable unit mode: Task
Cross memory mode: PASN = HASN
AMODE (BPX1CHD): 31-bit
AMODE (BPX4CHD): 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 BPX1CHD,(Pathname_length,
              Pathname,
              Return_value,
              Return_code,
              Reason_code)

AMODE 64 callers use BPX4CHD with the same parameters.

Parameters

Pathname_length
Supplied parameter
Type:
Integer
Length:
Fullword

The name of a fullword that contains the length of the pathname of the directory that is to become your new working directory.

Pathname
Supplied parameter
Type:
Character string
Character set:
No restriction
Length:
Specified by the Pathname_length parameter

The name of a field that contains the pathname of the new directory. This field has the length specified in Pathname_length.

Pathnames can begin with or without a slash:
  • A pathname that begins with a slash is an absolute pathname. The slash refers to the root directory, and the search for the file starts at the root directory.
  • A pathname that does not begin with a slash is a relative pathname. The search for the file starts at the working directory.
Return_value
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the chdir service returns 0 if the request is successful, or -1 if it is not successful.

Return_code
Returned parameter
Type:
Integer
Length:
Fullword
The name of a fullword in which the chdir service stores the return code. The chdir service returns Return_code only if Return_value is -1. See z/OS UNIX System Services Messages and Codes for a complete list of possible return code values. The chdir service can return one of the following values in the Return_code parameter:
Return_code Explanation
EACCES The calling process does not have permission to search one of the components of Pathname.
EINVAL The Pathname parameter is not valid; it contains nulls.
ELOOP A loop exists in symbolic links that were encountered during resolution of the Pathname argument. This error is issued if more than 24 symbolic links are detected in the resolution of Pathname.
ENAMETOOLONG Pathname is longer than 1023 characters, or a component of Pathname is longer than 255 characters. Name truncation is not supported.
ENOENT No directory named Pathname was found, or no Pathname was specified. The following reason codes can accompany the return code: JRChdNoEnt and JRQuiescing.
ENOTDIR Some component of Pathname is not a directory. The following reason code can accompany the return code: JRChdNotDir.
Reason_code
Returned parameter
Type:
Integer
Length:
Fullword

The name of a fullword in which the chdir service stores the reason code. The chdir service returns a Reason_code only if Return_value is -1. Reason_code further qualifies the Return_code value. See z/OS UNIX System Services Messages and Codes for the reason codes.

Related services

Characteristics and restrictions

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

Examples

For an example using this callable service, see BPX1CHD (chdir) example.