Chapter Contents

Previous

Next
Developing Applications for Use with UNIX System Services OS/390

File Access

SAS/C POSIX applications can access either HFS files or OS/390 data sets from the USS shell. This section describes how this is accomplished. For detailed information about file access and input/output considerations, refer to Chapter 3, "I/O Functions," in the SAS/C Library Reference, Volume 1. Also refer to the MVS/ESA OpenEdition MVS User's Guide (SC23-3013-01) for general information about file access and USS.


Hierarchical File System (HFS) Files

The USS Hierarchical File System (HFS) is patterned after the UNIX file system. All files are located in directories, and the directories are organized in a hierarchical manner with each directory being a subdirectory to another directory until you reach the root directory.

When you start a shell session, a process is created. Each process maintains a location in the HFS. This location is called the working directory. The initial working directory you are placed in when you start a shell session is called your home directory. You can use the USS shell command cd to change the current working directory location for the shell.

Pathnames are used to specify the location of files within the directory structure. A pathname starts with the root directory and works its way down the directory hierarchy, separating each directory name with a single slash (/), until you come to the name of the file. For example, the following pathname specifies a file named qsort.c located in the src subdirectory of the userxyz directory.

/u/userxyz/src/qsort.c

Notice that the userxyz directory is a subdirectory of the u directory, which is located in the root directory. The root directory is signified by the single slash (/) at the beginning of the pathname. This type of pathname, which shows the complete path from the root directory to the file, is called an absolute pathname.

There is a second type of pathname, called a relative pathname, that specifies a path relative to your current working directory. To specify a relative pathname for a file, simply enter the pathname to the file from your current location in the HFS. For example, if the current working directory is userxyz , the qsort.c file could specified as follows:

src/qsort.c

Notice that the beginning slash (/) is not used in a relative pathname.

The following special fields can also be used when specifying a relative pathname:
. is used to specify the current directory.
.. is used to specify the parent directory.

For example, we could have specified the qsort.c file from the userxyz directory in either of the following ways:

./src/qsort.c
../userxyz/src/qsort.c

To put all this in the context of a SAS/C program, we could open the scrambled.txt file from our qsort.c program with any of the following statements, provided the current working directory is /u/userxyz/src .

datafile = fopen("./scrambled.txt", O_RDWR);

datafile = fopen("../scrambled.txt", O_RDWR);

datafile = fopen("../src/scrambled.txt", O_RDWR);

We could also use the following absolute pathname to specify the scrambled.txt file:

datafile = open("./scrambled.txt", O_RDWR);

Note:    The exact format of the filename specification depends upon whether or not the posix option was used at compile time.  [cautionend]

In this case the scramble.txt file will be found no matter where the working directory is when the program is executed.


OS/390 Data Sets

OS/390 data sets can also be accessed from an exec -linkage program running under the USS shell. If a // precedes a filename, the filename is assumed to be either of the tso styles. For example, the following statement could be used to reference a PDS member from the shell:

datafile = fopen("//scramble.text(eggnog)", "r+");

In an exec -linkage program compiled with the posix option, you must precede the filename with // even if you are using a style prefix such as tso: . If the filename does not begin with exactly two slashes, it will be interpreted as an HFS file. For example, the following statement will attempt to open the file named tso:scramble.text(eggnog) in the current working directory of the HFS:

datafile = fopen("tso:scramble.text(eggnog)", "r+");

Obviously, this is not the desired result. To correctly open the userid.scramble.text(eggnog) PDS member, you must precede the tso: with two slashes.

Note:    This convention of using two slashes to access OS/390 data sets or CMS files from your exec -linkage programs cannot be used with USS shell commands. For example, you cannot use // to concatenate a PDS member with an HFS file using the cat command.  [cautionend]


Accessing the Transient Library

In an ordinary (batch/TSO) OS/390 environment, SAS/C Library routines needed at runtime are loaded from the transient library. This library is located in one of three ways: it may be allocated to a STEPLIB (or tasklib) data set, it may be allocated to the DDname CTRANS, or it may reside in linklist/LPALIB.

When an application is called by the shell (or, more generally, invoked by the POSIX exec system call), it runs in an address space that has no preallocated DD statements. This creates problems for transient library access under the shell. The SAS/C Library solves this problem as follows:

  1. If the environment variable ddn_CTRANS is defined when a SAS/C program begins execution, the value of the variable is assumed to be an OS/390 data set name, which is dynamically allocated to the DDname CTRANS.

  2. When a SAS/C program running with an allocated CTRANS calls the fork function, the same file is allocated to CTRANS in the child before fork returns.

  3. When a SAS/C program running with an allocated CTRANS performs an exec , the environment variable ddn_CTRANS is generated to contain the name of the CTRANS data set, unless this variable already exists. This variable is passed to the called program, so that if it is a SAS/C compiled program, it will have access to the same CTRANS data set.

When a program is linked with the all-resident library, it normally does not access CTRANS; however, if such a program issues an exec call, the CTRANS data set name is still recorded in the ddn_CTRANS environment variable, since the called program might require transient library access.

It is recommended that you update /etc/profile so that ddn_CTRANS is set to an appropriate value automatically whenever the shell starts up.

USS supports a feature similar to the SAS/C CTRANS support for STEPLIB data sets, using the environment variable STEPLIB. If the value of STEPLIB is CURRENT, an existing STEPLIB data set is propagated on exec . Alternately, STEPLIB may name one or more data sets to be allocated to STEPLIB in the new address space. This support will also work for access to the SAS/C Transient Library.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.