![]() Chapter Contents |
![]() Previous |
![]() Next |
| SAS/C C++ Development System User's Guide, Release 6.50 |
Many C++ programs
were developed
under UNIX operating systems, which are where the first C++ translators were
available. Unfortunately, I/O is very different under MVS and CMS than under
UNIX. This may require you to make some changes to existing C++ applications
to adapt to the mainframe environment. This section discusses some of these
issues. For a more detailed discussion of the differences
between 370 I/O and traditional UNIX I/O, and of portable I/O coding techniques,
see the SAS/C Library Reference, Volume 1.
Under UNIX and some other operating systems, files are stored as sequences of characters, and the newline character serves to separate one line from the next. Under MVS and CMS, files are stored as sequences of records, separated by gaps (which do not contain any characters). Files in such systems therefore support two forms of access: text and binary. When a file is accessed in binary mode, only the characters are accessed and information about lines or records is lost. When a file is accessed in text mode, record gaps are treated as if they contained a newline character. That is, a newline is inserted at the end of each record on input, and writing a newline on output causes a record gap to be generated, but no physical character is written.
Text access is generally more suitable for programs that need to be aware of line boundaries, while binary access is suitable for programs that must read or write data exactly as specified. (For example, a program that writes an object deck must use binary access, to keep newlines in the object deck from being translated to record gaps.)
When a stream is associated with an external file, the default access
mode is text. You can specify
ios::binary
in the open mode if you need binary access, as in the
following statement:
ostream object("tso:fred.obj",
ios::out|ios::binary);
|
Mainframe systems offer several unique ways of naming files, most of which bear little resemblance to traditional MYFILE.TXT style filenames found under UNIX. The general form of a file name is
| style:name |
where style is a code describing how the rest of the name
is to be interpreted. The style: portion of a filename can be
omitted, in which case a default is assumed.
Under MVS, the following filename styles are supported:
tso
: style names most closely resemble
typical filenames under UNIX systems.Under CMS, the following filename styles are supported:
char*
variable named
_style
. For
example, the following statement specifies that by default all filenames are
to be interpreted as
tso:
style names:
char *_style = "tso:"; |
To successfully and efficiently use a file on
IBM 370
systems, it is often necessary to provide information about actual or desired
file attributes in addition to the filename. For example, when you create
a new file under MVS, it may be necessary to specify the file size and how
large the records are to be. File attributes of this sort are specified via amparms, which are keyword parameters
defined by the SAS/C library. Amparms can be specified as a third argument
to an
fstream
constructor or
open()
member function. For example,
the following statements specify that the DDname SYSLIN should define a file
with fixed-length 80-byte records, grouped into blocks of 3,200 characters:
ostream objfile;
objfile.open("syslin", ios::out|ios::binary,
"recfm=f,reclen=80,blksize=3200");
|
An additional optional argument to stream constructors and
open()
member
functions is an access method name. For instance, the following statement
defines an
iostream
processed by the "rel" access method.
iostream work("dsn:&wkfile",
ios::out|ios:binary,
"alcunit=cyl,space=5","rel");
|
See the SAS/C Library Reference, Volume 1 for a discussion
of the meaning and utility of specifying an access method.
Under UNIX systems, it is generally possible to reposition any file to a particular character, for example, the 10,000th character. Due to the inner workings of mainframe I/O, this is generally not possible under MVS or CMS. One exception is for files accessed for binary access, using the "rel" access method. These files can be freely positioned to particular characters in a way compatible with UNIX systems.
The streams library defines two different types to deal with file positioning,
streampos
and
streamoff
. The streampos type is used to hold file
positions, while
streamoff
is used to hold offsets of one point
in a file from another.
In UNIX implementations of C++, both
streampos
and
streamoff
are integral types and both may be used freely with any file. However, in
the SAS/C implementation, only
streamoff
is an integral type. Further,
streamoff
can only be used for files that behave like UNIX files,
namely, those opened for binary access using the "rel" access method.
streampos
is a nonintegral type that encodes a file position in a system-dependent
manner. You can use the
tellg()
and
tellp()
member functions to obtain
a
streampos
for a particular
point in the file, and you can use the
seekg()
and
seekp()
functions
to position to a point whose location has previously been determined. Because
no arithmetic or other operations are defined on
streampos
values, more general positioning
operations such as seeking 10,000 characters past a specific location in the
file are not supported.
370 I/O is not based on file descriptors. For this reason, member functions
such as
fd()
and
attach()
are not meaningful in the IBM 370 environment
and are not supported. Similarly, UNIX protection modes are not meaningful
to MVS or CMS and constructors or
open()
calls that specify a protection
mode will be rejected at compile time.
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © Tue Feb 10 12:11:23 EST 1998 by SAS Institute Inc., Cary, NC, USA. All rights reserved.