Skip to Main Content United States    
PRODUCTS SUPPORT SOLUTIONS SERVICES
COMPAQ SOFTWARE
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

1.5.4 Multiple-Version-Support Macro

By default, the header files enable APIs in the Compaq C RTL provided by the version of the operating system on which the compilation occurs. This is accomplished by the predefined setting of the __VMS_VER macro, as described in the Compaq C User's Guide for OpenVMS Systems. For example, compiling on OpenVMS Version 6.2 causes only Compaq C RTL APIs from Version 6.2 and earlier to be made available.

Another example of the use of the __VMS_VER macro is support for the 64-bit versions of Compaq C RTL functions available with OpenVMS Alpha Version 7.0 and higher. In all header files, functions that provide 64-bit support are conditionalized so that they are visible only if __VMS_VER indicates a version of OpenVMS that is greater than or equal to 7.0.

To target an older version of the operating system, do the following:

  1. Define a logical DECC$SHR to point to the old version of DECC$SHR. The compiler uses a table from DECC$SHR to perform routine name prefixing.
  2. Define __VMS_VER appropriately, either with the /DEFINE qualifier or with a combination of the #undef and #define preprocessor directives. With /DEFINE, you may need to disable the warning regarding redefinition of a predefined macro.

Targeting a newer version of the operating system might not always be possible. For some versions, you can expect that the new DECC$SHR.EXE will require new features of the operating system that are not present. For such versions, the defining if the logical DECC$SHR in Step 1 would cause the compilation to fail.

1.5.5 Compatibility Modes

The following predefined macros are used to select header-file compatibility with previous versions of DEC C) or the OpenVMS operating system:

  • _DECC_V4_SOURCE
  • _VMS_V6_SOURCE

There are two types of incompatibilities that can be controlled in the header files:

  • To conform to standards, some changes are source-code incompatible but binary compatible. To select DEC C Version 4.0 source compatibility, use the _DECC_V4_SOURCE macro.
  • Other changes to conform to standards introduce a binary or run-time incompatibility.
    In general, programs that recompile get new behaviors. In these cases, use the _VMS_V6_SOURCE feature test macro to retain previous behaviors.
    However, for the exit , kill , and wait functions, the OpenVMS Version 7.0 changes to make these routines ISO POSIX-1 compliant were considered too incompatible to become the default. Therefore, in these cases the default behavior is the same as on pre-OpenVMS Version 7.0 systems. To access the versions of these routines that comply with ISO POSIX-1, use the _POSIX_EXIT feature test macro.

The following examples help clarify the use of these macros:

  • To conform to the ISO POSIX-1 standard, typedefs for the following have been added to <types.h> :
    dev_t
    gid_t
    ino_t
    mode_t
    nlink_t
    off_t
    pid_t
    size_t
    ssize_t
    uid_t

    Previous development environments using a version of DEC C earlier than Version 5.2 may have compensated for the lack of these typedef s in <types.h> by adding them to another module. If this is the case on your system, then compiling with the <types.h> provided with DEC C Version 5.2 might cause compilation errors.
    To maintain your current environment and include the DEC C Version 5.2 <types.h> , then compile with _DECC_V4_SOURCE defined. This will omit incompatible references from the DEC C Version 5.2 headers. In <types.h> , for example, the previously listed typedefs will not be visible.
  • As of OpenVMS Version 7.0, the Compaq C RTL getuid and geteuid functions are defined to return an OpenVMS UIC (user identification code) that contains both the group and member portions of the UIC. In previous versions of the DEC C RTL, these functions returned only the member number from the UIC code.
    Note that the prototypes for getuid and geteuid in <unistd.h> (as required by the ISO POSIX-1 standard) and in <unixlib.h> (for Compaq C RTL compatibility) have not changed. By default, newly compiled programs that call getuid and geteuid get the new definitions. That is, these functions will return an OpenVMS UIC.
    To let programs retain the pre-OpenVMS Version 7.0 behavior of getuid and geteuid , compile with the _VMS_V6_SOURCE feature-test macro defined.
  • As of OpenVMS Version 7.0, the Compaq C RTL exit function is defined with ISO POSIX-1 semantics. As a result, the input status argument to exit takes a number between 0 and 255. (Prior to this, exit could take an OpenVMS condition code in its status parameter.)
    By default, the behavior for exit on OpenVMS systems is the same as before --- exit accepts an OpenVMS condition code. To enable the ISO POSIX-1 compatible exit function, compile with the _POSIX_EXIT feature-test macro defined.

