HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

1.4.9 Standard-Compliant stat Structure (INTEGRITY SERVERS, ALPHA)

The C RTL supports an X/Open standard-compliant definition of the stat structure and associated definitions. To use these new definitions, applications must compile with the _USE_STD_STAT feature-test macro defined. Use of _USE_STD_STAT specifies long (32-bit) GIDs.

When compiled with _USE_STD_STAT, the stat structure includes these changes:

1.4.10 Using Legacy _toupper and _tolower Behavior (INTEGRITY SERVERS, ALPHA)

As of OpenVMS Version 8.3, to comply with the C99 ANSI standard and X/Open Specification, the _tolower and _toupper macros by default do not evaluate their parameter more than once. They simply call their respective tolower or toupper function. This avoids side effects (such as i++ or function calls) where the user can tell how many times an expression is evaluated.

To retain the older, optimized behavior of the _tolower and _toupper macros, compile with /DEFINE=_FAST_TOUPPER. Then, as in previous releases, these macros optimize the call to avoid the overhead of a runtime call. However, the macro's parameter is evaluated more than once to determine how to calculate the result, possibly creating unwanted side effects.

1.4.11 Using Faster, Inlined Put and Get Functions (INTEGRITY SERVERS, ALPHA)

Compiling with the __UNIX_PUTC macro defined enables an optimization that sets the following I/O functions to use faster, inlined functions:


fgetc 
fputc 
putc 
putchar 
fgetc_unlocked 
fputc_unlocked 
putc_unlocked 
putchar_unlocked 

1.4.12 POSIX Style exit (INTEGRITY SERVERS, ALPHA)

The HP C and C++ Version 7.1 and higher compilers have a /MAIN=POSIX_EXIT qualifier that defines the _POSIX_EXIT macro and causes the main program to call __posix_exit instead of exit when returning from the main program.

This qualifier should be used with programs ported from UNIX that do not explicitly call exit and do not use OpenVMS specific exit codes.

For older compilers, the following sample code can be used to force the existing main module to have a different name so that a simple main program will call it but force the exit status to be through the __posix_exit call.

The replacement main function can be in a different module, so that /DEFINE="main=real_main" is all that is needed for modifying the build of the existing main function.


#define _POSIX_EXIT 1 
 
#include <stdlib.h> 
 
int real_main(int argc, char **argv); 
 
/* Make sure POSIXized exit is used */ 
int main(int argc, char **argv) 
{ 
int ret_status; 
 
   ret_status = real_main(argc, argv); 
 
exit (ret_status); 
} 
#define main real_main 

Unless your C program is intentionally using OpenVMS status codes for exit values, it is strongly recommended that both the _POSIX_EXIT macro be defined and, if needed, the /MAIN=POSIX_EXIT or the alternative main replacement be used so that DCL, BASH, and the accounting file get usable exit values.

1.5 Enabling C RTL Features Using Feature Logical Names

The C RTL provides an extensive list of feature switches that can be set using DECC$ logical names. These switches affect the behavior of a C application at run time.

The feature switches introduce new behaviors and also preserve old behaviors that have been deprecated.

You enable most features by setting a logical name to ENABLE and disable a feature by setting the logical name to DISABLE:


$ DEFINE DECC$feature ENABLE 
 
$ DEFINE DECC$feature DISABLE 

Some feature logical names can be set to a numeric value. For example:


$ DEFINE DECC$PIPE_BUFFER_SIZE 32768 

Notes

  • Do not set C RTL feature logical names for the system. Set them only for the applications that need them, because other applications including OpenVMS components depend on the default behavior of these logical names.
  • Older feature logicals from earlier releases of the C Run-Time Library were documented as supplying "any equivalence string" to enable a feature. While this was true at one time, we now strongly recommend that you use ENABLE for setting these feature logicals and DISABLE for disabling them. Failure to do so may produce unexpected results.

    The reason for this is twofold:
    • In previous versions of the C RTL, any equivalence string, even DISABLE, may have enabled a feature logical.
    • In subsequent and current versions of the C RTL, the following equivalence strings will disable a feature logical. Do not use them to enable a feature logical.
      DISABLE
      0 (zero)
      F
      FALSE
      N
      NO


      Any other string not on this list will enable a feature logical. The unintentionally misspelled string "DSABLE", for example, will enable a feature logical.

The C RTL also provides several functions to manage feature logicals within your applications:


decc$feature_get 
decc$feature_get_value 
decc$feature_get_index 
decc$feature_get_name 
decc$feature_set 
decc$feature_set_value 
decc$feature_show 
decc$feature_show_all 

See the reference section for more information on these functions.

Table 1-4 lists the C RTL feature logical names, grouped by the type of features they control.

