3.9 Return Status Values

The status values from OpenVMS system service procedures are returned in general register R0. This return status value indicates the success or failure of the operation performed by the called procedure. In DEC C, passing a return status value in R0 is equivalent to a function returning int.

To obtain a return status value from any system procedure, declare the procedure as a function, as shown in the following example:

int  SYS$SETEF();

After declaring a procedure in this way, you can invoke the procedure as a function and obtain a return status value. In DEC C, such a declaration is needed only as program documentation; SYS$SETEF can be called without explicit declaration and will be interpreted by default as a function returning int.

This section describes the following topics:

3.9.1 Format of Return Status Values

All OpenVMS system procedures and programs use a longword value to communicate return status information. When a DEC C main function executing under the control of the DCL interpreter executes a return statement to return control to the command level, the command interpreter uses the return status value to conditionally display a message on the current output device.

To provide a unique means of identifying every return condition in the system, bit fields within the value are defined as shown in Figure 3-5.

Figure 3-5 Bit Fields Within a Return Status Value

The following list describes the division of this bit field:

control bits (31-28)
Define special action(s) to be taken. At present, only bit 28 is used. When set, it inhibits the printing of the message associated with the return status value at image exit. Bits 29 through 31 are reserved for future use by Digital and must be 0.
facility number (27-16)
A unique value assigned to the system component, or facility, that is returning the status value. Within this field, bit 27 has a special significance. If bit 27 is clear, the facility is a Digital facility: the remaining value in the facility number field is a number assigned by the operating system. If bit 27 is set, the number indicates a customer-defined facility.
message number (15-3)
An identification number that specifically describes the return status or condition. Within this field, bit 15 has a special significance. If bit 15 is set, the message number is unique to the facility issuing the message. If bit 15 is clear, the message is issued by more than one system facility.
severity (2-0)
A numeric value indicating the severity of the return status. Table 3-13 shows the possible values in these three bits, and their meanings.

Table 3-13 Possible Severity Values

Value  Meaning 
Warning 
Success 
Error 
Informational 
Severe error, FATAL 
5-7  Reserved 

Odd values indicate success (an informational condition is considered a successful status) and even values indicate failures (a warning is considered an unsuccessful status).

The following names are associated with these fields:
control bits bit 28 (inhibit message)  CONTROLINHIB_MSG  
facility number bit 27 (customer facility)  FAC_NOCUST_DEF  
message number bit 15 (facility specific)  MSG_NOFAC_SP  
severity bit 0 (success)  SEVERITYSUCCESS 

When testing return values in a DEC C program, either you can test only for successful completion of a procedure or you can test for specific return status values.

3.9.2 Manipulating Return Status Values

You can construct a structure or union that describes a return status value, but this method of manipulating return status values is not recommended. A status value is usually constructed or checked using bitwise operators. DEC C provides the <stsdef.h> header file, which contains preprocessor definitions to make this job easier. All the preprocessor symbols are named according to the following OpenVMS naming convention:

STS$type_name
STS
Identifies standard return status values.
type
One of the following characters denoting the type of the constant:
Represents a constant value  
Represents a bit mask  
Represents the bit size of a field  
Defines the bit offset to the field  
name
An abbreviation for the field name.

For example, the following constants are defined in <stsdef.h> for the facility number field, FAC_NO, which spans bits 16 through 27:

                                   /*  Size of field in bits   */
#define STS$S_FAC_NO  12

                                   /*  Bit offset to the       *
                                    *   beginning of the field */
#define STS$V_FAC_NO   16

                                   /*  Bit mask of the field   */
#define STS$M_FAC_NO   0xFFF0000

Figure 3-6 shows how the status value is represented internally.

Figure 3-6 Internal Representation of a Status Value

Use the following expression to extract the facility number from a particular status value contained in the variable named status:

(status & STS$M_FAC_NO) >> STS$V_FAC_NO

In the previous example, the parentheses are required for the expression to be evaluated properly; the relative precedence of the bitwise AND operator (&) is lower than the precedence of the binary shift operator (>>).

3.9.3 Testing for Success or Failure

To test a return status value for success or failure, you need only test the success bit. A value of true in this bit indicates that the return value is a successful value.

Example 3-21 shows a program that checks the success bit.

Example 3-21 Testing for Success

/*  This program shows how to test the success bit.            */

#include <stdio.h>
#include <descrip.h>
#include <stsdef.h>

#include <starlet.h>
#include <stdlib.h>

int main(void)
{
   int  status;
   $DESCRIPTOR(name, "student");

   status = sys$setprn(&name);

   if (status & STS$M_SUCCESS)
                                   /*  Success code            */
        fprintf(stderr, "Successful completion");

   else
                                   /*  Failure code            */

      fprintf(stderr, "Failed to set process name.\n");
   exit(status);

}

The failure code in Example 3-21 causes the printing of a program-specific message indicating the condition that caused the program to terminate. The error status is passed to the DCL by the exit function, which then interprets the status value.

3.9.4 Testing for Specific Return Status Values

Each numeric return status value defined by the system has a symbolic name associated with it. The names of these values are defined as system global symbols, and you can access their values by referring to their symbolic names.

The global symbol names for OpenVMS return status values have the following format:

facility$_code
facility
An abbreviation or acronym for the system facility that defined the global symbol.
code
A mnemonic for the specific status value.

Table 3-14 shows some examples of facility codes used in global symbol names.

Table 3-14 Facility Codes

Facility  Description 
SS  System services; these status codes are listed in the OpenVMS System Services Reference Manual.  
RMS  File system procedures; these status codes are listed in the OpenVMS Record Management Services Reference Manual.  
SOR  SORT procedures; these status codes are listed in the VMS Sort/Merge Utility Manual

The definitions of the global symbol names for the facilities listed are located in the default DEC C object module libraries, so they are automatically located when you link a DEC C program that references them.

When you write a DEC C program that calls system procedures and you want to test for specific return status values using the symbol names, you must perform the following tasks:

  1. Determine, from the documentation of the procedure, the status values that can be returned, and choose the values for which you want to provide specific tests.

  2. Declare the symbolic name for each value of interest. The <ssdef.h> and <rmsdef.h> header files define the system service and RMS return status values, respectively. If you are checking return status values from other facilities, such as the SORT utility, you must explicitly declare the return values as globalvalue int. Consider the following example:
    globalvalue  int  SOR$_OPENIN;
    

  3. Reference the symbols in your program.

Example 3-22 shows a program that checks for specific return status values defined in the <ssdef.h> header file.

Example 3-22 Testing for Specific Return Status Values

/*  This program checks for specific return status values.     */

#include <ssdef.h>
#include <stdio.h>
#include <descrip.h>

$DESCRIPTOR(message,"\07**Lunch_time**\07");

int main(void)
{

   int status =  SYS$BRDCST(&message,0);

   if (status != SS$_NORMAL)
      {
         if (status == SS$_NOPRIV)
            fprintf(stderr, "Can't broadcast; requires OPER \
privilege.");

         else
            fprintf(stderr, "Can't broadcast; some fatal \
error.");

         exit(status);
      }
}


Previous Page | Next Page | Table of Contents | Index