1.5.6 Curses and Socket Compatibility Macros

The following feature-test macros are used to control the curses and socket subsets of the Compaq C RTL library:

  • _BSD44_CURSES
    This macro selects the curses package from the 4.4BSD Berkeley Software Distribution.
  • _VMS_CURSES
    This macro selects a curses package based on the VAX C compiler. This is the default curses package.
  • _SOCKADDR_LEN
    This macro is used to select 4.4BSD-compatible and XPG4 V2-compatible socket interfaces. These interfaces require support in your underlying TCP/IP software. Contact your TCP/IP vendor to inquire if the version of TCP/IP software you run supports 4.4BSD sockets.

Strict XPG4 V2 compliance requires the 4.4BSD-compatible socket interface. Therefore, if _XOPEN_SOURCE_EXTENDED is defined on OpenVMS Version 7.0 or higher, _SOCKADDR_LEN is defined to be 1.

The following examples help clarify the use of these macros:

  • Symbolic constants like AE, AL, AS, AM, BC, which represent pointers to termcap fields used by the BSD curses package, are only visible in <curses.h> if _BSD44_CURSES is defined.
  • The <socket.h> header file defines a 4.4BSD sockaddr structure only if _SOCKADDR_LEN or _XOPEN_SOURCE_EXTENDED is defined. Otherwise, <socket.h> defines a pre-4.4BSD sockaddr structure. If _SOCKADDR_LEN is defined and _XOPEN_SOURCE_EXTENDED is not defined,
    The <socket.h> header file also defines an osockaddr structure, which is a 4.3BSD sockaddr structure to be used for compatibility purposes. Since XPG4 V2 does not define an osockaddr structure, it is not visible in _XOPEN_SOURCE_EXTENDED mode.

1.6 Feature Logical Names

{ TBS }

1.7 32-Bit User and Group Identifiers

When supported in versions of the OpenVMS operating system, POSIX-style identifiers refers to the User Identification (UID), Group Identification (GID), and Process Group. The scope includes real and effective identifiers.

The support for POSIX-style identifiers in the Compaq C RTL requires 32-bit user and group ID support and also depends on features in the base version of OpenVMS. Currently, POSIX-style IDs are supported only by some OpenVMS versions done for specific government agencies, but will be integrated into future OpenVMS releases.

OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit UID/GID. When an application is compiled to use 32-bit UID/GID, the UID and GID are derived from the UIC as in previous versions of the operating system. In some cases, such as with the getgroups function, more information may be returned when the application supports 32-bit GIDs.

On OpenVMS Version 7.3-1, to compile an application for 32-bit UID/GID support, define the macro __USE_LONG_GID_T. To compile an application for 16-bit UID/GID support, define the macro _DECC_SHORT_GID_T.

In addition, although you cannot compile with POSIX-style IDs enabled on OpenVMS Version 7.3-1, you can run programs that were compiled with POSIX-style IDs enabled on OpenVMS systems that do provide that support.

1.8 Input and Output on OpenVMS Systems

After you learn how to link with the Compaq C RTL and call Compaq C functions and macros, you can use the Compaq C RTL for its primary purpose: input/output (I/O).

Since every system has different methods of I/O, familiarize yourself with the OpenVMS-specific methods of file access. In this way, you will be equipped to predict functional differences when porting your source program from one operating system to another.

Figure 1-2 shows the I/O methods available with the Compaq C RTL. The OpenVMS system services communicate directly with the OpenVMS operating system, so they are closest to the operating system. The OpenVMS Record Management Services (RMS) functions use the system services, which manipulate the operating system. The Compaq C Standard I/O and UNIX I/O functions and macros use the RMS functions. Since the Compaq C RTL Standard I/O and UNIX I/O functions and macros must go through several layers of function calls before the system is manipulated, they are furthest from the operating system.

Figure 1-2 I/O Interface from C Programs