Table 1-4 C RTL Feature Logical Names
Feature Logical Name Default
Performance Optimizations
DECC$ENABLE_GETENV_CACHE DISABLE
DECC$LOCALE_CACHE_SIZE 0
DECC$TZ_CACHE_SIZE 2
Legacy Behaviors
DECC$ALLOW_UNPRIVILEGED_NICE DISABLE
DECC$NO_ROOTED_SEARCH_LISTS DISABLE
DECC$PRINTF_USES_VAX_ROUND DISABLE
DECC$THREAD_DATA_AST_SAFE DISABLE
DECC$V62_RECORD_GENERATION DISABLE
DECC$WRITE_SHORT_RECORDS DISABLE
DECC$XPG4_STRPTIME DISABLE
File Attributes
DECC$DEFAULT_LRL 32767
DECC$DEFAULT_UDF_RECORD DISABLE
DECC$FIXED_LENGTH_SEEK_TO_EOF DISABLE
DECC$ACL_ACCESS_CHECK DISABLE
Mailboxes
DECC$MAILBOX_CTX_STM DISABLE
Changes for UNIX Conformance
DECC$SELECT_IGNORES_INVALID_FD DISABLE
DECC$STRTOL_ERANGE DISABLE
DECC$VALIDATE_SIGNAL_IN_KILL DISABLE
General UNIX Enhancements
DECC$UNIX_LEVEL DISABLE
DECC$ARGV_PARSE_STYLE DISABLE
DECC$PIPE_BUFFER_SIZE 512
DECC$PIPE_BUFFER_QUOTA 512
DECC$STREAM_PIPE DISABLE
DECC$POPEN_NO_CRLF_REC_ATTR DISABLE
DECC$STDIO_CTX_EOL DISABLE
DECC$USE_RAB64 DISABLE
DECC$GLOB_UNIX_STYLE DISABLE
Enhancements for UNIX Style Filenames
DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION DISABLE
DECC$EFS_CHARSET DISABLE
DECC$ENABLE_TO_VMS_LOGNAME_CACHE ENABLE
DECC$FILENAME_ENCODING_UTF8 DISABLE
DECC$FILENAME_UNIX_NO_VERSION DISABLE
DECC$FILENAME_UNIX_REPORT DISABLE
DECC$READDIR_DROPDOTNOTYPE DISABLE
DECC$RENAME_NO_INHERIT DISABLE
DECC$RENAME_ALLOW_DIR DISABLE
Enhancements for UNIX Style File Attributes
DECC$EFS_FILE_TIMESTAMPS DISABLE
DECC$EXEC_FILEATTR_INHERITANCE DISABLE
DECC$FILE_OWNER_UNIX DISABLE
DECC$FILE_PERMISSION_UNIX DISABLE
DECC$FILE_SHARING DISABLE
UNIX Compliance Mode
DECC$DETACHED_CHILD_PROCESS DISABLE
DECC$FILENAME_UNIX_ONLY DISABLE
DECC$POSIX_STYLE_UID DISABLE
DECC$USE_JPI$_CREATOR DISABLE
New Behaviors for POSIX Conformance
DECC$ALLOW_REMOVE_OPEN_FILES DISABLE
DECC$POSIX_SEEK_STREAM_FILE DISABLE
DECC$UMASK RMS default
File-Name Handling
DECC$POSIX_COMPLIANT_PATHNAMES DISABLE
DECC$DISABLE_POSIX_ROOT ENABLE
DECC$EFS_CASE_PRESERVE DISABLE
DECC$EFS_CASE_SPECIAL DISABLE
DECC$EFS_NO_DOTS_IN_DIRNAME DISABLE
DECC$READDIR_KEEPDOTDIR DISABLE
DECC$UNIX_PATH_BEFORE_LOGNAME DISABLE

An alphabetic listing and description of the C RTL feature logical names follows. Unless otherwise stated, the feature logicals are enabled with ENABLE and disabled with DISABLE.

DECC$ACL_ACCESS_CHECK

The DECC$ACL_ACCESS_CHECK feature logical controls the behavior of the access function.

With DECC$ACL_ACCESS_CHECK enabled, the access function checks both UIC protection and OpenVMS Access Control Lists (ACLs).

With DECC$ACL_ACCESS_CHECK disabled, the access function checks only UIC protection.

DECC$ALLOW_REMOVE_OPEN_FILES

The DECC$ALLOW_REMOVE_OPEN_FILES feature logical controls the behavior of the remove function on open files. Ordinarily, the operation fails. However, POSIX conformance dictates that the operation succeed.

With DECC$ALLOW_REMOVE_OPEN_FILES enabled, this POSIX conformant behavior is achieved.

DECC$ALLOW_UNPRIVILEGED_NICE

With DECC$ALLOW_UNPRIVILEGED_NICE enabled, the nice function exhibits its legacy behavior of not checking the privilege of the calling process (that is, any user may lower the nice value to increase process priorities). Also, when the caller sets a priority above MAX_PRIORITY, the nice value is set to the base priority.

With DECC$ALLOW_UNPRIVILEGED_NICE disabled, the nice function conforms to the X/Open standard of checking the privilege of the calling process (only users with ALTPRI privilege can lower the nice value to increase process priorities), and when the caller sets a priority above MAX_PRIORITY, the nice value is set to MAX_PRIORITY.

DECC$ARGV_PARSE_STYLE

With DECC$ARGV_PARSE_STYLE enabled, case is preserved in command-line arguments when the process has been set up for extended DCL parsing using SET PROCESS/PARSE_STYLE=EXTENDED.

DECC$ARGV_PARSE_STYLE must be defined externally as a logical name or set in a function called using the LIB$INITIALIZE mechanism because it is evaluated before function main is called.

DECC$DEFAULT_LRL

DECC$DEFAULT_LRL specifies the default value for the RMS attribute for the longest record length. The default value 32767 is the largest record size supported by RMS.

Default: 32767

Maximum: 32767

DECC$DEFAULT_UDF_RECORD

With DECC$DEFAULT_UDF_RECORD enabled, file access mode defaults to RECORD instead of STREAM mode for all files except STREAMLF.

DECC$DETACHED_CHILD_PROCESS

With DECC$DETACHED_CHILD_PROCESS enabled, child processes created using vfork and exec are created as detached processes instead of subprocesses.

This feature has only limited support. In some cases the console cannot be shared between the parent process and the detached process, which can cause exec to fail.

DECC$DISABLE_POSIX_ROOT

With DECC$DISABLE_POSIX_ROOT enabled, support for the POSIX root directory defined by SYS$POSIX_ROOT is disabled.

With DECC$DISABLE_POSIX_ROOT disabled, the SYS$POSIX_ROOT logical name is interpreted as the equivalent of the file path "/". If a UNIX path starting with a slash (/) is given and the value after the leading slash cannot be translated as a logical name, SYS$POSIX_ROOT is used as the parent directory for the specified UNIX file path.

The C RTL supports a UNIX style root that behaves like a real directory. This allows such actions as:


% cd / 
% mkdir /dirname 
% tar -xvf tarfile.tar /dirname 
% ls / 

Previously, the C RTL did not recognize "/" as a directory name. The normal processing for a file path starting with "/" was to interpret the first element as a logical name or device name. If this failed, there was special processing for the name /dev/null and names starting with /bin and /tmp :


/dev/null       NLA0: 
/bin            SYS$SYSTEM: 
/tmp            SYS$SCRATCH: 

These behaviors are retained for compatibility purposes. In addition, support has been added to the C RTL for the logical name SYS$POSIX_ROOT as an equivalent to "/".

To enable this feature for use by the C RTL, define SYS$POSIX_ROOT as a concealed logical name. For example:


$ DEFINE/TRANSLATION=(CONCEALED,TERMINAL) SYS$POSIX_ROOT "$1$DKA0:[SYS0.abc.]" 

To disable this feature:


$ DEFINE DECC$DISABLE_POSIX_ROOT DISABLE 

Enabling SYS$POSIX_ROOT results in the following behavior:

DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION

With DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION enabled, the conversion routine decc$to_vms will only treat the first element of a UNIX style name as a logical name if there is a leading slash (/).

DECC$EFS_CASE_PRESERVE

With DECC$EFS_CASE_PRESERVE enabled, case is preserved for filenames on ODS-5 disks.

With DECC$EFS_CASE_PRESERVE disabled, UNIX style filenames are always reported in lowercase.

However, note that enabling DECC$EFS_CASE_SPECIAL overrides the setting for DECC$EFS_CASE_PRESERVE.

DECC$EFS_CASE_SPECIAL

With DECC$EFS_CASE_SPECIAL enabled, case is preserved only for filenames containing lowercase. If an element of a filename contains all uppercase letters, it is reported in all lowercase in UNIX style.

When enabled, DECC$EFS_CASE_SPECIAL overrides the value of DECC$EFS_CASE_PRESERVE.

DECC$EFS_CHARSET

With DECC$EFS_CHARSET enabled, UNIX names can contain ODS-5 extended characters. Support includes multiple dots and all ASCII characters in the range 0 to 255, except the following:


<NUL>      
/         * 
"         ? 