The C programming language was developed on the UNIX operating system, and the Standard I/O functions were designed to provide a convenient method of I/O that would be powerful enough to be efficient for most applications, and also be portable so that the functions could be used on any system running C language compilers.

The Compaq C RTL adds functionality to this original specification. Since, as implemented in the Compaq C RTL, the Standard I/O functions recognize line terminators, the Compaq C RTL Standard I/O functions are particularly useful for text manipulation. The Compaq C RTL also implements some of the Standard I/O functions as preprocessor defined macros.

In a similar manner, the UNIX I/O functions originally were designed to provide a more direct access to the UNIX operating systems. These functions were meant to use a numeric file descriptor to represent a file. A UNIX system represents all peripheral devices as files to provide a uniform method of access.

The Compaq C RTL adds functionality to the original specification. The UNIX I/O functions, as implemented in Compaq C, are particularly useful for manipulating binary data. The Compaq C RTL also implements some of the UNIX I/O functions as preprocessor defined macros.

The Compaq C RTL includes the Standard I/O functions that should exist on all C compilers, and also the UNIX I/O functions to maintain compatibility with as many other implementations of C as possible. However, both Standard I/O and UNIX I/O use RMS to access files. To understand how the Standard I/O and UNIX I/O functions manipulate RMS formatted files, learn the fundamentals of RMS. See Section 1.8.1 for more information about Standard I/O and UNIX I/O in relationship to RMS files. For an introduction to RMS, see the Guide to OpenVMS File Applications.

Before deciding which method is appropriate for you, first ask this question: Are you concerned with UNIX compatibility or with developing code that will run solely under the OpenVMS operating system?

  • If UNIX compatibility is important, you probably want to use the highest levels of I/O---Standard I/O and UNIX I/O---because that level is largely independent of the operating system. Also, the highest level is easier to learn quickly, an important consideration if you are a new programmer.
  • If UNIX compatibility is not important to you or if you require the sophisticated file processing that the Standard I/O and UNIX I/O methods do not provide, you might find RMS desirable.

If you are writing system-level software, you may need to access the OpenVMS operating system directly through calls to system services. For example, you may need to access a user-written device driver directly through the Queue I/O Request System Service ($QIO). To do this, use the OpenVMS level of I/O; this level is recommended if you are an experienced OpenVMS programmer. For examples of programs that call OpenVMS system services, see the Compaq C User's Guide for OpenVMS Systems.

You may never use the RMS or the OpenVMS system services. The Standard I/O and UNIX I/O functions are efficient enough for a large number of applications. Figure 1-3 shows the dependency of the Standard I/O and the UNIX I/O functions on RMS, and the various methods of I/O available to you.

Figure 1-3 Mapping Standard I/O and UNIX I/O to RMS


1.8.1 RMS Record and File Formats

To understand the capabilities and the restrictions of the Standard I/O and UNIX I/O functions and macros, you need to understand VAX Record Management Services (RMS).

RMS supports the following file organizations:

  • Sequential
  • Relative
  • Indexed

Sequential files have consecutive records with no empty records in between; relative files have fixed-length cells that may or may not contain a record; and indexed files have records that contain data, carriage-control information, and keys that permit various orders of access.

The Compaq C RTL functions can access only sequential files. If you wish to use the other file organizations, you must use the RMS functions. For more information about the RMS functions, see the Compaq C User's Guide for OpenVMS Systems.

RMS is not concerned with the contents of records, but it is concerned about the record format, which is the way a record physically appears on the recording surface of the storage medium.

RMS supports the following record formats:

  • Fixed length
  • Variable length
  • Variable with fixed-length control (VFC)
  • Stream

You can specify a fixed-length record format at the time of file creation. This means that all records occupy the same amount of space in the file. You cannot change the record format once you create the file.

The length of records in variable length, VFC, and stream file formats can vary up to a maximum size that must be specified when you create the file. With variable-length record or VFC format files, the size of the record is held in a header section at the beginning of the data record. With stream files, RMS terminates the records when it encounters a specific character, such as a carriage-control or line-feed character. Stream files are useful for storing text.

RMS allows you to specify carriage-control attributes for records in a file. Such attributes include the implied carriage-return or the FORTRAN formatted records. RMS interprets these carriage controls when the file is output to a terminal, a line printer, or other device. The carriage-control information is not stored in the data records.

By default, files inherit the RMS record format, maximum record size and record attributes, from the previous version of the file, if one exists; to an OpenVMS system programmer, the inherited attributes are known as fab$b_rfm, fab$w_mrs and fab$b_rat. If no previous versions exist, the newly created file defaults to stream format with line-feed record separator and implied carriage-return attributes. (This manual refers to this type of file as a stream file.) You can manipulate stream files using the Standard I/O and the UNIX I/O functions of the Compaq C RTL. When using these files and fixed-record files with no carriage control, there is no restriction on the ability to seek to any random byte of the file using the fseek or the lseek functions. However, if the file has one of the other RMS record formats, such as variable-length record format, then these functions, due to RMS restrictions, can seek only to record boundaries. Use the default VAX stream format unless you need to create or access files to be used with other VAX languages or utilities.

1.8.2 Access to RMS Files

RMS sequential files can be opened in record mode or stream mode. By default, STREAM_LF files are opened in stream mode; all other file types are opened in record mode. When opening a file, you can override these defaults by specifying the optional argument "ctx=rec" to force record mode, or "ctx=stm" to force stream mode. RMS relative and indexed files are always opened in record mode. The access mode determines the behavior of various I/O functions in the Compaq C RTL.

One of the file types defined by RMS is an "RMS-11 stream" format file, corresponding to a value of FAB$C_STM for the record format. The definition of this format is such that the RMS record operation SYS$GET removes leading null bytes from each record. Because this file type is processed in record mode by the Compaq C RTL, it is unsuitable as a file format for binary data unless it is explicitly opened with "ctx=stm", in which case the raw bytes of data from the file are returned.

Note

In OpenVMS Version 7.0 the default LRL value on stream files was changed from 0 to 32767. This change caused significant performance degradation on certain file operations such as sort.

This is no longer a problem. The Compaq C Run-Time Library now lets you define the logical DECC$DEFAULT_LRL to change the default record-length value on stream files.

The Compaq C Run-Time Library first looks for this logical. If it is found and it translates to a numeric value between 0 and 32767, that value is used for the default LRL.

To restore the behavior prior to OpenVMS Version 7.0, enter the following command:


$ DEFINE DECC$DEFAULT_LRL 0 

1.8.2.1 Accessing RMS Files in Stream Mode

Stream access to RMS files is done with the block I/O facilities of RMS. Stream input is performed from RMS files by passing each byte of the on-disk representation of the file to your program. Stream output to RMS files is done by passing each byte from your program to the file. The Compaq C RTL performs no special processing on the data.

When opening a file in stream mode, the Compaq C RTL allocates a large internal buffer area. Data is read from the file using a single read into the buffer area and then passing the data to your program as needed. Data is written to the file when the internal buffer is full or when the fflush function is called.

1.8.2.2 Accessing RMS Record Files in Record Mode

Record access to record files is done with the record I/O facilities of RMS. The Compaq C RTL emulates a byte stream by translating carriage-control characters during the process of reading and writing records. Random access is allowed to all record files, but positioning (with fseek and lseek ) must be on a record boundary for VFC files, variable record files, or files with non-null carriage control. Positioning a record file causes all buffered input to be discarded and buffered output to be written to the file.

Record input from RMS record files is emulated by the Compaq C RTL in two steps:

  1. The Compaq C RTL reads a logical record from the file.
    If the record format is variable length with fixed control (RFM = VFC), and the record attributes are not print carriage control (RAT is not PRN), then the Compaq C RTL concatenates the fixed-control area to the beginning of the record.
  2. The Compaq C RTL expands the record to simulate a stream of bytes by translating the record's carriage-control information (if any).