Unless DECC$FILENAME_UNIX_ONLY is enabled, some characters can be interpreted as OpenVMS characters depending on context. They are:


:         ^ 
[         ; 
< 

DECC$EFS_CHARSET might be necessary for existing applications that make assumptions about filenames based on the presence of certain characters, because the following nonstandard and undocumented C RTL extensions do not work when EFS extended character-set support is enabled:

With DECC$EFS_CHARSET enabled, the following encoding for EFS extended characters is supported when converting from an OpenVMS style filename to a UNIX style filename:

Note

There are some special cases in C RTL filename processing. For example:
  • Pathnames ending in ^.dir are treated as directories, and when translated, these characters are truncated from the string.
  • Pathnames begining with ^/ treat the next token as a logical name or a directory from the root.


The following sample program shows these nuances:


#include <stdio.h> 
#include <dirent.h> 
#include <unixlib.h> 
#include <string.h> 
main() 
{ 
  char adir[80]; 
  DIR *dir; 
  struct dirent *dp; 
  int decc_feature_efs_charset_index = 0; 
  int decc_feature_efs_charset_default_val = 0; 
 
  if ( 
      ( (decc_feature_efs_charset_index = 
        decc$feature_get_index("DECC$EFS_CHARSET")) == -1 ) 
      || 
      ( (decc_feature_efs_charset_default_val = 
        decc$feature_get_value(decc_feature_efs_charset_index, 0)) == -1 ) 
      || 
      ( (decc$feature_set_value(decc_feature_efs_charset_index, 1, TRUE) == -1)) 
     ) 
    { 
      printf("Error setting up DECC$EFS_CHARSET macro\n"); 
    } 
 
  strcpy(adir, "SYS$SYSDEVICE:[SSHTEST.TEST.a^,test^.dir^;22]"); 
  printf("\n\nFor %s\n", adir); 
mrb:  dir = opendir(adir); 
  if(dir) 
    { 
      do 
        { 
          dp = readdir(dir); 
          if(dp->d_name) printf("%s\n", dp->d_name); 
        } while (dp); 
    } 
 
  closedir(dir); 
 
  strcpy(adir, "SYS$SYSDEVICE:[SSHTEST.TEST.a^,test^.dir]"); 
  printf("\n\nFor %s\n", adir); 
  dir = opendir(adir); 
  if(dir) 
    { 
      do 
        { 
          dp = readdir(dir); 
          if(dp->d_name) printf("%s\n", dp->d_name); 
        } while (dp); 
    } 
 
  closedir(dir); 
 
  strcpy(adir, "SYS$SYSDEVICE:[SSHTEST.TEST.a^\\test]"); 
  printf("\n\nFor %s\n", adir); 
  dir = opendir(adir); 
  if(dir) 
    { 
      do 
        { 
          dp = readdir(dir); 
          if(dp->d_name) printf("%s\n", dp->d_name); 
        } while (dp); 
    } 
 
  strcpy(adir, "SYS$SYSDEVICE:[SSHTEST.TEST.copies]"); 
  printf("\n\nFor %s\n", adir); 
  dir = opendir(adir); 
  if(dir) 
    { 
      do 
        { 
          dp = readdir(dir); 
          if(dp->d_name) printf("%s\n", dp->d_name); 
        } while (dp); 
    } 
 
  closedir(dir); 
 
  strcpy(adir, "/SYS$SYSDEVICE/SSHTEST/TEST/copies"); 
  printf("\n\nFor %s\n", adir); 
  dir = opendir(adir); 
  if(dir) 
    { 
      do 
        { 
          dp = readdir(dir); 
          if(dp->d_name) printf("%s\n", dp->d_name); 
        } while (dp); 
    } 
 
  closedir(dir); 
 
} 

DECC$EFS_FILE_TIMESTAMPS

With DECC$EFS_FILE_TIMESTAMPS enabled, stat and fstat report new ODS-5 access time ( st_atime ), attribute revision time ( st_ctime ) and modification time ( st_mtime ) for files on ODS-5 volumes that have the extended file times enabled using SET VOLUME/VOLUME=ACCESS_DATES.

If DECC$EFS_FILE_TIMESTAMPS is disabled, or the volume is not ODS-5, or the volume does not have support for these additional times enabled, st_ctime continues to be the file creation time and st_atime the same as the st_mtime .

The utime and utimes functions support these ODS-5 times in the same way as stat .

DECC$EFS_NO_DOTS_IN_DIRNAME

With support for extended characters in filenames for ODS-5, a name such as NAME.EXT can be interpreted as NAME.EXT.DIR. Determining if directory [.name^.ext] exists adds overhead to UNIX name translation when support for extended character support in UNIX filenames is enabled.


Previous Next Contents Index