In RMS terms, the Compaq C RTL translates the record's carriage-control information using one of the following methods:

  • If the record attribute is implied carriage control (RAT = CR), then the Compaq C RTL appends a new-line character to the record.
    This new-line character is considered an integral part of the record, which means for example, that it can be obtained by the fgetc function and is considered a line terminator by the fgets function. Since fgets reads the file up to the new-line character, for RAT=CR files this function cannot retrieve a string that crosses the record boundaries.
  • If the record attributes are print carriage control (RAT = PRN), then the Compaq C RTL expands and concatenates the prefix and postfix carriage controls before and after the record.
    This translation is done according to rules specified by RMS, with one exception: if the prefix character is x01 and the postfix character is x8D, then nothing is attached to the beginning of the record and a single new-line character is attached to the end of it. This is done because this prefix/postfix combination is normally used to represent a line.
  • If the record attributes are FORTRAN carriage control (RAT = FTN), then the Compaq C RTL removes the initial control byte and attaches the appropriate carriage-control characters before and after the data as defined by RMS, with the exception of the space and default carriage-control characters. In these cases, which are used to represent a line, the Compaq C RTL appends a single new-line character to the data.
    The mapping of Fortran cariage-control can be disabled by using "ctx=nocvt".
  • If the record attributes are null (RAT = NONE) and the input is coming from a terminal, then the Compaq C RTL appends the terminating character to the record. If the terminator is a carriage return or Ctrl/Z, then Compaq C translates the character to a new-line character (\n).
    If the input is coming from a nonterminal file, then the Compaq C RTL passes the record unchanged to your program with no additional prefix or postfix characters.

As you read from the file, the Compaq C RTL delivers a stream of bytes resulting from the translations. Information that is not read from an expanded record by one function call is delivered on the next input function call.

The Compaq C RTL performs record output to RMS record files in two steps.

The first part of the record output emulation is the formation of a logical record. As you write bytes to a record file, the emulator examines the information being written for record boundaries. The handling of information in the byte stream depends on the attributes of the destination file or device, as follows:

  • For all files, if the number of output bytes is greater than the internal buffer allocated by the Compaq C RTL, a record is output.
  • For files with fixed record length (RFM = FIX) or for files opened with "ctx=bin" or "ctx=xplct", a record is output only when the internal buffer is filled or when the flush function is called.
  • For files with STREAM_CR record format (RFM = STMCR), the Compaq C RTL outputs a record when it encounters a carriage-return character (\r).
  • For files with STREAM record format (RFM = STM) the Compaq C RTL outputs a record when it encounters a new-line (\n), form feed (\f), or vertical tab (\v) character.
  • For all other file types, the Compaq C RTL outputs a record when it encounters a new-line (\n) character.

The second part of record output emulation is to write the logical record formed during the first step. The Compaq C RTL forms the output record as follows:

  • If the record attribute is carriage control (R AT = CR), and if the logical record ends with a new-line character (\n), the Compaq C RTL drops the new-line character and writes the logical record with implied carriage control.
  • If the record attribute is print carriage control (RAT = PRN), then the Compaq C RTL writes the record with print carriage control according to the rules specified by RMS. If the logical record ends with a single new-line character (\n), the Compaq C RTL maps the new-line character to an x01 prefix and x8D postfix character. This is the reverse of the translation for record input files with print carriage-control attributes.
  • If the record attributes are Fortran carriage control (RAT = FTN), then the Compaq C RTL removes any prefix and/or postfix carriage control characters and concatenates a single carriage control byte to the beginning of the record as defined by RMS, with one exception: If the output record ends in a new-line character (\n), the Compaq C RTL will remove the new-line and use the space carriage control byte. This is the reverse of the translation for record input files with Fortran carriage-control attributes.
    The mapping of Fortran cariage-control can be disabled by using "ctx=nocvt".
  • If the logical record is to be written to a terminal device and the last character of the record is a new-line character (\n) the Compaq C RTL replaces the new-line character with a carriage-return (\r), and attaches a line-feed character (\n) to the front of the record. The Compaq C RTL then writes out the record with no carriage control.
  • If the output file record format is variable length with fixed control (RFM = VFC), and the record attributes do not include print carriage control (RAT is not PRN), then the Compaq C RTL takes the beginning of the logical record to be the fixed-control header, and reduces the number of bytes written out by the length of the header. These bytes are then used to construct the fixed-control header. If there are too few bytes in the logical record, an error is signaled.


Previous Next Contents Index
Buy Online or Call 1.800.888.0220      privacy statement and legal notices 
STORES CONTACT US SEARCH PRODUCTS SOLUTIONS OPTIONS DEVELOPERS