1 CRTL The complete Compaq C Run-Time Library needed for use with the Compaq C compiler is distributed with the OpenVMS Alpha Operating System. The Compaq C Run-Time Library provides routines to perform input/output, character and string handling, mathematical computations, memory allocation, error detection, subprocess creation, system access, and emulation of selected UNIX[R] features. These routines are provided both in shared image and object module library form. The Compaq C RTL contains XPG4-compliant internationalization support, providing functions to help you develop software that can run in different languages and cultures. This online help describes the C RTL routines available with this version of the OpenVMS Alpha system, as well as the socket routines used for writing Internet application programs for the TCP/IP Services for OpenVMS product. 2 Feature-Test_Macros Feature-test macros provide a means for writing portable programs. They ensure that the Compaq C RTL symbolic names used by a program do not clash with the symbolic names supplied by the implementation. The Compaq C RTL header files are coded to support the use of a number of feature-test macros. When an application defines a feature-test macro, the Compaq C RTL header files supply the symbols and prototypes defined by that feature-test macro and nothing else. If a program does not define such a macro, the Compaq C RTL header files define symbols without restriction. The feature-test macros supported by the Compaq C RTL fall into several broad categories for controlling the visibility of symbols in header files according to the following: o Standards o Multiple-version support o Compatibility 3 Standards The Compaq C RTL implements parts of the following standards: o X/Open CAE Specification, System Interfaces and Headers, Issue 4, Version 2, also known as XPG4 V2. o X/Open CAE Specification, System Interfaces and Headers, Issue 4, also known as XPG4. o Standard for Information Technology - Portable Operating System Interface (POSIX) - Part 1: System Application Program Interface (API)-Amendment 2: Threads Extension [C Language], also known as POSIX 1003.1c-1995 or IEEE 1003.1c-1995. o ISO/IEC 9945-2:1993 - Information Technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities, also known as ISO POSIX-2. o ISO/IEC 9945-1:1990 - Information Technology - Portable Operating System Interface (POSIX) - Part 1: System Application Programming Interface (API) (C Language), also known as ISO POSIX-1. o ANSI/ISO/IEC 9899:1999 - The C99 standard, published by ISO in December, 1999 and adopted as an ANSI standard in April, 2000. o ISO/IEC 9899:1990-1994 - Programming Languages - C, Amendment 1: Integrity, also known as ISO C, Amendment 1. o ISO/IEC 9899:1990 - Programming Languages - C, also known as ISO C. The normative part is the same as X3.159-1989, American National Standard for Information Systems - Programming Language C, also known as ANSI C. 3 Standard_Macros You can define a feature-test macro to select each standard. You can do this either with a #define preprocessor directive in your C source before the inclusion of any header file, or with the /DEFINE qualifier on the CC command line. Features not defined by standards listed here are considered Compaq C extensions and are selected by not defining any standards-related, feature-test macros. If you do not explicitly define feature test macros to control header file definitions, you implicitly include all defined symbols as well as Compaq C extensions. 4 _XOPEN_SOURCE_EXTENDED Makes visible XPG4-extended features, including traditional UNIX based interfaces not previously adopted by X/Open. Standard Selected: XPG4 V2 Other Standards Implied: XPG4, ISO POSIX-2, ISO POSIX-1, ANSI C 4 _XOPEN_SOURCE Makes visible XPG4 standard symbols and causes _POSIX_C_SOURCE to be set to 2 if it is not already defined with a value greater than 2. Notes: o Where the ISO C Amendment 1 includes symbols not specified by XPG4, defining __STDC_VERSION__ == 199409 and _XOPEN_SOURCE (or _XOPEN_SOURCE_EXTENDED) selects both ISO C and XPG4 APIs. Conflicts that arise when compiling with both XPG4 and ISO C Amendment 1 resolve in favor of ISO C Amendment 1. o Where XPG4 extends the ISO C Amendment 1, defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED selects ISO C APIs as well as the XPG4 extensions available in the header file. This mode of compilation makes XPG4 extensions visible. Standard Selected: XPG4 Other Standards Implied: XPG4, ISO POSIX-2, ISO POSIX-1, ANSI C 4 _POSIX_C_SOURCE==199506 Header files defined by ANSI C make visible those symbols required by IEEE 1003.1c-1995. Standard Selected: IEEE 1003.1c-1995 Other Standards Implied: ISO POSIX-2, ISO POSIX-1, ANSI C 4 _POSIX_C_SOURCE == 2 Header files defined by ANSI C make visible those symbols required by ISO POSIX-2 plus those required by ISO POSIX-1. Standard Selected: ISO POSIX-2 Other Standards Implied: ISO POSIX-1, ANSI C 4 _POSIX_C_SOURCE == 1 Header files defined by ANSI C make visible those symbols required by ISO POSIX-1. Standard Selected: ISO POSIX-1 Other Standards Implied: ANSI C 4 _STDC_VERSION__ == 199409 Makes ISO C amendment 1 symbols visible. Standard Selected: ISO C amendment 1 Other Standards Implied: ANSI C 4 _ANSI_C_SOURCE Makes ANSI C standard symbols visible. Standard Selected: ANSI C Other Standards Implied: None. 4 Interactions_with_the_/STANDARD_Qualifier The /STANDARD qualifier selects the dialect of the C language supported. With the exception of /STANDARD=ANSI89 and /STANDARD=ISOC94, the selection of C dialect and the selection of Compaq C RTL APIs to use are independent choices. All other values for /STANDARD cause the entire set of APIs to be available, including extensions. Specifying /STANDARD=ANSI89 restricts the default API set to the ANSI C set. In this case, to select a broader set of APIs, you must also specify the appropriate feature-test macro. To select the ANSI C dialect and all APIs, including extensions, undefine __HIDE_FORBIDDEN_NAMES before including any header file. Compiling with /STANDARD=ISOC94 sets __STDC_VERSION__ to 199409. Conflicts that arise when compiling with both XPG4 and ISO C Amendment 1 resolve in favor of ISO C Amendment 1. XPG4 extensions to ISO C Amendment 1 are selected by defining _XOPEN_ SOURCE. The following examples help clarify these rules: o The fdopen function is an ISO POSIX-1 extension to . Therefore, defines fdopen only if one or more of the following is true: - The program including it is not compiled in strict ANSI C mode (/STANDARD=ANSI89). - _POSIX_C_SOURCE is defined as 1 or greater. - _XOPEN_SOURCE is defined. - _XOPEN_SOURCE_EXTENDED is defined. o The popen function is an ISO POSIX-2 extension to . Therefore, defines popen only if one or more of the following is true: - The program including it is not compiled in strict ANSI C mode (/STANDARD=ANSI89). - _POSIX_C_SOURCE is defined as 2 or greater. - _XOPEN_SOURCE is defined. - _XOPEN_SOURCE_EXTENDED is defined. o The getw function is an X/Open extension to . Therefore, defines getw only if one or more of the following is true: - The program is not compiled in strict ANSI C mode (/STANDARD=ANSI89). - _XOPEN_SOURCE is defined. - _XOPEN_SOURCE_EXTENDED is defined. o The X/Open Extended symbolic constants _SC_PAGESIZE, _SC_PAGE_SIZE, _SC_ATEXIT_MAX, and _SC_IOV_MAX were added to to support the sysconf function. However, these constants are not defined by _POSIX_C_SOURCE. The header file defines these constants only if a program does not define _POSIX_C_SOURCE and does define _XOPEN_SOURCE_EXTENDED. If _POSIX_C_SOURCE is defined, these constants are not visible in . Note that _POSIX_C_SOURCE is defined only for programs compiled in strict ANSI C mode. o The fgetname function is a Compaq C RTL extension to . Therefore, defines fgetname only if the program is not compiled in strict ANSI C mode (/STANDARD=ANSI89). o The macro _PTHREAD_KEYS_MAX is defined by POSIX 1003.1c-1995. This macro is made visible in when compiling for this standard with _POSIX_C_SOURCE == 199506 defined, or by default when compiling without any standards-defining, feature-test macros. o The macro WCHAR_MAX defined in is required by ISO C Amendment 1 but not by XPG4. Therefore: - Compiling for ISO C Amendment 1 makes this symbol visible, but compiling for XPG4 compliance does not. - Compiling for both ISO C Amendment 1 and XPG4 makes this symbol visible. Similarly, the functions wcsftime and wcstok in are defined slightly differently by the ISO C Amendment 1 and XPG4: - Compiling for ISO C Amendment 1 makes the ISO C Amendment 1 prototypes visible. - Compiling for XPG4 compliance makes the XPG4 prototypes visible. - Compiling for both ISO C Amendment 1 and XPG4 selects the ISO C prototypes because conflicts resulting from this mode of compilation resolve in favor of ISO C. - Compiling without any standard selecting feature test macros makes ISO C Amendment 1 features visible. So in this example, compiling with no standard-selecting feature-test macros makes WCHAR_MAX and the ISO C Amendment 1 prototypes for wcsftime and wcstok visible. o The wcswidth and wcwidth functions are XPG4 extensions to ISO C Amendment 1. Their prototypes are in . These symbols are visible if: - Compiling for XPG4 compliance by defining _XOPEN_SOURCE or _XOPEN_SOURCE_EXTENDED. - Compiling for DEC C Version 4.0 compatibility or on pre- OpenVMS Version 7.0 systems. - Compiling with no standard selecting feature test macros. - Compiling for both ISO C Amendment 1 and XPG4 compilance because these symbols are XPG4 extensions to ISO C Amendment 1. Compiling for strict ISO C Amendment 1 does not make them visible. 3 Multiple-Version_Macros __VMS_VER 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 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: o 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. o 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. __VMS_VER_OVERRIDE Define __VMS_VER_OVERRIDE on the compiler command line to override the value of __VMS_VER. Defining __VMS_VER_OVERRIDE without a value sets __VMS_VER to the maximum value. 3 Compatibility_Mode_Macros The following predefined macros are used to select header-file compatibility with previous versions of DEC C or the OpenVMS operating system: o _DECC_V4_SOURCE o _VMS_V6_SOURCE There are two types of incompatibilities that can be controlled in the header files: o 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. o 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: o To conform to the ISO POSIX-1 standard, typedefs for the following have been added to : dev_t off_t gid_t pid_t ino_t size_t mode_t ssize_t nlink_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 typedefs in by adding them to another module. If this is the case on your system, then compiling with the provided with DEC C Version 5.2 might cause compilation errors. To maintain your current environment and include the DEC C Version 5.2 , then compile with _DECC_V4_SOURCE defined. This will omit incompatible references from the DEC C Version 5.2 headers. In , for example, the previously listed typedefs will not be visible. o 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 (as required by the ISO POSIX-1 standard) and in (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. o 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. 3 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: o _BSD44_CURSES This macro selects the Curses package from the 4.4BSD Berkeley Software Distribution. o _VMS_CURSES This macro selects a Curses package based on the VAX C compiler. This is the default Curses package. o _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: o Symbolic constants like AE, AL, AS, AM, BC, which represent pointers to termcap fields used by the BSD Curses package, are only visible in if _BSD44_CURSES is defined. o The header file defines a 4.4BSD sockaddr structure only if _SOCKADDR_LEN or _XOPEN_SOURCE_EXTENDED is defined. Otherwise, defines a pre-4.4BSD sockaddr structure. If _SOCKADDR_LEN is defined and _XOPEN_SOURCE_EXTENDED is not defined, The 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. 3 2-Gigabyte_File_Size_Macro _LARGEFILE With OpenVMS Version 7.3-1, support is added for compiling applications to use file sizes and offsets that are two gigabytes and larger. This is accomplished by allowing file offsets of 64-bit integers. Two new functions, fseeko and ftello, have been added. They are identical to fseek and ftell, but they accept or return values of type off_t, which allows for a 64-bit variant of off_t to be used. Modifications to accommodate a 64-bit file offset have been made to the existing C RTL functions lseek, mmap, ftuncate, truncate, stat, fstat, and ftw. The new 64-bit interfaces can be selected at compile time by defining the _LARGEFILE feature macro. 3 32-bit_UID_GID_Macros With OpenVMS Version 7.3-1, The C RTL supports 32-bit User Identification (UID) and Group Identification (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. Use the following macros to control UID/GID size: o __USE_LONG_GID_T To compile an application for 32-bit UID/GID support, define the __USE_LONG_GID_T macro. o _DECC_SHORT_GID_T To compile an application for 16-bit UID/GID support, define the _DECC_SHORT_GID_T macro. 2 Feature_Logical_Names The C RTL provides an extensive list of feature switches that can be enabled or disabled 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 features logical names can be set to a numeric value. For example: $ DEFINE DECC$PIPE_BUFFER_SIZE 65536 The following C RTL Feature Logical Names lists the C RTL feature logical names, grouped by the type of features they control. Feature Logical Name Default ------- ------- ---- ------- Performance Optimizations: DECC$ENABLE_GETENV_CACHE DISABLE DECC$LOCALE_CACHE_SIZE 0 DECC$TZ_CACHE_SIZE 2 Legacy Behaviors: DECC$V62_RECORD_GENERATION DISABLE DECC$XPG4_STRPTIME DISABLE DECC$THREAD_DATA_AST_SAFE DISABLE File Attributes: DECC$DEFAULT_LRL 32767 DECC$DEFAULT_UDF_RECORD DISABLE DECC$FIXED_LENGTH_SEEK_TO_EOF DISABLE Mailboxes: DECC$MAILBOX_CTX_STM DISABLE Changes for UNIX Conformance: DECC$STRTOL_ERANGE DISABLE DECC$VALIDATE_SIGNAL_IN_KILL DISABLE DECC$SELECT_IGNORES_INVALID_FD DISABLE General UNIX Enhancements: DECC$ARGV_PARSE_STYLE DISABLE DECC$PIPE_BUFFER_SIZE 512 DECC$STDIO_CTX_EOL DISABLE DECC$USE_RAB64 DISABLE Enhancements for UNIX Style File Names: DECC$DISABLE_TO_VMS_LOGNAME_ DISABLE TRANSLATION DECC$EFS_CHARSET DISABLE DECC$FILENAME_UNIX_NO_VERSION DISABLE DECC$FILENAME_UNIX_REPORT DISABLE DECC$READDIR_DROPDOTNOTYPE DISABLE DECC$RENAME_NO_INHERIT 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$FILENAME_UNIX_ONLY DISABLE DECC$DETACHED_CHILD_PROCESS DISABLE New Behaviors for POSIX Conformance: DECC$POSIX_SEEK_STREAM_FILE DISABLE DECC$UMASK RMS default File Name Handling: DECC$READDIR_KEEPDOTDIR DISABLE DECC$EFS_CASE_PRESERVE DISABLE DECC$EFS_CASE_SPECIAL DISABLE DECC$UNIX_PATH_BEFORE_LOGNAME DISABLE DECC$DISABLE_POSIX_ROOT 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. 3 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. 3 DECC$DEFAULT_LRL DECC$DEFAULT_LRL specifies the default value for the RMS attribute for longest record length. The default value 32767 is the largest record size supported by RMS. Default: 32767 Maximum: 32767 3 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. 3 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. 3 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, logical name SYS$POSIX_ ROOT is interpreted as the equivalent of the file path "/". If a UNIX path starting with "/" 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. 3 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 "/". 3 DECC$EFS_CASE_PRESERVE With DECC$EFS_CASE_PRESERVE enabled, case is preserved for file names on ODS level 5 disks. With DECC$EFS_CASE_PRESERVE disabled, UNIX-style file names are always reported in lowercase. However, note that enabling DECC$EFS_CASE_SPECIAL overrides the setting for DECC$EFS_CASE_PRESERVE. 3 DECC$EFS_CASE_SPECIAL With DECC$EFS_CASE_SPECIAL enabled, case is preserved only for file names containing lowercase. If an element of a file name 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. 3 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: / " * ? 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 file names based on the presence of certain characters, because the following non-standard and undocumented C RTL extensions do not work when EFS extended character-set support is enabled: o $HOME is interpreted as the user's login directory With DECC$EFS_CHARSET enabled, $HOME is treated literally and may be in an OpenVMS or UNIX style file name. o ~name is interpreted as the login directory for user name With DECC$EFS_CHARSET enabled, ~name is treated literally and can be in an OpenVMS or UNIX style file name. o Wild card regular expressions in the form [a-z] With DECC$EFS_CHARSET enabled, square brackets are acceptable in OpenVMS and UNIX style file names. For instance, in a function such as open, abc[a-z]ef.txt is interpreted as a UNIX style name equivalent to the OpenVMS style name abc^[a- z^]ef.txt, and [a-z]bc is interpreted as an OpenVMS style name equivalent to the UNIX style name /sys$disk/a-z/bc. With DECC$EFS_CHARSET enabled, the following encoding for EFS extended characters is supported when converting from an OpenVMS style file name to a UNIX style file name: o All ODS-2 compatible names o All encoding for 8-bit characters, either as single byte or using two-digit hexadecimal form ^ab. In a UNIX path these are always represented as a single byte. o Encoding for DEL (^7F) o The following characters when preceded by a caret: space ! , _ & ' ( ) + @ { } ; # [ ] % ^ = $ - ~ . o The following characters when not preceded by a caret: $ - ~ . o The implementation supports the conversion from OpenVMS to UNIX needed for functions readdir, ftw, getname, fgetname, getcwd, and others. 3 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. Functions utime and utimes support these ODS-5 times in the same way as stat. 3 DECC$ENABLE_GETENV_CACHE The C RTL supplements the list of environment variables in the environ table with all logical names and DCL symbols available to the process. By default, whenever getenv is called for a name not in the environ table, an attempt is made to resolve this as a logical name and, if this fails, as a DCL symbol. With DECC$ENABLE_GETENV_CACHE enabled, once a logical name or DCL name has been successfully translated, its value is stored in a cache. When the same name is requested in a future call to getenv, the value is returned from the cache instead of reevaluating the logical name or DCL symbol. 3 DECC$EXEC_FILEATTR_INHERITANCE With DECC$EXEC_FILEATTR_INHERITANCE enabled, the current file pointer and the file open mode is passed to the child process in exec calls if the child is a C program. With this logical name disabled, the child process does not inherit append mode or the file position. 3 DECC$FILENAME_UNIX_ONLY With DECC$FILENAME_UNIX_ONLY enabled, file names are never interpreted as OpenVMS style names. This prevents any interpretation of the following as OpenVMS special characters: : [ ^ 3 DECC$FILENAME_UNIX_NO_VERSION With DECC$FILENAME_UNIX_NO_VERSION enabled, OpenVMS version numbers are not supported in UNIX style file names. With DECC$FILENAME_UNIX_NO_VERSION disabled, in UNIX style names, version numbers are reported preceded by a dot. 3 DECC$FILENAME_UNIX_REPORT With DECC$FILENAME_UNIX_REPORT enabled, all file names are reported in UNIX style unless the caller specifically selects OpenVMS style. This applies to getpwnam, getpwuid, argv[0], getname, and fgetname. With DECC$FILENAME_UNIX_REPORT disabled, unless specified in the function call, file names are reported in OpenVMS style. 3 DECC$FILE_OWNER_UNIX With DECC$FILE_OWNER_UNIX enabled, the owner for a new file or directory is always based on the effective UIC. When an earlier version of the file exists, the owner for the new file is inherited from the earlier version. With DECC$FILE_OWNER_UNIX disabled, the owner for a new file is set following OpenVMS rules and may inherit the owner from the parent directory. 3 DECC$FILE_PERMISSION_UNIX With DECC$FILE_PERMISSION_UNIX enabled, the file permissions for new files and directories are set according to the file creation mode and umask. This includes mode 0777. When an earlier version of the file exists, the file permissions for the new file are inherited from the earlier version. This mode sets DELETE permission for a new directory when WRITE permission is enabled. With DECC$FILE_PERMISSION_UNIX disabled, modes 0 and 0777 indicate using RMS default protection or protection from the previous version of the file. Permissions for new directories also follow OpenVMS rules, including disabling DELETE permissions. 3 DECC$FILE_SHARING With DECC$FILE_SHARING enabled, all files are opened with full sharing enabled (FAB$M_DEL | FAB$M_GET | FAB$M_PUT | FAB$M_UPD). This is set as a logical OR with any sharing mode specified by the caller. 3 DECC$FIXED_LENGTH_SEEK_TO_EOF With DECC$FIXED_LENGTH_SEEK_TO_EOF enabled, lseek, fseeko and fseek with the direction paremeter set to SEEK_END will position relative to the last byte in the file for files with fixed-length records. With DECC$FIXED_LENGTH_SEEK_TO_EOF disabled, lseek, fseek, and fseeko when called with SEEK_EOF on files with fixed-length records, will position relative to the end of the last record in the file. 3 DECC$LOCALE_CACHE_SIZE DECC$LOCALE_CACHE_SIZE defines how much memory, in bytes, to allocate for caching locale data. The default value is 0, which disables the locale cache. Default: 0 Maximum: 2147483647 3 DECC$MAILBOX_CTX_STM By default, open on a local mailbox that is not a pipe treats mailbox records as having a record attribute of FAB$M_CR. With DECC$MAILBOX_CTX_STM enabled, the record attribute FAB$M_CR is not set. 3 DECC$PIPE_BUFFER_SIZE The system default buffer size of 512 bytes for pipe write operations can limit performance and generate extra line feeds when handling messages longer than 512 bytes. DECC$PIPE_BUFFER_SIZE allows a larger default buffer size to be used for pipe functions such as pipe and popen. A value of 512 to 65024 bytes can be specified. If DECC$PIPE_BUFFER_SIZE is not specified, the default buffer size 512 is used. Default: 512 Minimum: 512 Maximum: 65536 3 DECC$POSIX_SEEK_STREAM_FILE With DECC$POSIX_SEEK_STREAM_FILE enabled, positioning beyond end-of-file on STREAM files does not write to the file until the next write. If the write is beyond the current end-of-file, this positions beyond the old end-of-file, and the start position for the write is filled with zeros. With DECC$POSIX_SEEK_STREAM_FILE disabled, positioning beyond end-of-file will immediately write zeros to the file from the current end-of-file to the new position. 3 DECC$READDIR_DROPDOTNOTYPE With DECC$READDIR_DROPDOTNOTYPE enabled, readdir when reporting files in UNIX style only reports the trailing dot for files with no file type when the file name contains a dot. With this logical name disabled, all files without a file type are reported with a trailing dot. 3 DECC$READDIR_KEEPDOTDIR The default behavior when reporting files in UNIX style from readdir is to report directories without a file type. With DECC$READDIR_KEEPDOTDIR enabled, directories are reported in UNIX style with a file type of ".DIR". 3 DECC$RENAME_NO_INHERIT With DECC$RENAME_NO_INHERIT enabled, the new name for the file does not inherit anything from the old name. The new name must be specified completely. With DECC$RENAME_NO_INHERIT disabled, the new file name inherits missing components of the file name such as the device, directory, file type, and version from the old file, in the same way as the DCL RENAME command. 3 DECC$SELECT_IGNORES_INVALID_FD With DECC$SELECT_IGNORES_INVALID_FD enabled, select fails with errno set to EBADF when an invalid file descriptor is specified in one of the descriptor sets. With DECC$SELECT_IGNORES_INVALID_FD disabled, select ignores invalid file descriptors. 3 DECC$STDIO_CTX_EOL With DECC$STDIO_CTX_EOL enabled, writing to stdout and stderr for stream access is deferred until a terminator is seen or the buffer is full. With DECC$STDIO_CTX_EOL disabled, each fwrite generates a separate write, which for mailbox and record files generates a separate record. 3 DECC$STRTOL_ERANGE With DECC$STRTOL_ERANGE enabled, the strtol behavior for an ERANGE error is corrected to consume all remaining digits in the string. With DECC$STRTOL_ERANGE disabled, the legacy behavior of leaving the pointer at the failing digit is preserved. 3 DECC$THREAD_DATA_AST_SAFE The C RTL has a mode that allocates storage for thread-specific data allocated by threads at non-AST level separate for data allocated for ASTs. In this mode, each access to thread- specific data requires a call to LIB$AST_IN_PROG, which can add significant overhead when accessing thread-specific data in the C RTL. The alternate mode protects thread-specific data only if another function has it locked. This protects data that is in use within the C RTL, but does not protect the caller from an AST changing the data pointed to. This latter mode is now the C RTL default for the strtok, ecvt, and fcvt functions. You can select the legacy AST safe mode by enabling DECC$THREAD_ DATA_AST_SAFE. 3 DECC$TZ_CACHE_SIZE DECC$TZ_CACHE_SIZE specifies the number of time zones that can be held in memory. Default: 2 Maximum: 2147483647 3 DECC$UMASK DECC$UMASK specifies the default value for the permission mask umask. By default, a parent C program sets the umask from the RMS default permissions for the process. A child process inherits the parent's value for umask. To enter the value as an octal value, add the leading zero; otherwise it is translated as a decimal value. For example: $ DEFINE DECC$UMASK 026 Maximum: 0777 3 DECC$UNIX_PATH_BEFORE_LOGNAME With DECC$UNIX_PATH_BEFORE_LOGNAME enabled, when translating a UNIX file name not starting with a leading slash (/), an attempt is made to match this to a file or directory in the current directory. If this is not found and the name is valid as a logical name in an OpenVMS file name, an attempt is made to translate the logical name and, if found, is used as part of the resulting file name. Enabling DECC$UNIX_PATH_BEFORE_LOGNAME overrides the setting for DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION. 3 DECC$USE_RAB64 With DECC$USE_RAB64 enabled, open functions allocate a RAB64 structure instead of the traditional RAB structure. This provides latent support for file buffers in 64-bit memory. 3 DECC$VALIDATE_SIGNAL_IN_KILL With DECC$VALIDATE_SIGNAL_IN_KILL enabled, a signal value that is in the range 0 to _SIG_MAX but is not supported by the C RTL generates an error with errno set to EINVAL, which makes the behavior the same as for raise. With this logical name disabled, validation of signals is restricted to checking that the signal value is in the range 0 to _SIG_MAX. If sys$sigprc fails, errno is set based on sys$sigprc exit status. 3 DECC$V62_RECORD_GENERATION OpenVMS Versions 6.2 and higher can output record files using different rules. With DECC$V62_RECORD_GENERATION enabled, the output mechanism follows the rules used for OpenVMS Version 6.2. 3 DECC$XPG4_STRPTIME XPG5 support for strptime introduces pivoting year support so that years in the range 0 to 68 are in the 21st century, and years in the range 69-99 are in the 20th century. With DECC$XPG4_STRPTIME enabled, XPG5 support for the pivoting year is disabled and all years in the range 0 to 99 are in the current century. 2 Version-Dependency_Tables New functions are added to the Compaq C Run-Time Library with each version of Compaq C. These functions are implemented and shipped with the OpenVMS operating system, while the documentation and header files containing their prototypes are shipped with versions of the Compaq C compiler. You might have a newer version of Compaq C that has header files and documentation for functions that are not supported on your older OpenVMS system. For example, if your target operating system platform is OpenVMS Version 6.2, you cannot use Compaq C RTL functions that were introduced on OpenVMS Version 7.0, even though they are documented in this manual. The tables that follow list what Compaq C RTL functions are supported on recent OpenVMS versions. This is helpful for determining the functions to avoid using on your target OpenVMS platforms. Also, for Compaq C and C++ Version 5.6 and higher, a C RTL backport object library is included with the compiler distribution kit. The backport object library allows developers on older versions of OpenVMS to use the latest C run- time library functions. For more information, see the file SYS$LIBRARY:DECC$CRTL.README on your system. 3 All_OpenVMS_Versions The following table lists functions available on all OpenVMS VAX and OpenVMS Alpha versions: Table B-1 Functions Available on All OpenVMS Systems abort abs access acos alarm asctime asin assert atan2 atan atexit atof atoi atoll (Alpha) atol atoq (Alpha) box brk bsearch cabs calloc ceil cfree chdir chmod chown clearerr clock close cosh cos creat ctermid ctime cuserid decc$crtl_init decc$fix_time decc$from_vms decc$match_wild decc$record_read decc$record_write decc$set_reentrancy decc$to_vms decc$translate_vms delete delwin difftime div dup2 dup ecvt endwin execle execlp execl execve execvp execv exit _exit exp fabs fclose fcvt fdopen feof ferror fflush fgetc fgetname fgetpos fgets fileno floor fmod fopen fprintf fputc fputs fread free freopen frexp fscanf fseek fsetpos fstat fsync ftell ftime fwait fwrite gcvt getchar getcwd getc getegid getenv geteuid getgid getname getpid getppid gets getuid getw gmtime gsignal hypot initscr isalnum isalpha isapipe isascii isatty iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit kill labs ldexp ldiv llabs (Alpha) lldiv(Alpha) localeconv localtime log10 log longjmp longname lseek lwait malloc mblen mbstowcs mbtowc memchr memcmp memcpy memmove memset mkdir mktemp mktime modf mvwin mv[w]addstr newwin nice open overlay overwrite pause perror pipe pow printf putchar putc puts putw qabs (Alpha) qdiv (Alpha) qsort raise rand read realloc remove rename rewind sbrk scanf scroll setbuf setgid setjmp setlocale setuid setvbuf sigblock signal sigpause sigstack(VAX) sigvec sinh sin sleep sprintf sqrt srand sscanf ssignal stat strcat strchr strcmp strcoll strcpy strcspn strerror strftime strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtod strtok strtoll strtol (Alpha) strtoq (Alpha) strtoull (Alpha) strtoul strtouq (Alpha) strxfrm subwin system tanh tan times time tmpfile tmpnam toascii tolower _tolower touchwin toupper _toupper ttyname umask ungetc vaxc$calloc_opt vaxc$cfree_opt vaxc$crtl_init vaxc$establish vaxc$free_opt vaxc$malloc_opt vaxc$realloc_opt va_arg va_count va_end va_start va_start_1 vfork vfprintf vprintf vsprintf wait wcstombs wctomb write [w]addch [w]addstr [w]clear [w]clrattr [w]clrtobot [w]clrtoeol [w]delch [w]deleteln [w]erase [w]getch [w]getstr [w]inch [w]insch [w]insertln [w]insstr [w]move [w]printw [w]refresh [w]scanw [w]setattr [w]standend [w]standout 3 Version_6.2_and_Higher The following table lists functions available on OpenVMS VAX and OpenVMS Alpha Version 6.2 and higher: Table B-2 Functions Added in OpenVMS Version 6.2 catclose catgets catopen fgetwc fgetws fputwc fputws getopt getwc getwchar iconv iconv_close iconv_open iswalnum iswalpha iswcntrl iswctype iswdigit iswgraph iswlower iswprint iswpunct iswspace iswupper iswxdigit nl_langinfo putwc putwchar strnlen strptime towlower towupper ungetwc wcscat wcschr wcscmp wcscoll wcscpy wcscspn wcsftime wcslen wcsncat wcsncmp wcsncpy wcspbrk wcsrchr wcsspn wcstol wcstoul wcswcs wcswidth wcsxfrm wcstod wctype wcwidth wcstok 3 Version_7.0_and_Higher The following table lists functions available on OpenVMS VAX and OpenVMS Alpha Version 7.0 and higher: Table B-3 Functions Added in OpenVMS Version 7.0 basename bcmp bcopy btowc bzero closedir confstr dirname drand48 erand48 ffs fpathconf ftruncate ftw fwide fwprintf fwscanf getclock getdtablesizegetitimer getlogin getpagesize getpwnam getpwuid gettimeofday index initstate jrand48 lcong48 lrand48 mbrlen mbrtowc mbsinit mbsrtowcs memccpy mkstemp mmap mprotect mrand48 msync munmap nrand48 opendir pathconf pclose popen putenv random readdir rewinddir rindex rmdir seed48 seekdir setenv setitimer setstate sigaction sigaddset sigdelset sigemptyset sigfillset sigismember siglongjmp sigpending sigprocmask sigsetjmp sigsuspend srand48 srandom strcasecmp strdup strfmon strncasecmp strsep swab swprintf swscanf sysconf telldir tempnam towctrans truncate tzset ualarm uname unlink unsetenv usleep vfwprintf vswprintf vwprintf wait3 wait4 waitpid wcrtomb wcsrtombs wcsstr wctob wctrans wmemchr wmemcmp wmemcpy wmemmove wmemset wprintf wscanf 3 OpenVMS_Alpha_Version_7.0_and_Higher The following table lists functions available on OpenVMS Alpha Version 7.0 and higher: Table B-4 Functions Added in OpenVMS Alpha Version 7.0 _basename32 _basename64 _bsearch32 _bsearch64 _calloc32 _calloc64 _catgets32 _catgets64 _ctermid32 _ctermid64 _cuserid32 _cuserid64 _dirname32 _dirname64 _fgetname32 _fgetname64 _fgets32 _fgets64 _fgetws32 _fgetws64 _gcvt32 _gcvt64 _getcwd32 _getcwd64 _getname32 _getname64 _gets32 _gets64 _index32 _index64 _longname32 _longname64 _malloc32 _malloc64 _mbsrtowcs32 _mbsrtowcs64 _memccpy32 _memccpy64 _memchr32 _memchr64 _memcpy32 _memcpy64 _memmove32 _memmove64 _memset32 _memset64 _mktemp32 _mktemp64 _mmap32 _mmap64 _qsort32 _qsort64 _realloc32 _realloc64 _rindex32 _rindex64 _strcat32 _strcat64 _strchr32 _strchr64 _strcpy32 _strcpy64 _strdup32 _strdup64 _strncat32 _strncat64 _strncpy32 _strncpy64 _strpbrk32 _strpbrk64 _strptime32 _strptime64 _strrchr32 _strrchr64 _strsep32 _strsep64 _strstr32 _strstr64 _strtod32 _strtod64 _strtok32 _strtok64 _strtol32 _strtol64 _strtoll32 _strtoll64 _strtoq32 _strtoq64 _strtoul32 _strtoul64 _strtoull32 _strtoull64 _strtouq32 _strtouq64 _tmpnam32 _tmpnam64 _wcscat32 _wcscat64 _wcschr32 _wcschr64 _wcscpy32 _wcscpy64 _wcsncat32 _wcsncat64 _wcsncpy32 _wcsncpy64 _wcspbrk32 _wcspbrk64 _wcsrchr32 _wcsrchr64 _wcsrtombs32 _wcsrtombs64 _wcsstr32 _wcsstr64 _wcstok32 _wcstok64 _wcstol32 _wcstol64 _wcstoul32 _wcstoul64 _wcswcs32 _wcswcs64 _wmemchr32 _wmemchr64 _wmemcpy32 _wmemcpy64 _wmemmove32 _wmemmove64 _wmemset32 _wmemset64 3 Version_7.2_and_Higher The following table lists functions available on OpenVMS VAX and OpenVMS Alpha Version 7.2 and higher: Table B-5 Functions Added in OpenVMS Version 7.2 asctime_r ctime_r decc$set_child_standard_streams decc$write_eof_to_mbx decc$validated lclose dlerror dlopen dlsym fcntl gmtime_r localtime_r wchar 3 Version_7.3_and_Higher The following table lists functions available on OpenVMS VAX and OpenVMS Alpha Version 7.3 and higher: Table B-6 Functions Added in OpenVMS Version 7.3 fchown link utime utimes writev 3 Version_7.3-1_and_Higher The following table lists functions available on OpenVMS Alpha Version 7.3-1 and higher: Table B-7 Functions Added in OpenVMS Version 7.3-1 access fseeko chmod ftello chown ftw fstat readdir_r stat vfscanf vfwscanf vscanf vwscanf vsscanf vswscanf decc$feature_get_index decc$feature_get_name decc$feature_get_value decc$feature_set_value 2 Prototypes_Duplicated_to_Non-Standard_Headers The various standards dictate which header file must define each of the standard functions. This is the included header file documented with each function prototype in the Reference Section of the C RTL manual and help. However, many of the functions defined by the standards already existed on several operating systems and were defined in different header files. This is especially true on OpenVMS systems with the header files , , and . So, to provide upward compatibility for these functions, their prototypes are duplicated in both the expected header file as well as the header file defined by the standards. Duplicated Prototypes lists these functions. Table C-1 Duplicated Prototypes Duplicated Function in Standard says access alarm bcmp bcopy bzero chdir chmod chown close creat ctermid cuserid dirname dup dup2 ecvt execl execle execlp execv execve execvp _exit fcvt ffs fsync ftime gcvt getcwd getegid getenv geteuid getgid getopt getpid getppid getuid index isatty lseek mkdir mktemp nice open pause pipe read rindex sbrk setgid setuid sleep strcasecmp strncasecmp system times umask vfork wait write 2 Socket_Routines Socket routines are used in writing Internet application programs for the TCP/IP Services for OpenVMS product or other implementations of the TCP/IP protocol. For a description of Internet details, such as protocols, protocol types, and sockets, see the TCP/IP Services for OpenVMS product documentation. 3 accept Accepts a connection on a socket. Format #include int accept (int s, struct sockaddr *addr, int *addrlen); (_DECC_V4_SOURCE) int accept (int s, struct sockaddr *addr, size_t *addrlen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_accept. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been returned by socket, subsequently bound to an address with bind, and that is listening for connections after a listen. addr A result parameter that is filled in with the address of the connecting entity, as known to the communications layer. The exact format of the structure to which the address parameter points is determined by the domain in which the communication is occurring. This version of Compaq C supports only the Internet domain (AF_INET). addrlen A value-result parameter; it should initially contain the size of the structure pointed to by addr. On return it will contain the actual length, in bytes, of the structure that has been filled in by the communication layer. See for a description of the sockaddr structure. 4 Description This routine completes the first connection on the queue of pending connections, creates a new socket with the same properties as s, and allocates and returns a new descriptor for the socket. If no pending connections are present on the queue, and the socket is not marked as nonblocking, accept blocks the caller until a connection request is present. If the socket is marked nonblocking by using a setsockopt call and no pending connections are present on the queue, accept returns an error. The accepted socket may not be used to accept connections. The original socket s remains open (listening) for other connection requests. This call is used with connection-based socket types, currently with SOCK_STREAM. It is possible to select a socket for the purposes of performing an accept by selecting it for read. See also bind, connect, listen, select, and socket. 4 Return_Values x A nonnegative integer that is a descriptor for the accepted socket. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EOPNOTSUPP - The reference socket is not of type SOCK_STREAM. o EFAULT - The addr parameter is not in a writable part of the user address space. o EWOULDBLOCK - The socket is marked nonblocking and no connections are present to be accepted. 3 bind Binds a name to a socket. Format #include int bind (int s, struct sockaddr *name, int namelen); (_DECC_V4_SOURCE) int bind (int s, const struct sockaddr *name, size_t namelen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_bind. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. 4 Arguments s A socket descriptor that has been created with socket. name Address of a structure used to assign a name to the socket in the format specific to the family (AF_INET) socket address. See for a description of the sockaddr structure. namelen The size, in bytes, of the structure pointed to by name. 4 Description This routine assigns a name to an unnamed socket. When a socket is created with socket it exists in a name space (address family) but has no name assigned. The bind routine requests that a name be assigned to the socket. See also connect, getsockname, listen, and socket. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EADDRNOTAVAIL - specified address is not available from the local machine. o EADDRINUSE - The specified Internet address and ports are already in use. o EINVAL - The socket is already bound to an address. o EACCESS - The requested address is protected, and the current user has inadequate permission to access it. o EFAULT - The name parameter is not a valid part of the user address space. 3 close Closes a connection and deletes a socket descriptor. Format #include int close (s); 4 Argument s A socket descriptor. 4 Description This routine deletes a descriptor from the per-process object reference table. If this is the last reference to the underlying object, then it will be deactivated. See also accept, socket, and write. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to EBADF (The socket descriptor is invalid.) 3 connect Initiates a connection on a socket. Format #include int connect (int s, struct sockaddr *name, int namelen); (_DECC_V4_SOURCE) int connect (int s, const struct sockaddr *name, size_t namelen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_connect. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been created with socket. name The address of a structure that specifies the name of the remote socket in the format specific to the address family (AF_INET). namelen The size, in bytes, of the structure pointed to by name. 4 Description If s is a socket descriptor of type SOCK_DGRAM, then this call permanently specifies the peer to which data is to be sent. If it is of type SOCK_STREAM, then this call attempts to make a connection to another socket. Each communications space interprets the name parameter in its own way. This argument specifies the socket to which the socket specified in s is to be connected. See also accept, select, socket, getsockname, and shutdown. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EADDRNOTAVAIL - specified address is not available from the local machine. o EAFNOSUPPORT - Address in the specified address family cannot be used with this socket. o EISCONN - The socket is already connected. o ETIMEOUT - Connection establishment timed out without establishing a connection. o ECONNREFUSED - The attempt to connect was forcefully rejected. o ENETUNREACH - The network is not reachable from this host. o EADDRINUSE - The specified Internet address and ports are already in use. o EFAULT - The name parameter is not a valid part of the user address space. o EWOULDBLOCK - The socket is nonblocking and the connection cannot be completed immediately. It is possible to select the socket while it is connecting by selecting it for writing. 3 decc$get_sdc Returns the Socket Device Channel (SDC) associated with a socket descriptor for direct use with the TCP/IP Services for OpenVMS product. Format #include short int decc$get_sdc (int s); 4 Argument s A socket descriptor. 4 Description This routine returns the SDC associated with a socket. C socket descriptors are normally used either as file descriptors or with one of the routines that take an explicit socket descriptor as its argument. C sockets are implemented using TCP/IP Services for OpenVMS Socket Device Channels. This routine returns the SDC used by a given socket descriptor so that you can use the TCP/IP Services for OpenVMS's facilities directly by means of various I/O system services ($QIO). 4 Return_Values 0 Indicates that s is not an open socket descriptor. x The SDC number. 3 endhostent Closes host database file. Format #include void endhostent (void); 4 Description The endhostent routine closes the network host database file, previously opened with the gethostbyaddr or gethostbyname routine. See also gethostbyaddr, and gethostbyname. 4 Errors If the endhostent routine does not exist in your TCP/IP library, then errno is set to ENOSYS. 3 endnetent Closes the networks database file. Format #include void endnetent (void); 4 Description The endentent routine closes the networks database file, previously opened with the getnetent, setnetent, getnetbyaddr or getnetbyname routine. See also getnetent, getnetbyaddr, getnetbyname, and setnetent. 4 Errors If the endnetent routine does not exist in your TCP/IP library, then errno is set to ENOSYS. 3 endprotoent Closes the protocols database file. Format #include void endprotoent (void); 4 Description The endprotoent routine closes the network protocols database file, previously opened with the getprotoent, getprotobyname, or getprotobynumber routine. See also getprotobyname, getprotoent and getprotobynumber. 4 Errors If the endprotoent routine does not exist in your TCP/IP library, then errno is set to ENOSYS. 3 endservent Closes the network services database file. Format #include void endservent (void); 4 Description The endservent routine closes the network services database file, previously opened with the getservent, getservbyname, or getservbyport routine. See also getservent, getservbyname, and getservbyport. 4 Errors If the endservent routine does not exist in your TCP/IP library, then errno is set to ENOSYS. 3 freeaddrinfo IPv6 socket routine Frees system resources used by an address information structure. Format #include void freeaddrinfo (struct addrinfo *ai); 4 Arguments ai Pointer to the addrinfo structure to be freed. 4 Description This routine frees one or more addrinfo structures and any dynamic storage associated with the structures. The process continues until the routine encounters a NULL ai_next pointer. The header file defines the addrinfo structure. 3 freehostent Deprecated IPv6 socket routine. Replace with freeaddrinfo. 3 getaddrinfo Protocol-independent function for mapping names to addresses. Format #include int getaddrinfo (const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res); 4 Arguments nodename Pointer to a network node name, alias, or numeric host address (for example, an IPv4 dotted-decimal address or an IPv6 hexadecimal address). This is a null-terminated string or NULL. NULL means the service location is local to the caller. The nodename and servname parameters cannot both be NULL. servname Pointer to a network service name or port number. This is a null-terminated string or NULL; NULL returns network-level addresses for the specified nodename). The nodename and servname arguments cannot both be NULL. hints Pointer to an addrinfo structure that contains information about the type of socket the caller supports. The header file defines the addrinfo structure. This is an optional parameter. res Pointer to a linked list of one or more addrinfo structures. 4 Description This routine takes a service location (nodename) or a service name (servname), or both, and returns a pointer to a linked list of one or more structures of type addrinfo. Its members specify data obtained from either the local hosts database TCPIP$ETC:IPNODES.DAT file, local TCPIP$HOSTS.DAT file, or one of the files distributed by DNS/BIND. The header file defines the addrinfo structure. If you specify the hints parameter, all addrinfo structure members other than the following members must be zero or a NULL pointer: o ai_flags Control the processing behavior of getaddrinfo. The ai flags are defined in . o ai_family Specifies to return addresses for use with a specific protocol family: - If you specify a value of AF_UNSPEC, the routine returns addresses for any protocol family that can be used with nodename or servname. - If the value is not AF_UNSPEC and ai_protocol is not zero, the routine returns addresses for use only with the specified protocol family and protocol. - If the application handles only IPv4, set this member of the hints structure to PF_INET. - If ai_family is set to PF_INET6, the function looks only in the TCPIP$ETC:IPNODES.DAT file and the lookup fails in the BIND database. o ai_socktype Specifies a socket type for the given service. If you specify a value of 0, you will accept any socket type. This resolves the service name for all socket types and returns all successful results. o ai_protocol Specifies a network protocol. If you specify a value of 0, you will accept any protocol. If the application handles only TCP, set this member to IPPROTO_TCP. If the hints parameter is a NULL pointer, this is identical to passing an addrinfo structure that has been initialized to zero, and the the ai_family member set to AF_UNSPEC. You can use the flags in any combination to achieve finer control of the translation process. The AI_ADDRCONFIG flag is typically used in combination with other flags to modify the search based on the source address or addresses configured on the system. Most applications will want to use the combination of the AI_ADDRCONFIG and AI_V4MAPPED flags to control their search. To simplify this for the programmer, the AI_DEFAULT symbol, which is a logical OR of AI_ADDRCONFIG and AI_V4MAPPED, is defined. Upon successful return, getaddrinfo returns a pointer to a linked list of one or more addrinfo structures. The application can process each addrinfo structure in the list by following the ai_next pointer until a NULL pointer is encountered. In each returned addrinfo structure, the ai_family, ai_socktype, and ai_protocol members are the corresponding arguments for a call to the socket() function. The ai_addr member points to a filled-in socket address structure whose length is specified by the ai_addrlen member. 4 Return_Values 0 Indicates successful completion. nonzero Indicates failure. 3 gethostaddr Returns the standard host address for the processor. Format #include int gethostaddr (char *addr); 4 Arguments addr A pointer to the buffer in which the standard host address for the current processor is returned. 4 Description This system call returns the standard host address for the current processor. The returned address is null-terminated. The addr parameter must point to at least 16 bytes of free space. Host addresses are limited to 16 characters. 4 Return_Values 0 Indicates success. -1 Indicates that an error has occurred and is further specified in the global errno. 3 gethostbyaddr Searches the host database sequentially from the beginning of the database for a host record with a given address. Format #include struct hostent *gethostbyaddr (char *addr, int len, int type); 4 Routine_Variants This socket routine has a variant named __bsd44_gethostbyaddr. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. 4 Arguments addr A pointer to a series of bytes in network order specifying the address of the host sought. This argument does not point to an ASCII string. len The number of bytes in the address pointed to by the addr argument. type The type of address format being sought. Currently, only AF_INET (defined in ) is supported.) 4 Description This routine finds the first host record in the host database with the given address. The gethostbyaddr routine uses a common static area for its return values. This means that subsequent calls this routine will overwrite any existing host entry. You must make a copy of the host entry if you wish to save it. 4 Return_Values NULL Indicates an error. x A pointer to an object having the hostent structure. See for a description of the hostent structure. Depending on the error condition and the socket implementation selected, errno or h_ errno might be set to further indicate the error. 3 gethostbyname Searches the host database sequentially from the beginning of the database for a host record with a given name or alias. Format #include struct hostent *gethostbyname (char *name); 4 Routine_Variants This socket routine has a variant named __bsd44_gethostbyname. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. 4 Argument name A pointer to a null-terminated character string containing the name or an alias of the host sought. 4 Description This routine finds the first host in the host database with the given name or alias. The gethostbyname routine uses a common static area for its return values. This means that subsequent calls to this routine will overwrite any existing host entry. You must make a copy of the host entry if you wish to save it. 4 Return_Values NULL Indicates an error. x A pointer to an object having the hostent structure. See for a description of the hostent structure. Depending on the error condition and the socket implementation selected, errno or h_ errno might be set to further indicate the error. 3 gethostent Gets a host file entry from the network host database file. Format #include struct hostent *gethostent (void); 4 Description The gethostent routine reads the next entry of the database, opening a connection to the database, if necessary. See the header file for a description of the hostent structure. This routine uses a common static area for its return values. Therefore, subsequent calls to this routine overwrite any existing network entry. You must make a copy of the network services entry, if you wish to save it. 4 Return_Values x A pointer to the hostent structure. NULL Indicates an error. 3 gethostname Returns the name currently associated to the host. Format #include int gethostname (char *name, int namelen); (_DECC_V4_SOURCE) int gethostname (char *name, size_t namelen); (not _DECC_V4_SOURCE) 4 Arguments name The address of a buffer into which the name should be written. The returned name is null-terminated unless sufficient space is not provided. namelen The size of the buffer pointed to by name. 4 Description This routine returns the hostname maintained by the TCP/IP Services for OpenVMS or compatible TCP/IP product. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EFAULT - The buffer decribed by name and namelen is not a valid, writable part of the user address space. o EINVAL - The returned name is an invalid address. 3 getipnodebyname Deprecated IPv6 socket routine. Replace with getnameinfo 3 getipnodebyaddr Deprecated IPv6 socket routine. Replace with getaddrinfo 3 getnameinfo Protocol-independent function for mapping names to addresses. Format #include int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char **serv, size_t servlen, int flags ); 4 Arguments sa Pointer either to a sockaddr_in structure (for IPv4) or to a sockaddr_in6 structure (for IPv6) that holds the IP address and port number. salen Length of either the sockaddr_in structure or the sockaddr_in6 structure. node Pointer to a buffer in which to receive the null-terminated network node name or alias corresponding to the address contained in the sa. A NULL pointer instructs the routine not to return a node name. The node parameter and serv parameter cannot both be zero. nodelen Length of the node buffer. A value of zero instructs the routine not to return a node name. serv Pointer to a buffer in which to receive the null-terminated network service name associated with the port number contained in sa. A NULL pointer instructs the routine not to return a service name. The node parameter and serv parameter cannot both be zero. servlen Length of the serv buffer. A value of zero instructs the routine not to return a service name. flags Specifies changes to the routine's default actions. By default, the routine searches for the fully qualified domain name of the node in the host's database and returns it. The flag bits and their meanings follow: NI_DGRAM Specifies that the service is a datagram service (SOCK_DGRAM). The default assumes a stream service (SOCK_STREAM). This is required for the few ports (512-514) that have different services for UDP and TCP. NI_NAMEREQD Returns an error if the host name cannot be located in the host's database. NI_NOFQDN Searches the host's database and returns the node name portion of the fully qualified domain name for local hosts. NI_NUMERICHOST Returns the numeric form of the host's address instead of its name. Resolution of the host name is not performed. NI_NUMERICSERV Returns the numeric form (port number) of the service address instead of its name. Resolution of the host name is not performed. The two NI_NUMERIC* flags are required to support the -n flag that many commands provide. All flags are defined in the header file. 4 Description The getnameinfo routine looks up an IP address and port number in a sockaddr structure specified by sa and returns node name and service name text strings in the buffers pointed to by the node and serv parameters, respectively. If the node name is not found, the routine returns the numeric form of the node address, regardless of the value of the flags parameter. If the service's name is not found, the routine returns the numeric form of the service's address (port number) regardless of the value of the flags parameter. The application must provide buffers large enough to hold the fully qualified domain name and the service name, including the terminating null characters. 4 Return_Values 0 Indicates successful completion. nonzero Indicates failure. 3 getnetbyaddr Searches the network database sequentially from the beginning of the database for a network record with a given address. Format #include struct netent *getnetbyaddr (long net, int type); 4 Arguments net The network number, in host byte order, of the network database entry required. type The type of network sought. Currently, only AF_INET (defined in ) is supported. 4 Description This routine finds the first network record in the network database with the given address. The getnetent, getnetbyaddr, and getnetbyname routines all use a common static area for their return values. This means that subsequent calls to any of these routines will overwrite any existing network entry. You must make a copy of the network entry if you wish to save it. 4 Return_Values NULL Indicates EOF or an error. x A pointer to an object having the netent structure. See the header file for a description of the netent structure. 3 getnetbyname Searches the network database sequentially from the beginning of the database for a network record with a given name or alias. Format #include struct netent *getnetbyname (char *name); 4 Argument name A pointer to a null-terminated character string of the name or an alias of the network sought. 4 Description This routine finds the first host in the network database with the given name or alias. The getnetent, getnetbyaddr, and getnetbyname routines all use a common static area for their return values. This means that subsequent calls to any of these routines will overwrite any existing network entry. You must make a copy of the network entry if you wish to save it. 4 Return_Values NULL Indicates EOF or an error; errno is set to EFAULT (The buffer described by name is not a valid, writable part of the user address space.) x A pointer to an object having the netent structure. See the header file for a description of the netent structure. Depending on the error condition and the socket implementation selected, errno or h_ errno might be set to further indicate the error. 3 getnetent Gets a network file entry from the networks database file. Format #include struct netent *getnetnet (void); 4 Description The getnetent routine opens and sequentially reads the networks database file to retrieve network information. See the header file for a description of the netent structure. The getnetent routine uses a common static area for its return values, so subsequent calls to this routine overwrite any existing network entry. You must make a copy of the network services entry, if you wish to save it. See also setnetent, and endnetent. 4 Return_Values x A pointer to a netent structure. 0 Indicates an error or EOF. 3 getpeername Returns the name of the connected peer. Format #include int getpeername (int s, struct sockaddr *name, int *namelen); (_DECC_V4_SOURCE) int getpeername (int s, struct sockaddr *name, size_t *namelen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_getpeername. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. 4 Arguments s A socket descriptor that has been created using socket. name A pointer to a buffer within which the peer name is to be returned. namelen An address of an integer that specifies the size of the name buffer. On return, it will be modified to reflect the actual length, in bytes, of the name returned. 4 Description This routine returns the name of the peer connected to the socket descriptor specified. See also bind, getsockname, and socket. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o ENOTCONN - The socket is not connected. o ENOBUFS - Resources were insufficient in the system to perform the operation. o EFAULT - The name parameter is not a valid part of the user address space. 3 getprotobyname Searches the protocols database until a matching protocol name is found or until EOF is encountered. Format #include struct protoent *getprotobyname (char *name); 4 Argument name A pointer to a string containing the desired protocol name. 4 Description This routine returns a pointer to a protoent structure containing the broken-out fields of the requested line from the protocols database. See the header file for a description of the protoent structure. See also getprotoent and getprotobynumber. 4 Return_Values NULL Indicates EOF or an error. x A pointer to a protoent structure. 3 getprotobynumber Searches the protocols database until a matching protocol number is found or until an EOF is encountered. Format #include struct protoent *getprotobynumber (int *proto); 4 Argument proto A pointer to a string containing the desired protocol number. 4 Description This routine returns a pointer to a protoent structure containing the broken-out fields of the requested line from the protocols database. See the header file for a description of the protoent structure. See also getprotoent and getprotobyname. 4 Return_Values NULL Indicates EOF or an error. x A pointer to a protoent structure. 3 getprotoent Gets a protocol database entry from the protocols database file. Format #include struct protoent *getprotoent (void); 4 Description The getprotoent routine reads the next entry of the database, opening a connection to the database, if necessary. See the header file for a description of the protoent structure. See also getprotobyname, getprotobynumber, setprotoent, and endprotoent. 4 Return_Values x A pointer to a protoent structure. NULL Indicates an error or EOF. 3 getservbyname Gets information on the named service from the network services database. Format #include struct servent *getservbyname (char *name, char *proto); 4 Arguments name A pointer to a string containing the name of the service about which information is required. proto A pointer to a string containing the name of the protocol to search for. 4 Description This routine searches sequentially from the beginning of the file until a matching service name is found, or until an EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol. This routine returns a pointer to a servent structure containing the broken-out fields of the requested line in the network services database. See the header file for a description of the servent structure. All information is contained in a static area, so it must be copied if it is to be saved. See also getservbyport. 4 Return_Values NULL Indicates EOF or an error. x A pointer to a servent structure. 3 getservbyport Gets information on the specified port from the network services database. Format #include struct servent *getservbyport (int port, char *proto); 4 Arguments port The port number to search for. proto A pointer to a string containing the name of the protocol to search for. 4 Description This routine searches sequentially from the beginning of the file until a matching port is found, or until an EOF is encountered. If a protocol name is also supplied (non-NULL), searches must also match the protocol. This routine returns a pointer to a servent structure containing the broken-out fields of the requested line in the network services database. See the header file for a description of the servent structure. All information is contained in a static area, so it must be copied if it is to be saved. See also getservbyname. 4 Return_Values NULL Indicates EOF or an error. x A pointer to a servent structure. 3 getservent Gets a services file entry from the network services database file. Format #include struct servent *getservent (void); 4 Description The getservent routine reads the next line of the network services database file, opening a connection to the database, if necessary. This routine returns a servent structure that contains fields for a line of information from the network services database file. See the header file for a description of the hostent structure. This routine uses a common static area for its return values, so subsequent calls to this routine overwrite any existing network entry. You must make a copy of the network services entry, if you wish to save it. See also setservent, and endservent. 4 Return_Values x A pointer to a servent structure. NULL Indicates an error or EOF. 3 getsockname Returns the name associated with a socket. Format #include int getsockname (int s, struct sockaddr *name, int *namelen); (_DECC_V4_SOURCE) int getsockname (int s, struct sockaddr *name, size_t *namelen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_getsockname. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. 4 Arguments s A socket descriptor created with socket and bound to the socket name with bind. name A pointer to the buffer in which getsockname should return the socket name. namelen A pointer to an integer specifying the size of the buffer pointed to by name. On return, the integer contains the actual size of the name returned, in bytes. 4 Description This routine returns the current name for the specified socket descriptor. The name is a format specific to the address family (AF_INET) assigned to the socket. bind makes the association of the name to the socket, not getsockname. See also bind and socket. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o ENOBUFS - Resources were insufficient in the system to perform the operation. o EFAULT - The name parameter is not a valid part of the user address space. 3 getsockopt Returns the options set on a socket. Format #include int getsockopt (int s, int level, int optname, char *optval, int *optlen); (_DECC_V4_SOURCE) int getsockopt (int s, int level, int optname, void *optval, size_t *optlen); (not _DECC_V4_SOURCE) 4 Arguments s A socket descriptor created by socket. level The protocol level for which the socket options are desired. It may have one of the following values: SOL_SOCKET Get the options at the socket level. p Any protocol number. Get the options for protocol level p. See the file for the various IPPROTO values. optname Is interpreted by the protocol that is specified in the level. Options at each protocol level are documented with the protocol. See setsockopt for socket level options. optval Points to a buffer in which the value of the specified option should be placed by getsockopt. optlen Points to an integer containing the size of the buffer pointed to by optval. On return, the integer will be modified to contain the actual size of the option value returned. 4 Description This routine gets information on socket options. See the appropriate protocol for information on available options at each protocol level. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o ENOPROTOOPT - The option is unknown or the protocol is unsupported. 3 herror Writes a message to standard error explaining h_error. Format #include void herror (const char *string); 4 Arguments string A user-printable string. 4 Description The herror routine maps the error number in the external variable h_errno to a locale-dependent error message. 3 hstrerror Returns an error message string. Format #include char *hstrerror (int errnum); 4 Arguments errnum An error number specifying a value of h_errno. 4 Description The hstrerror routine maps the error number specified by the errnum parameter to a locale-dependent error message string and returns a pointer to the string. The string pointed to by the return value cannot be modified by the program, but could be overwritten by subsequent calls to this routine. 4 Return_Values x A pointer to the generated message string. -1 On error, errno might be set, but no return value is reserved to indicate an error. 4 Errors If the hstrerror routine fails, errno is set to one of the following values: o EINVAL - The errnum parameter is an invalid error number. 3 hostalias Searches for host aliases associated with a name. Format #include char *hostalias (const char *name); 4 Arguments name Points to the name of the host that you want to retrieve aliases from. 4 Description The hostalias routine searches for the alias associated with the name parameter. The HOSTALIASES environment variable defines the name of a file where you can find the host aliases, in the form: host alias 4 Return_Values x The host alias. NULL Indicates an error. 3 htonl Converts longwords from host to network byte order. Format #include unsigned long int htonl (unsigned long int hostlong); 4 Argument hostlong A longword in host (VAX system) byte order. All integers on VAX systems are in host byte order unless otherwise specified. 4 Description This routine converts 32-bit unsigned integers from host byte order to network byte order. The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host. The host byte order on VAX systems differs from the network order. This routine is most often used with Internet addresses and ports as returned by gethostent and getservent, and when manipulating values in the structures. Network byte-order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address. 4 Return_Value x A longword in network byte order. 3 htons Converts short integers from host to network byte order. Format #include unsigned short int htons (unsigned short int hostshort); 4 Argument hostshort A short integer in host (VAX system) byte order. All short integers on VAX systems are in host byte order unless otherwise specified. 4 Description This routine converts 16-bit unsigned integers from host byte order to network byte order. The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host. The host byte order on VAX systems differs from the network order. This routine is most often used with Internet addresses and ports as returned by gethostent and getservent, and when manipulating values in the structures. Network byte order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address. 4 Return_Value x A short integer in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems. 3 if_freenameindex IPv6 socket routine Frees dynamic memory allocated by the if_nameindex routine to the array of interface names and indexes. Format #include void if_freenameindex (struct if_nameindex *ptr); 4 Argument ptr A pointer that was returned by the if_nameindex routine. 4 Description This routine frees dynamic memory allocated by the if_nameindex routine. The argument to if_freenameindex is the pointer returned by if_nameindex. 3 if_indextoname IPv6 socket routine Maps an interface index to its corresponding name. Format #include void if_indextoname (unsigned int ifindex, char *ifname); 4 Argument ifname Pointer to a buffer that is IFNAMSIZ bytes long. 4 Description The ifname argument points to a buffer that is IFNAMSIZ bytes in length (IFNAMSIZ is defined in TCPIP$EXAMPLES:IF.H). If an interface name is found, it is returned in the buffer. If no interface name corresponds to the specified index, the function returns NULL and sets errno to ENXIO. If a system error occurs, the function returns NULL and sets errno to an appropriate value. 3 if_nameindex IPv6 socket routine Returns an array of all interface names and indexes. Format #include struct if_nameindex *if_nameindex (void); 4 Description The following if_nameindex structure must also be defined (by including (TCPIP$EXAMPLES:IF.H) prior to the call to if_nameindex : struct if_nameindex { unsigned int if_index; char *if_name; }; The if_nameindex routine dynamically allocates memory for an array of if_nameindex structures, one structure for each interface. A structure with an if_index value of 0 and a NULL if_name value indicates the end of the array. If an error occurs, the function returns a NULL pointer and sets errno to an appropriate value. To free the memory allocated by this function, use the if_freenameindex function. 4 Return_Values NULL Indicates an error; errno is set to an appropriate value. 3 if_nametoindex IPv6 socket routine Maps an interface name to its corresponding index. Format #include unsigned int if_nametoindex (const char *ifname); 4 Description If the interface does not exist, the function returns 0 and sets errno to ENXIO. If a system error occurs, the function returns 0 and sets errno to an appropriate value. 4 Return_Values 0 The interface does not exist and errno is set to ENXIO, OR A system error occurred and errno is set to an appropriate value. 3 inet_addr Converts Internet addresses in text form into numeric (binary) Internet addresses. Format #include #include int inet_addr (char *cp); 4 Argument cp A pointer to a null-terminated character string containing an Internet address in the standard Internet "." format. 4 Description This routine returns an Internet address in network byte order when given as its argument an ASCIZ (null-terminated) string representing the address in the Internet standard "." notation. Internet addresses specified using the "." notation take one of the following forms: a.b.c.d a.b.c a.b a When four parts are specified, each is interpreted as a byte of data and assigned, from left to right, to the four bytes of an Internet address. Note that when an Internet address is viewed as a 32-bit integer quantity on VAX systems, the bytes previously referred to appear in binary as "d.c.b.a". That is, VAX bytes are ordered from least significant to most significant. When only one part is given, the value is stored directly in the network address without any byte rearrangement. All numbers supplied as "parts" in a "." address expression may be decimal, octal, or hexadecimal, as specified in the C language (that is, a leading 0x or 0X implies hexadecimal; a leading 0 implies octal; otherwise, the number is interpreted as decimal). 4 Return_Values -1 Indicates that cp does not point to a proper Internet address. x An Internet address in network byte order. 3 inet_lnaof Returns the local network address portion of an Internet address. Format #include #include int inet_lnaof (struct in_addr in); 4 Argument in An Internet address. 4 Description This routine returns the local network address (LNA) portion of a full Internet address. 4 Return_Value x The LNA portion of an Internet address in host byte order. 3 inet_makeaddr Returns an Internet address given a network address and a local address on that network. Format #include #include struct in_addr inet_makeaddr (int net, int lna); 4 Arguments net An Internet network address in host byte order. lna A local network address on network net in host byte order. 4 Description This routine combines the net and lna arguments into a single Internet address. 4 Return_Value x An Internet address in network byte order. 3 inet_netof Returns the Internet network address portion of an Internet address. Format #include #include int inet_netof (struct in_addr in); 4 Argument in An Internet address. 4 Description This routine returns the Internet network address (NET) portion of a full Internet address. 4 Return_Value x The Internet network portion of an Internet address in host byte order. 3 inet_network Converts a text string representing an Internet network address in the standard Internet "." notation into an Internet network address as machine-format integer values. Format #include #include int inet_network (char *cp); 4 Argument cp A pointer to an ASCIZ (null-terminated) character string containing a network address in the standard Internet "." format. 4 Description This routine returns an Internet network address as machine- format integer values when given as its argument an ASCIZ string representing the address in the Internet standard "." notation. 4 Return_Values -1 Indicates that cp does not point to a proper Internet network address. x An Internet network address as machine-format integer values. 3 inet_ntoa Converts an Internet address into a text string representing the address in the standard Internet "." notation. Format #include #include char *inet_ntoa (struct in_addr in); 4 Argument in An Internet address in network byte order. 4 Description This routine converts an Internet address into an ASCIZ (null- terminated) string representing that address in the standard Internet "." notation. WARNING Arguments should not be passed as integers because of how Compaq C handles struct arguments. Because the string is returned in a static buffer that will be overwritten by successive calls to inet_ntoa, it is recommended to copy the string to a safe place. 4 Return_Value x A pointer to a string containing the Internet address in "." notation. 3 inet_ntop IPv6 socket routine. Converts a numeric address to a text string suitable for presentation. The routine converts both IPv4 and IPv6 addresses. Format const char *inet_ntop(int af, const void *src, char *dst, size_t size); 4 Arguments af Specifies the address family. Valid values are AF_INET for an IPv4 address and AF_INET6 for an IPv6 address. src Points to a buffer that contains the numeric Internet address. dst Points to a buffer that is to contain the text string. size Specifies the size of the buffer pointed to by the dst parameter. For IPv4 addresses, the minimum buffer size is 16 octets; for IPv6 addresses, the minimum buffer size is 46 octets. The header file defines the INET_ADDRSTRLEN and INET6_ADDRSTRLEN constants, respectively, for these values. 4 Description IPv6 socket routine This routine converts a numeric Internet address value to a text string. 4 Return_Values ptr Upon successful conversion, the inet_ntop function returns a pointer to the buffer containing the text string. If the function fails, it returns a pointer to the buffer containing NULL. 3 inet_pton IPv6 socket routine. Converts a numeric address to a text string suitable for presentation. The routine converts both IPv4 and IPv6 addresses. Format int inet_pton (int af, const char *src, void *dst); 4 Arguments af Specifies the address family. Valid values are AF_INET for an IPv4 address and AF_INET6 for an IPv6 address. src Pointer to the address text string to be converted. dst Pointer to a buffer that is to contain the numeric address. 4 Description IPv6 socket routine This routine converts a text string to a numeric value in Internet network byte order. o If the af parameter is AF_INET, the function accepts a string in the standard IPv4 dotted-decimal format: ddd.ddd.ddd.ddd In this format, ddd is a one- to three-digit decimal number between 0 and 255. o If the af parameter is AF_INET6, the function accepts a string in the following format: x:x:x:x:x:x:x:x In this format, x is the hexadecimal value of a 16-bit piece of the address. IPv6 addresses can contain long strings of zero bits. To make it easier to write these addresses, you can use double-colon characters (::) one time in an address to represent one or more 16-bit groups of zeros. o For mixed IPv4 and IPv6 environments, the following format is also accepted: x:x:x:x:x:x:ddd.ddd.ddd.ddd In this format, x is the hexadecimal value of a 16-bit piece of the address, and ddd is a one- to three-digit decimal value between 0 and 255 that represents the IPv4 address. The calling application is responsible for ensuring that the buffer referred to by the dst parameter is large enough to hold the numeric address. AF_INET addresses require 4 bytes and AF_INET6 addresses require 16 bytes. 4 Return_Values 1 Indicates successful completion. 0 Indicates the input string is neither a valid IPv4 dotted-decimal string nor a valid IPv6 address string. errno is set to EAFNOSUPPORT, and the address family specified in the af argument is unknown. -1 Indicates any other error. errno is set to EAFNOSUPPORT, and the address family specified in the af argument is unknown. 3 ioctl Controls socket operations only. Format #include int ioctl (int d, unsigned long request, void *arg); 4 Arguments d Specifies the file descriptor of the requested device. request Specifies the ioctl command performed on the device. arg Specifies parameters for this request. The type of arg is dependent on the specific ioctl request and device to which the ioctl is targeted. 4 Description The ioctl routine performs a variety of operations on sockets. An ioctl request has encoded in it, whether the parameter is an "in" parameter or "out" parameter, and the size of the arg parameter in bytes. The ioctl request is defined in the header file. 4 Return_Values 0 Indicates success. -1 Indicates an error; further specified in the global errno. 4 Errors If the ioctl routine fails, errno is set to one of the following values: o EBADF - The d parameter is not a valid descriptor. o ENOTTY - The d parameter is not associated with a character special device, or the specified request does not apply to the kind of object that the d parameter references. o EINVAL - Either the request or the arg parameter is not valid. 3 listen Sets the maximum limit of outstanding connection requests for a socket that is connection-oriented. Format int listen (int s, int backlog); 4 Arguments s A socket descriptor of type SOCK_STREAM that has been created using socket. backlog The maximum number of pending connections that may be queued on the socket at any given time. The maximum cannot exceed 5. 4 Description This routine creates a queue for pending connection requests on socket s with a maximum size of backlog. Connections may then be accepted with accept. If a connection request arrives with the queue full (more than backlog connection requests pending), the client will receive a timeout. See also accept, connect, and socket. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EOPNOTSUPP - The socket is not of a type that supports the operation listen. 3 ntohl Converts longwords from network to host byte order. Format #include unsigned long int ntohl (unsigned long int netlong); 4 Argument netlong A longword in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems. 4 Description This routine converts 32-bit unsigned integers from network byte order to host byte order. The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host. The host byte order on VAX systems differs from the network order. This routine is most often used with Internet addresses and ports as returned by gethostent and getservent, and when manipulating values in the structures. Network byte order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address. 4 Return_Value x A longword in host byte order. 3 ntohs Converts short integers from network to host byte order. Format #include unsigned short int ntohs (unsigned short int netshort); 4 Argument netshort A short integer in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems. 4 Description This routine converts 16-bit unsigned integers from network byte order to host byte order. The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host. The host byte order on VAX systems differs from the network order. This routine is most often used with Internet addresses and ports as returned by gethostent and getservent, and when manipulating values in the structures. Network byte order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address. 4 Return_Value x A short integer in host (VAX) byte order. 3 read Reads bytes from a socket or file and places them in a buffer. Format #include int read (int d, void *buffer, int nbytes); 4 Arguments d A descriptor that must refer to a socket or file currently opened for reading. buffer The address of contiguous storage in which the input data is placed. nbytes The maximum number of bytes involved in the read operation. 4 Description If the end-of-file is not reached, the read routine returns nbytes. If the end-of-file occurs during the read routine, it returns the number of bytes read. Upon successful completion, read returns the number of bytes actually read and placed in the buffer. See also socket. 4 Return_Values x The number of bytes read and placed in the file. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o EFAULT - The buffer points outside the allocated address space. o EINVAL - The nbytes argument is negative. o EWOULDBLOCK - The NBIO socket option (nonblocking) flag is set for the socket or file descriptor and the process would be delayed in the read operation. 3 recv Receives bytes from a connected socket and places them into a buffer. Format #include int recv (int s, char *buf, int len, int flags); (_DECC_V4_SOURCE) ssize_t recv (int s, void *buf, size_t len, int flags); (not _DECC_V4_SOURCE) 4 Arguments s A socket descriptor that was created as the result of a call to accept or connect. buf A pointer to a buffer into which received data will be placed. len The size of the buffer pointed to by buf. flags A bit mask that may contain one or more of MSG_OOB and MSG_PEEK. It is built by ORing the appropriate values together. The MSG_OOB flag allows out-of-band data to be received. If out- of-band data is available, it will be read before any other data that is available. If no out-of-band data is available, the MSG_ OOB flag is ignored. Out-of-band data can be sent using send, sendmsg, and sendto. The MSG_PEEK flag allows you to peek at the data that is next in line to be received without removing it from the system's buffers. 4 Description This routine receives data from a connected socket. To receive data on an unconnected socket, use the recvfrom or recvmsg routines. The received data is placed in the buffer buf. Data is sent by the socket's peer using the send, sendmsg, or sendto routines. You may use the select routine to determine when more data arrives. If no data is available at the socket, the receive call waits for data to arrive, unless the socket is nonblocking in which case a -1 is returned with the external variable errno set to EWOULDBLOCK. See also read, send, sendmsg, sendto, and socket. 4 Return_Values x The number of bytes received and placed in buf. 0 Indicates that a connection is broken or reset by its peer. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The descriptor references a file, not a socket. o EPIPE - An attempt was made to write to a socket that is not open for reading by any process. o EWOULDBLOCK - The NBIO socket option (nonblocking) flag is set for the socket or file descriptor and the process would be delayed in the read operation. o EFAULT - The data was specified to be received into a non-existent or protected part of the process address space. 3 recvfrom Receives bytes from a socket from any source. Format #include int recvfrom (int s, char *buf, int len, int flags, struct sockaddr *from, int *fromlen) ; (_DECC_V4_SOURCE) ssize_t recvfrom (int s, void *buf, size_t len, int flags, struct sockaddr *from, size_t *fromlen) ; (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_recvfrom. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been created with socket and bound to a name using bind or as a result of accept. buf A pointer to a buffer into which received data will be placed. len The size of the buffer pointed to by buf. flags A bit mask that may contain one or more of MSG_OOB and MSG_PEEK. It is built by ORing the appropriate values together. The MSG_OOB flag allows out-of-band data to be received. If out- of-band data is available, it will be read before any other data that is available. If no out-of-band data is available, the MSG_ OOB flag is ignored. Out-of-band data can be sent using send, sendmsg, and sendto. The MSG_PEEK flag allows you to peek at the data that is next in line to be received without actually removing it from the system's buffers. from If from is nonzero, from is a buffer into which recvfrom places the address (structure) of the socket from which the data is received. If from was 0, the address will not be returned. fromlen Points to an integer containing the size of the buffer pointed to by from. On return, the integer is modified to contain the actual length of the socket address structure returned. 4 Description This routine allows a named, unconnected socket to receive data. The data is placed in the buffer pointed to by buf, and the address of the sender of the data is placed in the buffer pointed to by from if from is non-NULL. The structure that from points to is assumed to be as large as the sockaddr structure. See for a description of the sockaddr structure. To receive bytes from any source, the sockets need not be connected to another socket. You may use the select routine to determine if data is available. If no data is available at the socket, the recv call waits for data to arrive, unless the socket is nonblocking, in which case a -1 is returned with the external variable errno set to EWOULDBLOCK. See also read, send, sendmsg, sendto, and socket. 4 Return_Values x The number of bytes of data received and placed in buf. -1 Indicates an error; errno is set to one of the following values: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EPIPE - An attempt was made to write to a socket that is not open for reading by any process. o EWOULDBLOCK - The NBIO (nonblocking) flag is set for the socket descriptor and the process would be delayed in the write operation. o EFAULT - The data was specified to be received into a non-existent or protected part of the process address space. 3 recvmsg Receives bytes on a socket and places them into scattered buffers.. Format #include int recvmsg (int s, struct msghdr msg[], int flags); 4 Routine_Variants This socket routine has a variant named __bsd44_recvmsg. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been created with socket. msg A msghdr structure. See for a description of the msghdr structure. flags A bit mask that may contain one or more of MSG_OOB and MSG_PEEK. It is built by ORing the appropriate values together. The MSG_OOB flag allows out-of-band data to be received. If out- of-band data is availiable, it will be read before any normal data that is available. If no out-of-band data is available, the MSG_OOB flag is ignored. Out-of-band data can be sent using send, sendmsg, and sendto. The MSG_PEEK flag allows you to peek at the data that is next in line to be received without actually removing it from the system's buffers. 4 Description This routine may be used with any socket, whether it is in a connected state or not. It receives data sent by a call to sendmsg, send, or sendto. The message is scattered into several user buffers if such buffers are specified. To receive data, the socket need not be connected to another socket. When the iovec[iovcnt] array specifies more than one buffer, the input data is scattered into iovcnt buffers as specified by the members of the iovec array: iov[0], iov[1], ..., iov[iovcnt] When a message is received, it is split among the buffers by filling the first buffer in the list, then the second, and so on, until either all of the buffers are full or there is no more data to be placed in the buffers. When a message is sent, the first buffer is copied to a system buffer and then the second buffer is copied, followed by the third buffer and so on, until all the buffers are copied. After the data is copied, the protocol will send the data to the remote host at the appropriate time, depending upon the protocol. You may use the select routine to determine when more data arrives. See also read, send, and socket. 4 Return_Values x The number of bytes returned in the msg_iov buffers. -1 Indicates an error; errno is set to one of the following values: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o EPIPE - An attempt was made to write to a socket that is not open for reading by any process. o EWOULDBLOCK - The NBIO (nonblocking) flag is set for the socket descriptor and the process would be delayed in the write operation. o EINTR - The receive was interrupted by delivery of a signal before any data was available for the receive. o EFAULT - The data was specified to be received into a non-existent or protected part of the process address space. 3 select Allows the user to poll or check a group of sockets for I/O activity. It can check what sockets are ready to be read or written, or what sockets have a pending exception. As of OpenVMS Version 7.0, this routine can operate on any number of sockets up to the limit of open files supported by the Compaq C RTL (65535 on OpenVMS Alpha; 2047 on OpenVMS VAX). However, for select to use more than 32 sockets, the TCP/IP Services for OpenVMS used with the Compaq C RTL must offer the same support. Format #include int select (int nfds, int *readfds, int *writefds, int *exceptfds, struct timeval *timeout); (_DECC_V4_SOURCE) int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); (not _DECC_V4_SOURCE) 4 Arguments nfds The highest numbered socket descriptor to search for. That is, the highest numbered bit + 1 in readfds, writefds, and exceptfds that should be examined. Descriptor s is represented by 1<< s (1 shifted to the left s number of times). NOTE You must increase the value of FD_SETSIZE if your application will use more sockets in the call to select than the value of FD_SETSIZE in the or header files. Do this by defining a larger value for FD_SETSIZE within the application before including or . readfds A pointer to an array of bits, organized as integers (each integer describing 32 descriptors), that should be examined for read readiness. If bit n of the longword is set, socket descriptor n will be checked to see if it is ready to be read. All bits set in the bit mask must correspond to the file descriptors of sockets. The select routine cannot be used on normal files. On return, the array of bits to which readfds points contains a bit mask of the sockets that are ready for reading. Only bits that are set on entry to select will be set on exit. If this pointer is NULL, select ignores the array. writefds A pointer to a longword bit mask of the socket descriptors that should be examined for write readiness. If bit n of the longword is set, socket descriptor n will be checked to see if it is ready to be written to. All bits set in the bit mask must correspond to socket descriptors. On return, the array of bits that writefds points to contains a bit mask of the sockets that are ready for writing. Only bits that are set on entry to select will be set on exit. If this pointer is NULL, select ignores the array. exceptfds A pointer to a longword bit mask of the socket descriptors that should be examined for exceptions. If bit n of the longword is set, socket descriptor n will be checked to see if it has any pending exceptions. All bits set in the bit mask must correspond to the file descriptors of sockets. On return, the array of bits pointer exceptfds contains a bit mask of the sockets that have exceptions pending. Only bits that are set on entry to select will be set on exit. If this pointer is NULL, select ignores the array. timeout The length of time that select should examine the sockets before returning. If one of the sockets specified in the readfds, writefds, and exceptfds bit masks is ready for I/O, select will return before the timeout period has expired. The timeout structure points to a timeval structure. See for a description of the timeval structure. 4 Description This routine determines the I/O status of the sockets specified in the various mask arguments. It returns either when a socket is ready to be read or written, or when the timeout period expires. If timeout is a nonzero integer, it specifies a maximum interval to wait for the selection to complete. If the timeout argument is NULL, select will block indefinitely. In order to effect a poll, timeout should be non-NULL, and should point to a zero-valued structure. If a process is blocked on a select while waiting for input from a socket and the sending process closes the socket, the select notes this as an event and will unblock the process. The descriptors are always modified on return if select returns because of the timeout. When the socket option SO_OOBINLINE is set on the device_socket, a select on both read and exception events returns the socket mask set on both the read and exception mask. Otherwise, only the exception mask is set. NOTE Beginning with OpenVMS Version 7.2-1, the select function fails if one of the specified file descriptor sets contains an invalid file descriptor (errno is set to EBADF) or a file descriptor not associated with a socket (errno is set to ENOTSOCK). Previously, select set errno as described, but was otherwise ignoring invalid file descriptors and file descriptors not associated with sockets. To request this old behavior, define the logical name DECC$SELECT_IGNORES_INVALID_FD to any value before invoking the application. See also accept, connect, read, recv, recvfrom, recvmsg, send, sendmsg, sendto, and write. 4 Return_Values n The number of sockets that were ready for I/O or that had pending exceptions. This value matches the number of returned bits that are set in all output masks. 0 Indicates that select timed out before any socket became ready for I/O. -1 Indicates an error; errno is set to one of the following values: o EBADF - One of the bit masks specified an invalid descriptor. o EINVAL - The specified time limit is unacceptable. One of its components is negative or too large. o ENOTSOCK - A file descriptor not associated with a socket was found in one of the specified file descriptor sets. 3 send Sends bytes though a socket to its connected peer. Format #include int send (int s, char *msg, int len, int flags); (_DECC_V4_SOURCE) ssize_t send (int s, const void *msg, size_t len, int flags); (not _DECC_V4_SOURCE) 4 Arguments s A socket descriptor that was created with socket, and connected to another socket using accept or connect. msg A pointer to a buffer containing the data to be sent. len The length, in bytes, of the data pointed to by msg. flags May be either 0 or MSG_OOB. If it is equal to MSG_OOB, the data will be sent out-of-band. This means that the data can be received before other pending data on the receiving socket if the receiver also specifies a MSG_OOB in the flag parameter of the call. 4 Description This routine may only be used on connected sockets. To send data on an unconnected socket, use the sendmsg or sendto routines. The send routine passes data along to its connected peer, which may receive the data by using recv. If there is no space available to buffer the data being sent on the receiving end of the connection, send will normally block until buffer space becomes available. If the socket is defined as nonblocking, however, send will fail with an errno indication of EWOULDBLOCK. If the message is too large to be sent in one piece and the socket type requires that messages be sent atomically (using SOCK_DGRAM), send will fail with an errno indication of EMSGSIZE. No indication of failure to deliver is implicit in a send. All errors (except EWOULDBLOCK) are detected locally. You may use the select routine to determine when it is possible to send more data. See also read, recv, recvmsg, recvfrom, getsocketopt, and socket. 4 Return_Values n The number of bytes sent. This value will normally equal len. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The descriptor references a file, not a socket. o EFAULT - An invalid user space address was specified for a parameter. o EMSGSIZE -The socket requires that messages be sent atomically, and the size of the message to be sent made this impossible. o EWOULDBLOCK - Blocks if the system does not have enough space for buffering the user data. 3 sendmsg Sends gathered bytes through a socket to any other socket. Format #include int sendmsg (int s, struct msghdr msg[], int flags); 4 Routine_Variants This socket routine has a variant named __bsd44_sendmsg. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been created with socket. msg A pointer to a msghdr structure containing the message to be sent. See for a description of the msghdr structure. The msg_iov field of the msghdr structure is used as a series of buffers from which data is read in order until msg_iovlen bytes have been obtained. flags May be either 0 or MSG_OOB. If it is equal to MSG_OOB, the data will be sent out-of-band. This means that the data can be received before other pending data on the receiving socket if the receiver also specifies a flag of MSG_OOB. 4 Description This routine may be used on any socket to send data to any named socket. The data in the msg_iovec field of the msg structure is sent to the socket whose address is specified in the msg_name field of the structure. The receiving socket gets the data using either the read, recv, recvfrom, or recvmsg routine. When the iovec array specifies more than one buffer, the data is gathered from all specified buffers before being sent. See for a description of the iovec structure. If there is no space available to buffer the data being sent on the receiving end of the connection, sendmsg will normally block until buffer space becomes available. If the socket is defined as nonblocking, however, sendmsg will fail with an errno indication of EWOULDBLOCK. If the message is too large to be sent in one piece and the socket type requires that messages be sent atomically (SOCK_DGRAM), sendmsg will fail with an errno indication of EMSGSIZE. If the address specified is a INADDR_BROADCAST address, then the SO_BROADCAST option must be set and the process must have SYSPRV or BYPASS privilege for the I/O operation to succeed. No indication of failure to deliver is implicit in a sendmsg. All errors (except EWOULDBLOCK) are detected locally. You may use the select routine to determine when it is possible to send more data. See also read, recv, recvfrom, recvmsg, socket, getsockopt. 4 Return_Values n The number of bytes sent. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The descriptor references a file, not a socket. o EFAULT - An invalid user space address was specified for a parameter. o EMSGSIZE -The socket requires that messages be sent atomically, and the size of the message to be sent made this impossible. o EWOULDBLOCK - Blocks if the system does not have enough space for buffering the user data. 3 sendto Sends bytes through a socket to any other socket. Format #include int sendto (int s, char *msg, int len, int flags, struct sockaddr *to, int tolen); (_DECC_V4_SOURCE) ssize_t sendto (int s, const void *msg, size_t len, int flags, const struct sockaddr *to, size_t tolen); (not _DECC_V4_SOURCE) 4 Routine_Variants This socket routine has a variant named __bsd44_sendto. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD- compatible semantics. 4 Arguments s A socket descriptor that has been created with socket. msg A pointer to a buffer containing the data to be sent. len The length of the data pointed to by msg. flags May be either 0 or MSG_OOB. If it is equal to MSG_OOB, the data will be sent out-of-band. This means that the data can be received before other pending data on the receiving socket if the receiver also specifies a MSG_OOB in its flag parameter of the call. to Points to the address structure of the socket to which the data is to be sent. tolen The length of the address structure to points to. 4 Description This routine may be used on any socket to send data to any named socket. The data in the msg buffer is sent to the socket whose address is specified in to, and the address of socket s is provided to the receiving socket. The receiving socket gets the data using either the read, recv, recvfrom, or recvmsg routine. If there is no space available to buffer the data being sent on the receiving end of the connection, sendto will normally block until buffer space becomes available. If the socket is defined as nonblocking, however, sendto will fail with an errno indication of EWOULDBLOCK. If the message is too large to be sent in one piece and the socket type requires that messages be sent atomically (using SOCK_DGRAM), sendto will fail with an errno indication of EMSGSIZE. No indication of failure to deliver is implicit in a sendto. All errors (except EWOULDBLOCK) are detected locally. You may use the select routine to determine when it is possible to send more data. If the address specified is a INADDR_BROADCAST address, then the SO_BROADCAST option must be set and the process must have SYSPRV or BYPASS privilege for the I/O operation to succeed. See also read, recv, recvfrom, recvmsg, socket, and getsockopt. 4 Return_Values n The number of bytes sent. This value will normally equal len. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The descriptor references a file, not a socket. o EFAULT - An invalid user space address was specified for a parameter. o EMSGSIZE -The socket requires that messages be sent atomically, and the size of the message to be sent made this impossible. o EWOULDBLOCK - Blocks if the system does not have enough space for buffering the user data. 3 sethostent Opens and rewinds the network host database file. Format #include void sethostent (int stay_open); 4 Arguments stay_open Specifies a value used to indicate when to close the host database file: o 0 (zero) to close the host database file after each call to the gethostbyname or gethostbyaddr routine. o nonzero to keep the host database file open after each call. 4 Description The sethostent routine opens or rewinds the network host database file and resets the file marker to the beginning of the file. Passing a nonzero value to the stay_open parameter keeps the connection open until the endhostent or exit routine is called. See also endhostent. 3 setnetent Opens and rewinds the networks database file. Format #include void setnetent (int stay_open); 4 Arguments stay_open Specifies a value used to indicate when to close the networks database file: o 0 (zero) to close the networks database file after each call to the getnetent. o nonzero to keep the networks database file open after each call. 4 Description The setnetent routine opens the networks database file and resets the file marker to the beginning of the file. Passing a nonzero value to the stay_open parameter keeps the connection open until you call the endnetent or exit routine. See also endnetent, getnetent, and exit. 3 setprotoent Opens, rewinds, or closes the protocols database file. Format #include void setprotoent (int stay_open); 4 Arguments stay_open Specifies a value used to indicate when to close the protocols database file: o 0 (zero) to close the host database file after each call to the getprotoent routine. o nonzero to keep the host database file open after each call. 4 Description The setprotoent routine opens, or rewinds the protocols database file and sets the file marker to the beginning of the file. Passing a nonzero value to the stay_open parameter keeps the connection open until you call the endprotoent, or exit routine. See also endprotoent, exit, and getprotoent. 4 Return_Values 1 Indicates success. 0 Indicates an error; unable to open the protocols database file. 4 Errors If the setprotoent routine fails, the error is further specified in the global errno. 3 setservent Opens and rewinds the network services database file. Format #include void setservent (int stay_open); 4 Arguments stay_open Specifies a value used to indicate when to close the network services database file: o 0 (zero) to close the network services database file after each call to the getservent routine. o nonzero to keep the network services database file open after each call to getservent. 4 Description The setservent routine opens the network services database file and resets the file marker to the beginning of the file. Passing a nonzero value to the stay_open parameter keeps the connection open until you call the endservent, or exit routine. See also endservent, exit, and getservent. 3 setsockopt Sets options on a socket. Format #include int setsockopt (int s, int level, int optname, char *optval, int optlen); (_DECC_V4_SOURCE) int setsockopt (int s, int level, int optname, const void *optval, size_t optlen); (not _DECC_V4_SOURCE) 4 Arguments s A socket descriptor created by socket. level The protocol level for which the socket options are to be modified. It may have one of the following values: SOL_SOCKET Set the options at the socket level. p Any protocol number. Set the options for protocol level p. See the header file for the various IPPROTO values. optname Is interpreted by the protocol specified in level. Options at each protocol level are documented with the protocol. The following options are available at the socket level: SO_REUSEADDR indicates the rules used in validating addresses supplied in a bind call should allow reuse of local addresses. SO_KEEPALIVE keeps connections alive by enabling the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken and processes using the socket are notified through an EPIPE error. SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address. SO_LINGER delays the internal socket deletion portion of close until either the data has been transmitted, or the device times out (approximately eight minutes). SO_BROADCAST is used to enable or disable broadcasting on the socket. optval Points to a buffer containing the parameters of the specified option. All socket level options other than SO_LINGER take an integer parameter that should be nonzero if the option is to be enabled, or zero if it is to be disabled. SO_LINGER uses a linger structure parameter defined in the file. This structure specifies the desired state of the option and the linger interval. The option value for the SO_LINGER command is the address of a linger structure. See the header file for a description of the linger structure. If the socket promises reliable delivery of data and l_onoff is nonzero, the system will block the process on the close attempt until it is able to transmit the data or until it decides it is unable to deliver the information. A timeout period, called the linger interval, is specified in l_linger. If l_onoff is set to 0 and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible. optlen An integer containing the size of the buffer pointed to by optval. 4 Description This routine manipulates options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level. When manipulating socket options, the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, specify level as SOL_ SOCKET. To manipulate options at any other level, the protocol number of the appropriate protocol controlling the option must be supplied. For example, to indicate an option is to be interpreted by the TCP protocol, level should be set to the protocol number (IPPROTO_TCP) of TCP. See for the various IPPROTO values. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The descriptor is invalid. o ENOTSOCK - The socket descriptor references a file, not a socket. o ENOTCONN - The socket is not connected. o ENOPROTOOPT - The option is unknown. o EFAULT - The optname parameter is not a valid part of the user address space. 3 shutdown Shuts down all or part of a bidirectional connection on a socket. It can disallow further receives, further sends, or both. Format #include int shutdown (int s, int how); 4 Arguments s A socket descriptor that is in a connected state as a result of a previous call to either connect or accept. how How the socket is to be shut down. Use one of the following values: 0 Disallows further calls to recv on the socket. 1 Disallows further calls to send on the socket. 2 Disallows further calls to both send and recv. 4 Description This routine allows communications on a socket to be shut down one piece at a time rather than all at once. It can be used to create unidirectional connections rather than the normal bidirectional (full-duplex) connections. See also connect and socket. 4 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following: o EBADF - The socket descriptor is invalid. o ENOTSOCK - The descriptor references a file, not a socket. o ENOTCONN - The specified socket is not connected. 3 socket Creates an endpoint for communication by returning a special kind of file descriptor called a socket descriptor, which is associated with a TCP/IP Services for OpenVMS Socket Device Channel. Format #include int socket (int af, int type, int protocol); 4 Arguments af The address format to be used in later references to the socket. Addresses specified in subsequent operations using the socket are interpreted according to this format. Currently, only AF_INET (Internet style) addresses are supported. type The semantics of communication. The type may be SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW. SOCK_STREAM type sockets provide sequenced, reliable, two-way connection based byte streams with an available out-of-band data transmission mechanism. SOCK_DGRAM sockets support datagrams (connectionless, unreliable data transmission mechanism). SOCK_RAW sockets provide access to internal network interfaces, and are available only to users with SYSPRV privilege. protocol The protocol to be used with the socket. Normally only a single protocol exists to support a particular socket type using a given address format. However, it is possible that many protocols may exist, in which case a particular protocol must be specified with this argument. The protocol number to use is particular to the communication domain in which communication is to take place. 4 Description This routine provides the primary mechanism for creating sockets. The type and protocol of the socket affect the way the socket behaves and how it can be used. The operation of sockets is controlled by socket-level options, defined in the file . The setsockopt and getsockopt calls are used to set and get options. Options other than SO_ LINGER take an integer parameter that should be nonzero if the option is to be enabled, or 0 if it is to be disabled. SO_LINGER uses a linger structure parameter defined in . The members of this structure specify the desired state of the option and the linger interval in the following manner: SO_REUSEADDR indicates that the rules used in validating addresses supplied in a bind call should allow reuse of local addresses. SO_KEEPALIVE keeps connections alive by enabling the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken and processes using the socket are notified through the error code SS$_LINKDISCON. SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address. SO_LINGER lingers on close if data is present. It controls the actions taken when unsent messages are queued on the socket and a close is performed. When using the setsockopt to set the linger values, the option value for the SO_LINGER command is the address of a linger structure: struct linger { int l_onoff; /* option on/off */ int l_linger; /* linger time */ }; If the socket promises reliable delivery of data and l_onoff is nonzero, the system will block the process on the attempt until it is able to transmit the data or until it decides it is unable to deliver the information. A timeout period, called the linger interval, is specified in l_linger. If l_onoff is set to 0 and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible. SO_BROADCAST is used to enable or disable broadcasting on the socket. See also accept, bind, connect, getsockname, getsockopt, listen, read, recv, recvfrom, recvmgs, select, send, sendmsg, sendto, shutdown, and write. 4 Return_Values x A file descriptor that refers to the socket descriptor. -1 Indicates an error; errno is set to one of the following: o EAFNOSUPPORT - The specified address family is not supported in this version of the system. o ESOCKTNOSUPPORT - The specified socket type is not supported in this address family. o EPROTONOSUPPORT - The specified protocol is not supported. o EPROTOTYPE - Request for a type of socket for which there is no supporting protocol. o EMFILE - The per-process descriptor table is full. o ENOBUFS - No buffer space is available. The socket cannot be created. 3 decc$socket_fd Returns the socket descriptor associated with a Socket Device Channel for direct use with the Compaq C RTL. Format #include int decc$socket_fd (int channel); 4 Arguments channel A valid Socket Device Channel. 4 Description The decc$socket_fd routine associates a valid socket channel with a Compaq C RTL file descriptor, and returns the file descriptor. The file descriptor can then be used with one of the Compaq C routines that take a file descriptor or socket descriptor as an input parameter. 4 Return_Values x The socket descriptor. -1 Indicates an error; the socket descriptor cannot be allocated. 3 vaxc$get_sdc Returns the Socket Device Channel (SDC) associated with a socket descriptor for direct use with the TCP/IP Services for OpenVMS product. Format #include short int vaxc$get_sdc (int s); 4 Argument s A socket descriptor. 4 Description This routine returns the SDC associated with a socket. C socket descriptors are normally used either as file descriptors or with one of the routines that takes an explicit socket descriptor as its argument. C sockets are implemented using TCP/IP Services for OpenVMS Socket Device Channels. This routine returns the SDC used by a given socket descriptor so that you can use the TCP/IP Services for OpenVMS's facilities directly by means of various I/O system services ($QIO). 4 Return_Values 0 Indicates that s is not an open socket descriptor. x The SDC number. 3 write Writes a buffer of data to a socket or file. Format #include int write (int d, void *buffer, int nbytes); 4 Arguments d A descriptor that must refer to a socket or file. buffer The address of contiguous storage from which the output data is taken. nbytes The maximum number of bytes involved in the write operation. 4 Description This routine attempts to write a buffer of data to a socket or file. See also socket. 4 Return_Values x The number of bytes written to the socket or file. 0 Indicates an error. -1 Indicates an error; errno is set to one of the following: o EBADF - The d argument is not a valid descriptor open for writing. o EPIPE - An attempt was made to write to a socket that is not open for reading by any process. o EFAULT - Part of the array pointed to by iov or data to be written to the file points outside the process's allocated address space. o EWOULDBLOCK - The NBIO (nonblocking) flag is set for the socket descriptor and the process would be delayed in the write operation. o EINVAL - The nbytes argument is negative. 2 abort Sends the signal SIGABRT that terminates execution of the program. Format #include void abort (void); 2 abs Returns the absolute value of an integer. Format #include int abs (int x); 3 Argument x An integer. 3 Return_Value x The absolute value of the input argument. If the argument is LONG_MIN, abs returns LONG_ MIN because -LONG_MIN cannot fit in an int variable. 2 access Checks a file to see whether a specified access mode is allowed. This function only checks UIC protection; ACLs are not checked. NOTE The access function does not accept network files as arguments. Format #include int access (const char *file_spec, int mode); 3 Arguments file_spec A character string that gives an OpenVMS or UNIX style file specification. The usual defaults and logical name translations are applied to the file specification. mode Interpreted as shown in Interpretation of the mode Argument. Table REF-1 Interpretation of the mode Argument Mode Argument Access Mode F_OK Tests to see if the file exists X_OK Execute W_OK Write (implies delete access) R_OK Read Combinations of access modes are indicated by ORing the values. For example, to check to see if a file has RWED access mode, invoke access as follows: access (file_spec, R_OK | W_OK | X_OK); 3 Return_Values 0 Indicates that the access is allowed. -1 Indicates that the access is not allowed. 3 Example #include #include #include main() { if (access("sys$login:login.com", F_OK)) { perror("ACCESS - FAILED"); exit(2); } } 2 acos Returns the arc cosine of its argument. Format #include double acos (double x); float acosf (float x); (Alpha only) long double acosl (long double x); (Alpha only) double acosd (double x); (Alpha only) float acosdf (float x); (Alpha only) long double acosdl (long double x); (Alpha only) 3 Argument x A radian expressed as a real value in the domain [-1,1]. 3 Description The acos functions compute the principal value of the arc cosine of x in the range [0,] radians for x in the domain [-1,1]. The acosd functions compute the principal value of the arc cosine of x in the range [0,180] degrees for x in the domain [-1,1]. For abs(x) > 1, the value of acos(x) is 0, and errno is set to EDOM. 2 acosh Returns the hyperbolic arc cosine of its argument. This function is OpenVMS Alpha only. Format #include double acosh (double x); float acoshf (float x); long double acoshl (long double x); 3 Argument x A radian expressed as a real value in the domain [1, +Infinity]. 3 Description The acosh functions return the hyperbolic arc cosine of x for x in the domain [1, +Infinity], where acosh(x) = ln(x + sqrt(x**2 - 1)). The acosh function is the inverse function of cosh where acosh(cosh(x)) = |x|. x < 1 is an invalid argument. 2 [w]addch Add a character to the window at the current position of the cursor. Format #include int addch (char ch); int waddch (WINDOW *win, char ch); 3 Arguments win A pointer to the window. ch The character to be added. A new-line character (\n) clears the line to the end, and moves the cursor to the next line at the same x coordinate. A return (\r) moves the cursor to the beginning of the line on the window. A tab (\t) moves the cursor to the next tabstop within the window. 3 Description When the waddch function is used on a subwindow, it writes the character onto the underlying window as well. The addch routine performs the same function as waddch, but on the stdscr window. The cursor is moved after the character is written to the screen. 3 Return_Values OK Indicates success. ERR Indicates that writing the character would cause the screen to scroll illegally. For more information, see the scrollok function. 2 [w]addstr Add the string pointed to by str to the window at the current position of the cursor. Format #include int addstr (char *str); int waddstr (WINDOW *win, char *str); 3 Arguments win A pointer to the window. str A pointer to a character string. 3 Description When the waddstr function is used on a subwindow, the string is written onto the underlying window as well. The addstr routine performs the same function as waddstr, but on the stdscr window. The cursor position changes as a result of calling this routine. 3 Return_Values OK Indicates success. ERR Indicates that the function causes the screen to scroll illegally, but it places as much of the string onto the window as possible. For more information, see the scrollok function. 2 alarm Sends the signal SIGALRM (defined in the header file) to the invoking process after the number of seconds indicated by its argument has elapsed. Format #include unsigned int alarm (unsigned int seconds); (ISO POSIX-1) int alarm (unsigned int seconds); (Compatability) 3 Argument seconds Has a maximum limit of LONG_MAX seconds. 3 Description Calling the alarm function with a 0 argument cancels any pending alarms. Unless it is caught or ignored, the signal generated by alarm terminates the process. Successive alarm calls reinitialize the alarm clock. Alarms are not stacked. Because the clock has a 1-second resolution, the signal may occur up to 1 second early. If the SIGALRM signal is caught, resumption of execution may be held up due to scheduling delays. When the SIGALRM signal is generated, a call to SYS$WAKE is generated whether or not the process is hibernating. The pending wake causes the current pause() to return immediately (after completing any function that catches the SIGALRM). 3 Return_Value n The number of seconds remaining from a previous alarm request. 2 asctime,_asctime_r Converts a broken-down time in a tm structure into a 26-character string in the following form: Sun Sep 16 01:03:52 1984\n\0 All fields have a constant width. Format #include char *asctime (const struct tm *timeptr); char *asctime_r (const struct tm *timeptr, char *buffer); (ISO POSIX-1) 3 Argument timeptr A pointer to a structure of type tm, which contains the broken- down time. The tm structure is defined in the header file, and also shown in tm Structure in the description of localtime. buffer A pointer to a character array that is at least 26 bytes long. This array is used to store the generated date-and-time string. 3 Description The asctime and asctime_r functions convert the contents of tm into a 26-character string and returns a pointer to the string. The difference between asctime_r and asctime is that the former puts the result into a user-specified buffer. The latter puts the result into thread-specific static memory allocated by the Compaq C RTL, which can be overwritten by subsequent calls to ctime or asctime; you must make a copy if you want to save it. On success, asctime returns a pointer to the string; asctime_r returns its second argument. On failure, these functions return the NULL pointer. See the localtime function for a list of the members in tm. NOTE Generally speaking, UTC-based time functions can affect in- memory time-zone information, which is process-wide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_ r, ctime_r, gmtime_r and localtime_r, is both thread-safe and AST-reentrant. If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant. 3 Return_Value x A pointer to the string, if successful. NULL Indicates failure. 2 asin Returns the arc sine of its argument. Format #include double asin (double x); float asinf (float x); (Alpha only) long double asinl (long double x); (Alpha only) double asind (double x); (Alpha only) float asindf (float x); (Alpha only) long double asindl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number in the domain [-1, 1]. 3 Description The asin functions compute the principal value of the arc sine of x in the range [-/2,/2] radians for x in the domain [-1,1]. The asind functions compute the principal value of the arc sine of x in the range [-90,90] degrees for x in the domain [-1,1]. When abs(x) is greater than 1.0, the value of asin(x) is 0, and errno is set to EDOM. 2 asinh Returns the hyperbolic arc sine of its argument. This function is OpenVMS Alpha only. Format #include double asinh (double x); float asinhf (float x); long double asinhl (long double x); 3 Argument x A radian expressed as a real value in the domain [-Infinity, +Infinity]. 3 Description The asinh functions return the hyperbolic arc sine of x for x in the domain [-Infinity, +Infinity], where asinh(x) = ln(x + sqrt(x**2 + 1)). The asinh function is the inverse function of sinh where asinh(sinh(x)) = x. 2 assert Used for implementing run-time diagnostics in programs. Format #include void assert (int expression); 3 Argument expression An expression that has an int type. 3 Description When assert is executed, if expression is false (that is, it evaluates to 0), assert writes information about the particular call that failed (including the text of the argument, the name of the source file, and the source line number; the latter two are respectively the values of the preprocessing macros __FILE__ and __LINE__) to the standard error file in an implementation- defined format. Then, it calls the abort function. The assert function writes a message in the following form: Assertion failed: expression, file aaa, line nnn If expression is true (that is, it evaluates to nonzero) or if the signal SIGABRT is being ignored, assert returns no value. NOTE If a null character ('\0') is part of the expression being asserted, then only the text up to and including the null character is printed, since the null character effectively terminates the string being output. Compiling with the CC command qualifier /DEFINE=NDEBUG or with the preprocessor directive #define NDEBUG ahead of the #include assert statement causes the assert function to have no effect. 3 Example #include #include main() { printf("Only this and the assert\n"); assert(1 == 2); /* expression is FALSE */ /* abort should be called so the printf will not happen. */ printf("FAIL abort did not execute"); } 2 atan Format #include double atan (double x); float atanf (float x); (Alpha only) long double atanl (long double x); (Alpha only) double atand (double x); (Alpha only) float atandf (float x); (Alpha only) long double atandl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number. 3 Description The atan functions compute the principal value of the arc tangent of x in the range [-/2,/2] radians. The atand functions compute the principal value of the arc tangent of x in the range [-90,90] degrees. 2 atan2 Format #include double atan2 (double y, double x); float atan2f (float y, float x); (Alpha only) long double atan2l (long double y, long double x); (Alpha only) double atand2 (double y, double x); (Alpha only) float atand2f (float y, float x); (Alpha only) long double atand2l (long double y, long double x); (Alpha only) 3 Argument y A radian expressed as a real number. x A radian expressed as a real number. 3 Description The atan2 functions compute the principal value of the arc tangent of y/x in the range [-pi,pi] radians. The sign of atan2 and atan2f is determined by the sign of y. The value of atan2(y,x) is computed as follows, where f is the number of fraction bits associated with the data type: Value of Input Arguments Angle Returned x = 0 or y/x > /2 * (sign y) 2**(f+1) x > 0 and y/x <= atan(y/x) 2**(f+1) x < 0 and y/x <= * (sign y) + atan(y/x) 2**(f+1) The atand2 functions compute the principal value of the arc tangent of y/x in the range [-180,180] degrees. The sign of atand2 and atand2f is determined by the sign of y. The following are invalid arguments for the atan2 and atand2 functions: Function Exceptional Argument atan2, atan2f, atan2l x = y = 0 atan2, atan2f, atan2l |x| = |y| = Infinity atand2, atand2f, atand2l x = y = 0 atand2, atand2f, atand2l |x| = |y| = Infinity 2 atanh Returns the hyperbolic arc tangent of its argument. This function is OpenVMS Alpha only. Format #include double atanh (double x); float atanhf (float x); long double atanhl (long double x); 3 Argument x A radian expressed as a real value in the domain [-1, 1]. 3 Description The atanh functions return the hyperbolic arc tangent of x. The atanh function is the inverse function of tanh where atanh(tanh(x)) = x. |x| > 1 is an invalid argument. 2 atexit Registers a function that is called without arguments at program termination. Format #include int atexit (void (*func) (void)); 3 Argument func A pointer to the function to be registered. 3 Return_Values 0 Indicates that the registration has succeeded. nonzero Indicates failure. 3 Restriction The longjmp function cannot be executed from within the handler, because the destination address of the longjmp no longer exists. 3 Example #include #include static void hw(void); main() { atexit(hw); } static void hw() { puts("Hello, world\n"); } Running this example produces the following output: Hello, world 2 atof Converts an ASCII character string to a double-precision number. Format #include double atof (const char *nptr); 3 Argument nptr A pointer to the character string to be converted to a double- precision number. The string is interpreted by the same rules that are used to interpret floating constants. 3 Description The string to be converted has the following format: [white-spaces][+|-]digits[radix-character][digits][e|E[+|-]integer] Where radix-character is defined in the current locale. The first unrecognized character ends the conversion. This function is equivalent to strtod(nptr, (char**) NULL). 3 Return_Values x The converted value. 0 Indicates an underflow or the conversion could not be performed. The function sets errno to ERANGE or EINVAL, respectively. (+/-)HUGE_VAL Indicates overflow; errno is set to ERANGE. 2 atoi,_atol Convert strings of ASCII characters to the appropriate numeric values. Format #include int atoi (const char *nptr); long int atol (const char *nptr); 3 Argument nptr A pointer to the character string to be converted to a numeric value. 3 Description The atoi and atol functions convert the initial portion of a string to its decimal int or long int value, respectively. The atoi and atol functions do not account for overflows resulting from the conversion. The string to be converted has the following format: [white-spaces][+|-]digits The function call atol (str) is equivalent to strtol (str, (char**)NULL, 10), and the function call atoi (str) is equivalent to (int) strtol (str, (char**)NULL, 10), except, in both cases, for the behavior on error. 3 Return_Value n The converted value. 2 atoq,_atoll Convert strings of ASCII characters to the appropriate numeric values. atoll is a synonym for This function is OpenVMS Alpha only. atoq. Format #include __int64 atoq (const char *nptr); __int64 atoll (const char *nptr); 3 Argument nptr A pointer to the character string to be converted to a numeric value. 3 Description The atoq (or atoll) function converts the initial portion of a string to its decimal __int64 value. This function does not account for overflows resulting from the conversion. The string to be converted has the following format: [white-spaces][+|-]digits The function call atoq (str) is equivalent to strtoq (str, (char**)NULL, 10), except for the behavior on error. 3 Return_Value n The converted value. 2 basename Returns the last component of a path name. Format #include char *basename (char *path); 3 Function_Variants This function also has variants named _basename32 and _basename64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument path A UNIX style pathname from which the base path name is extracted. 3 Description This function takes the UNIX style pathname pointed to by path and returns a pointer to the pathname's final component, deleting any trailing slash (/) characters. If path consists entirely of the slash (/) character, the function returns a pointer to the string "/". If path is a NULL pointer or points to an empty string, the function returns a pointer to the string ".". The basename function can modify the string pointed to by path. 3 Return_Values x A pointer to the final component of path. "/" If path consists entirely of the '/' character. "." If path is a NULL pointer or points to an empty string. 2 bcmp Compares byte strings. Format #include void bcmp (const void *string1, const void *string2, size_t length); 3 Arguments string1, string2 The byte strings to be compared. length The length (in bytes) of the strings. 3 Description The bcmp function compares the byte string in string1 against the byte string in string2. Unlike the string functions, there is no checking for null bytes. Zero-length strings are always identical. Note that bcmp is equivalent to memcmp, which is defined by the ANSI C Standard. Therefore, using memcmp is recommended for portable programs. 3 Return_Values 0 The strings are identical. Nonzero The strings are not identical. 2 bcopy Copies byte strings. Format #include void bcopy (const void *source, void *destination, size_t length); 3 Arguments source Pointer to the source string. destination Pointer to the destination string. length The length (in bytes) of the string. 3 Description The bcopy function operates on variable-length strings of bytes. It copies the value of the length argument in bytes from the string in the source argument to the string in the destination argument. Unlike the string functions, there is no checking for null bytes. If the length argument is 0 (zero), no bytes are copied. Note that bcopy is equivalent to memcpy, which is defined by the ANSI C Standard. Therefore, using memcpy is recommended for portable programs. 2 box Draws a box around the window using the character vert as the character for drawing the vertical lines of the rectangle, and hor for drawing the horizontal lines of the rectangle. Format #include int box (WINDOW *win, char vert, char hor); 3 Arguments win The address of the window. vert The character for the vertical edges of the window. hor The character for the horizontal edges of the window. 3 Description This function copies boxes drawn on subwindows onto the underlying window. Use caution when using functions such as overlay and overwrite with boxed subwindows. Such functions copy the box onto the underlying window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 brk Determines the lowest virtual address that is not used with the program. Format #include void *brk (unsigned long int addr); 3 Argument addr The lowest address, which the function rounds up to the next multiple of the page size. This rounded address is called the break address. 3 Description An address that is greater than or equal to the break address and less than the stack pointer is considered to be outside the program's address space. Attempts to reference it will cause access violations. When a program is executed, the break address is set to the highest location defined by the program and data storage areas. Consequently, brk is needed only by programs that have growing data areas. 3 Return_Values n The new break address. (void *)(-1) Indicates that the program is requesting too much memory. errno and vaxc$errno are updated. 3 Restriction Unlike other C library implementations, the Compaq C RTL memory allocation functions (such as malloc) do not rely on brk or sbrk to manage the program heap space. Consequently, on OpenVMS systems, calling brk or sbrk can interfere with memory allocation routines. The brk and sbrk functions are provided only for compatibility purposes. 2 bsearch Performs a binary search. It searches an array of sorted objects for a specified object. Format #include void *bsearch (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *)); 3 Function_Variants This function also has variants named _bsearch32 and _bsearch64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments key A pointer to the object to be sought in the array. This pointer should be of type pointer-to-object and cast to type pointer-to- void. base A pointer to the initial member of the array. This pointer should be of type pointer-to-object and cast to type pointer-to-void. nmemb The number of objects in the array. size The size of an object, in bytes. compar A pointer to the comparison function. 3 Description The array must first be sorted in increasing order according to the specified comparison function pointed to by compar. Two arguments are passed to the comparison function pointed to by compar. The two arguments point to the objects being compared. Depending on whether the first argument is less than, equal to, or greater than the second argument, the comparison function must return an integer less than, equal to, or greater than 0. It is not necessary for the comparison function (compar) to compare every byte in the array. Therefore, the objects in the array can contain arbitrary data in addition to the data being compared. Since it is declared as type pointer-to-void, the value returned must be cast or assigned into type pointer-to-object. 3 Return_Values x A pointer to the matching member of the array or a null pointer if no match is found. NULL Indicates that the key cannot be found in the array. 3 Example #include #include #define SSIZE 30 extern int compare(); /* prototype for comparison function */ int array[SSIZE] = {30, 1, 29, 2, 28, 3, 27, 4, 26, 5, 24, 6, 23, 7, 22, 8, 21, 9, 20, 10, 19, 11, 18, 12, 17, 13, 16, 14, 15, 25}; /* This program takes an unsorted array, sorts it using qsort, */ /* and then calls bsearch for each element in the array, */ /* making sure that bsearch returns the correct element. */ main() { int i; int failure = FALSE; int *rkey; qsort(array, SSIZE, sizeof (array[0]), &compare); /* search for each element */ for (i = 0; i < SSIZE - 1; i++) { /* search array element i */ rkey = bsearch((array + i), array, SSIZE, sizeof(array[0]), &compare); /* check for successful search */ if (&array[i] != rkey) { printf("Not in array, array element %d\n", i); failure = TRUE; break; } } if (!failure) printf("All elements successfully found!\n"); } /* Simple comparison routine. */ /* */ /* Returns: = 0 if a == b */ /* < 0 if a < b */ /* > 0 if a > b */ int compare(int *a, int *b) { return (*a - *b); } This example program outputs the following: All elements successfully found! 2 btowc Converts a one-byte multibyte character to a wide character in the initial shift state. Format #include wint_t btowc (int c); 3 Arguments c The character to be converted to a wide-character representation. 3 Description This function determines whether (unsigned char)c is a valid one- byte multibyte character in the initial shift state, and if so, returns a wide-character representation of that character. 3 Return_Values x The wide-character representation of unsigned char c. WEOF Indicates an error. The c argument has the value EOF or does not constitute a valid one- byte multibyte character in the initial shift state. 2 bzero Copies null characters into byte strings. Format #include void bzero (void *string, size_t length); 3 Arguments string Specifies the byte string into which you want to copy null characters. length Specifies the length (in bytes) of the string. 3 Description This function copies null characters ('\0') into the byte string pointed to by string for length bytes. If length is 0 (zero), then no bytes are copied. 2 cabs Returns the absolute value of a complex number. Format #include double cabs (cabs_t z); float cabsf (cabsf_t z); (Alpha only) long double cabsl (cabsl_t z); (Alpha only) 3 Arguments z A structure of type cabs_t, cabsf_t, or cabsl_t. These types are defined in the header file as follows: typedef struct {double x,y;} cabs_t; typedef struct { float x, y; } cabsf_t; (Alpha only) typedef struct { long double x, y; } cabsl_t; (Alpha only) 3 Description The cabs functions return the absolute value of a complex number by computing the Euclidean distance between its two points as the square root of their respective squares: sqrt(x2 + y2) On overflow, the return value is undefined. The cabs, cabsf, and cabsl functions are equivalent to the hypot, hypotf, and hypotl functions, respectively. 2 calloc Allocates an area of zeroed memory. This function is AST- reentrant. Format #include void *calloc (size_t number, size_t size); 3 Function_Variants This function also has variants named _calloc32 and _calloc64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments number The number of items to be allocated. size The size of each item. 3 Description The calloc function initializes the items to 0. See also malloc and realloc. 3 Return_Values n The address of the first byte, which is aligned on a quadword boundary. NULL Indicates an inability to allocate the space. 2 catclose Closes a message catalog. Format #include int catclose (nl_catd catd); 3 Arguments catd A message catalog descriptor. This is returned by a successful call to catopen. 3 Description This function closes the message catalog referenced by catd and frees the catalog file descriptor. 3 Return_Values 0 Indicates that the catalog was successfully closed. -1 Indicates that an error occurred. The function sets errno to the following value: o EBADF - The catalog descriptor is not valid. 2 catgets Retrieves a message from a message catalog. Format #include char *catgets (nl_catd catd, int set_id, int msg_id, const char *s); 3 Function_Variants This function also has variants named _catgets32 and _catgets64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments catd A message catalog descriptor. This is returned by a successful call to catopen. set_id An integer set identifier. msg_id An integer message identifier. s A pointer to a default message string that is returned by the function if the message cannot be retrieved. 3 Description This function retrieves a message identified by set_id and msg_ id, in the message catalog catd. The message is stored in a message buffer in the nl_catd structure, which is overwritten by subsequent calls to catgets. If a message string needs to be preserved, it should be copied to another location by the program. 3 Return_Values x Pointer to the retrieved message. s Pointer to the default message string. Indicates that the function is not able to retrieve the requested message from the catalogue. This condition can arise if the requested pair (set_d, msg_id) does not represent an existing message from the open catalogue, or it indicates that an error occurred. If an error occurred, the function sets errno to one of the following values: o EBADF - The catalog descriptor is not valid. o EVMSRR - A VMS I/O read error; the VMS error code can be found in vaxc$errno. 3 Example #include #include #include #include #include #include /* This test makes use of all the message catalog routines. catopen() */ /* opens the catalog ready for reading, then each of the three messages */ /* in the catalog are extracted in turn using catgets() and printed out.*/ /* catclose() closes the catalog after use. */ /* The catalog source file used to create the catalog is as follows: */ /* $ this is a message file * $ * $quote " * $ another comment line * $set 1 * 1 "First set, first message" * 2 "second message -- This long message uses a backslash \ * for continuation." * $set 2 * 1 "Second set, first message" */ char *default_msg = "this is the first message."; main() { nl_catd catalog; int msg1, msg2, retval; char *cat = "sys$disk:[]catgets_ example.cat"; /* Force local catalog */ char *msgtxt; char string[128]; /* Create the message test catalog */ system("gencat catgets_example.msgx catgets_example.cat") ; if ((catalog = catopen(cat, 0)) == (nl_catd) - 1) { perror("catopen"); exit(EXIT_FAILURE); } msgtxt = catgets(catalog, 1, 1, default_msg); printf("%s\n", msgtxt); msgtxt = catgets(catalog, 1, 2, default_msg); printf("%s\n", msgtxt); msgtxt = catgets(catalog, 2, 1, default_msg); printf("%s\n", msgtxt); if ((retval = catclose(catalog)) == -1) { perror("catclose"); exit(EXIT_FAILURE); } delete("catgets_example.cat;") ; /* Remove the test catalog */ } Running the example program produces the following result: First set, first message second message -- This long message uses a backslash for continuation. Second set, first message 2 catopen Opens a message catalog. Format #include nl_catd catopen (const char *name, int oflag); 3 Arguments name The name of the message catalog to open. oflag An object of type int that determines whether the locale set for the LC_MESSAGES category in the current program's locale or the logical name LANG is used to search for the catalog file. 3 Description This function opens the message catalog identified by name. If name contains a colon (:), a square opening bracket ([), or an angle bracket (<), or is defined as a logical name, then it is assumed that name is the complete file specification of the catalog. If it does not include these characters, catopen assumes that name is a logical name pointing to an existing catalog file. If name is not a logical name, then the logical name NLSPATH is used to define the file specification of the message catalog. NLSPATH is defined in the user's process. If the NLSPATH logical name is not defined, or no message catalog can be opened in any of the components specified by the NLSPATH, then the SYS$NLSPATH logical name is used to search for a message catalog file. Both NLSPATH and SYS$NLSPATH is a comma-separated list of templates. The catopen function uses each template to construct a file specification. For example, NLSPATH could be defined as: DEFINE NLSPATH SYS$SYSROOT:[SYS$I18N.MSG]%N.CAT,SYS$COMMON:[SYSMSG]%N.CAT In this example, catopen first searches the directory SYS$SYSROOT:[SYS$I18N.MSG] for the named catalog. If the named catalog is not found there, the directory SYS$COMMON:[SYSMSG] is searced. The catalog name is constructed by substituting %N with the name passed to catopen, and adding the .cat suffix. %N is known as a substitution field. The following substitution fields are valid: Field Meaning %N Substitute the name passed to catopen %L Substitute the locale name. The period (.) and at-sign (@) characters in the locale name are replaced by an underscore (_) character. For example, the "zh_CN.dechanzi@radical" locale name results in a substitution of ZH_CN_DECHANZI_RADICAL. %l Substitute the language part of the locale name. For example, the language part of the en_GB.ISO8859-1 locale name is en. %t Substitute the territory part of the locale name. For example, the territory part of the en_GB.ISO8859-1 locale is GB. %c Substitute the codeset name from the locale name. For example, the codeset name of the en_GB.ISO8859-1 locale name is ISO8859-1. If the oflag argument is set to NL_CAT_LOCALE, then the current locale as defined for the LC_MESSAGES category is used to determine the substitution for the %L, %l, %t, and %c substitution fields. If the oflag argument is set to 0, then the value of the LANG environment variable is used as a locale name to determine the substitution for these fields. Note that using NL_CAT_LOCALE conforms to the XPG4 specification while a value of 0 (zero) exists for the purpose of preserving XPG3 compatibility. Note also, that catopen uses the value of the LANG environment variable without checking whether the program's locale can be set using this value. That is, catopen does not check whether this value can serve as a valid locale argument in the setlocale call. If the substitution value is not defined, an empty string is substituted. A leading comma or two adjacent commas (,,) is equivalent to specifying %N. For example, DEFINE NLSPATH ",%N.CAT,SYS$COMMON:[SYSMSG.%L]%N.CAT" In this example, catopen searches in the following locations in the order shown: 1. name (in the current directory) 2. name.cat (in the current directory) 3. SYS$COMMON:[SYSMSG.locale_name]name.cat 3 Return_Values x A message catalog file descriptor. Indicates the call was successful. This descriptor is used in calls to catgets and catclose. (nl_catd) -1 Indicates an error occurred. The function sets errno to one of the following values: o EACCES - Insufficient privilege or file protection violation, or file currently locked by another user. o EMFILE - Process channel count exceeded. o ENAMETOOLONG - The full file specification for message catalogue is too long o ENOENT - Unable to find the requested message catalogue. o ENOMEM - Insufficient memory available. o ENOTDIR - Part of the name argument is not a valid directory. o EVMSERR - An error occurred that does not match any errno value. Check the value of vaxc$errno. 2 cbrt Returns the rounded cube root of y. This function is OpenVMS Alpha only. Format #include double cbrt (double y); float cbrtf (float y); long double cbrtl (long double y); 3 Arguments y A real number. 2 ceil Returns the smallest integer that is greater than or equal to its argument. Format #include double ceil (double x); float ceilf (float x); (Alpha only) long double ceill (long double x); (Alpha only) 3 Argument x A real value. 3 Return_Values n The smallest integer greater than or equal to the function argument. 2 cfree Makes available for reallocation the area allocated by a previous calloc, malloc, or realloc call. This function is AST-reentrant. Format #include void cfree (void *ptr); 3 Argument ptr The address returned by a previous call to malloc, calloc, or realloc. 3 Description The contents of the deallocated area are unchanged. In Compaq C for OpenVMS Systems, the free and cfree functions are equivalent. Some other C implementations use free with malloc or realloc, and cfree with calloc. However, since the ANSI C standard does not include cfree, using free may be preferable. Also see the free function. 2 chdir Changes the default directory. Format #include int chdir (const char *dir_spec); (ISO POSIX-1) int chdir (const char *dir_spec, . . . ); (DEC C Extension) 3 Argument dir_spec A null-terminated character string naming a directory in either an OpenVMS or UNIX style specification. . . . This argument is a Compaq C extension available when not defining any of the standards-related feature-test macros and not compiling in strict ANSI C mode (/STANDARD=ANSI89). The argument is an optional flag of type int that is significant only when calling chdir from USER mode. If the value of the flag is 1, the new directory is effective across images. If the value is not 1, the original default directory is restored when the image exits. 3 Description This function changes the default directory. The change can be permanent or temporary. Permanent means that the new directory remains as the default directory after the image exits. Temporary means that on image exit, the default is set to whatever it was before the execution of the image. There are two ways of making the change permanent: o Call chdir from USER mode with the second argument set to 1. o Call chdir from SUPERVISOR or EXECUTIVE mode, regardless of the value of the second argument. Otherwise, the change is temporary. 3 Return_Values 0 Indicates that the directory is successfully changed to the given name. -1 Indicates that the change attempt has failed. 2 chmod Changes the file protection of a file. Format #include int chmod (const char *file_spec, mode_t mode); 3 Arguments file_spec The name of an OpenVMS or UNIX style file specification. mode A file protection. Modes are constructed by performing a bitwise OR on any of the values shown in File Protection Values and Their Meanings. Table REF-2 File Protection Values and Their Meanings Value Privilege 0400 OWNER:READ 0200 OWNER:WRITE 0100 OWNER:EXECUTE 0040 GROUP:READ 0020 GROUP:WRITE 0010 GROUP:EXECUTE 0004 WORLD:READ 0002 WORLD:WRITE 0001 WORLD:EXECUTE When you supply a mode value of 0, the chmod function gives the file the user's default file protection. The system is given the same privileges as the owner. A WRITE privilege also implies a DELETE privilege. 3 Description You must have a WRITE privilege for the file specified to change the mode. 3 Return_Values 0 Indicates that the mode is successfully changed. -1 Indicates that the change attempt has failed. 2 chown Changes the owner user identification code (UIC) of the file. Format #include int chown (const char *file_spec, uid_t owner, gid_t group); 3 Arguments file_spec The address of an ASCII file name. owner An integer corresponding to the new owner UIC of the file. group An integer corresponding to the group UIC of the file. 3 Return_Values 0 Indicates success. -1 Indicates failure. 2 [w]clear Erase the contents of the specified window and reset the cursor to coordinates (0,0). The clear function acts on the stdscr window. Format #include int clear(); int wclear (WINDOW *win); 3 Argument win A pointer to the window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 clearerr Resets the error and end-of-file indicators for a file (so that ferror and feof will not return a nonzero value). Format #include void clearerr (FILE *file_ptr); 3 Argument file_ptr A file pointer. 2 clearok Sets the clear flag for the window. Format #include clearok (WINDOW *win, bool boolf); 3 Arguments win The entire size of the terminal screen. You can use the windows stdscr and curscr with clearok. boolf A Boolean value of TRUE or FALSE. If the argument is TRUE, this forces a clearscreen to be printed on the next call to refresh, or stops the screen from being cleared if boolf is FALSE. The type bool is defined in the header file as follows: #define bool int 3 Description Unlike the clear function, the clearok function does not alter the contents of the window. If the win argument is curscr, the next call to refresh causes a clearscreen, even if the window passed to refresh is not a window the size of the entire terminal screen. 2 clock Determines the CPU time (in 10-millisecond units) used since the beginning of the process. The time reported is the sum of the user and system times of the calling process and any terminated child processes for which the calling process has executed wait or system. Format #include clock_t clock (void); 3 Description The value returned by the clock function must be divided by the value of the CLK_TCK, as defined in the standard header file , to obtain the time in seconds. The type clock_t is defined in the header file as follows: typedef long int clock_t; Only the accumulated times for child processes running a C main program or a program that calls VAXC$CRTL_INIT or DECC$CRTL_INIT are included. A typical usage of the clock function is to call it after a program does its initial setup, and then again after the program executes the code to be timed. Then subtract the two values to give elapsed CPU time. 3 Return_Values n The processor time used. -1 Indicates that the processor time used is not available. 2 close Closes the file associated with a file descriptor. Format #include int close (int file_desc); 3 Argument file_desc A file descriptor. 3 Description This function tries to write buffered data by using an implicit call to fflush. If the write fails (because the disk is full or the user's quota was exceeded, for example), close continues executing. It closes the VMS channel, deallocates any buffers, and releases the memory associated with the file descriptor (or FILE pointer). Any buffered data is lost, and the file descriptor (or FILE pointer) no longer refers to the file. If your program needs to recover from errors when flushing buffered data, it should make an explicit call to fsync (or fflush) before calling close. 3 Return_Values 0 Indicates that the file is properly closed. -1 Indicates that the file descriptor is undefined or an error occurred while the file was being closed (for example, if the buffered data cannot be written out). 3 Example #include int fd; . . . fd = open ("student.dat", 1); . . . close(fd); 2 closedir Closes directories. Format #include int closedir (DIR *dir_pointer); 3 Argument dir_pointer Pointer to the dir structure of an open directory. 3 Description This function closes a directory stream and frees the structure associated with the dir_pointer argument. Upon return, the value of dir_pointer does not necessarily point to an accessible object of the type DIR. The type DIR, which is defined in the header file, represents a directory stream that is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove files from or add files to a directory asynchronously to the operation of the readdir function. NOTE An open directory must always be closed with the closedir function to ensure that the next attempt to open the directory is successful. 3 Example The following example shows how to search a directory for the entry name, using the opendir, readdir, and closedir functions: #include #include #include #include #define FOUND 1 #define NOT_FOUND 0 static int dirent_example(const char *name, unsigned int unix_style) { DIR *dir_pointer; struct dirent *dp; if ( unix_style ) dir_pointer = opendir("."); else dir_pointer = opendir(getenv("PATH")); if ( !dir_pointer ) { perror("opendir"); return NOT_FOUND; } /* Note, that if opendir() was called with Unix style file */ /* spec like ".", readdir() will return only a single */ /* version of each file in the directory. In this case the */ /* name returned in d_name member of the dirent structure */ /* will contain only file name and file extension fields, */ /* both lowercased like "foo.bar". */ /* If opendir() was called with VMS style file spec, */ /* readdir() will return every version of each file in the */ /* directory. In this case the name returned in d_name */ /* member of the dirent structure will contain file name, */ /* file extension and file version fields. All in upper */ /* case, like "FOO.BAR;1". */ for ( dp = readdir(dir_pointer); dp && strcmp(dp->d_name, name); dp = readdir(dir_pointer) ) ; closedir(dir_pointer); if ( dp != NULL ) return FOUND; else return NOT_FOUND; } int main(void) { char *filename = "foo.bar"; FILE *fp; remove(filename); if ( !(fp = fopen(filename, "w")) ) { perror("fopen"); return (EXIT_FAILURE); } if ( dirent_example( "FOO.BAR;1", 0 ) == FOUND ) puts("VMS style: found"); else puts("VMS style: not found"); if ( dirent_example( "foo.bar", 1 ) == FOUND ) puts("Unix style: found"); else puts("Unix style: not found"); fclose(fp); remove(filename); return( EXIT_SUCCESS ); } 3 Return_Values 0 Indicates success. -1 Indicates an error and is further specified in the global errno. 2 [w]clrattr Deactivate the video display attribute attr within the window. The clrattr function acts on the stdscr window. Format #include int clrattr (int attr); int wclrattr (WINDOW *win, int attr); 3 Arguments win A pointer to the window. attr Video display attributes that can be blinking, boldface, reverse video, and underlining; they are represented by the defined constants _BLINK, _BOLD, _REVERSE, and _UNDERLINE. To clear multiple attributes, separate them with a bitwise OR operator (|) as follows: clrattr(_BLINK | _UNDERLINE); 3 Description These functions are specific to Compaq C for OpenVMS Systems and are not portable. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 [w]clrtobot Erase the contents of the window from the current position of the cursor to the bottom of the window. The clrtobot function acts on the stdscr window. Format #include int clrtobot(); int wclrtobot (WINDOW *win); 3 Argument win A pointer to the window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 [w]clrtoeol Erase the contents of the window from the current cursor position to the end of the line on the specified window. The clrtoeol function acts on the stdscr window. Format #include int clrtoeol(); int wclrtoeol (WINDOW *win); 3 Argument win A pointer to the window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 confstr Determines the current value of a specified system variable defined by a string value. Format #include size_t confstr (int name, char *buf, size_t len); 3 Arguments name The system variable setting. Valid values for the name argument are the _CS_X names defined in the header file. buf Pointer to the buffer where the confstr function copies the name value. len The size of the buffer storing the name value. 3 Description This function allows an application to determine the current setting of certain system parameters, limits, or options that are defined by a string value. The function is mainly used by applications to find the system default value for the PATH environment variable. If the following conditions are true, then the confstr function copies that value into a len-byte buffer pointed to by buf: o The len argument is not 0 (zero). o The name argument has a system-defined value. o The buf argument is not a NULL pointer. If the returned string is longer than len bytes, including the terminating null, then the confstr function truncates the string to len -1 bytes and adds a terminating null to the result. The application can detect that the string was truncated by comparing the value returned by the confstr function with the value of the len argument. The header file contains system-defined limits. The header file contains system-defined environmental variables. 3 Example To find out how big a buffer is needed to store the string value of name, enter: confstr(_CS_PATH, NULL, (size_t) 0) The confstr function returns the size of the buffer necessary. 3 Return_Values 0 Indicates an error. When the specified name value: o Is invalid, errno is set to EINVAL. o Does not have a system-defined value, errno is not set. n The size of the buffer needed to hold the value. o When the value of the name argument is system-defined, confstr returns the size of the buffer needed to hold the entire value. If this return value is greater than the len value, the string returned as the buf value is truncated. o When the value of the len argument is set to 0 or the buf value is NULL, confstr returns the size of the buffer needed to hold the entire system-defined value. The string value is not copied. 2 copysign Returns x with the same sign as y. This function is OpenVMS Alpha only. Format #include double copysign (double x, double y); float copysignf (float x, float y); (Alpha only) long double copysignl (long double x, long double y); (Alpha only) 3 Argument x A real value. y A real value. 3 Description The copysign functions return x with the same sign as y. IEEE 754 requires copysign(x,NaN), copysignf(x,NaN) and copysignl(x,NaN) to return +x or -x. 3 Return_Values x The value of x with the same sign as y. 2 cos Returns the cosine of its radian argument. Format #include double cos (double x); float cosf (float x); (Alpha only) long double cosl (long double x); (Alpha only) double cosd (double x); (Alpha only) float cosdf (float x); (Alpha only) long double cosdl (long double x); (Alpha only) 3 Argument x A radian expressed as a real value. 3 Description The cos functions return the cosine of their argument, measured in radians. The cosd functions return the cosine of their argument, measured in degrees. |x| = Infinity is an invalid argument. 3 Return_Values x The cosine of the argument. HUGE_VAL Indicates that the argument is too large; errno is set to ERANGE. 2 cosh Returns the hyperbolic cosine of its radian argument. Format #include double cosh (double x); float coshf (float x); (Alpha only) long double coshl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number. 3 Description The cosh functions return the hyperbolic cosine of x and are defined as (e**x + e**(-x))/2. 3 Return_Values x The hyperbolic cosine of the argument. HUGE_VAL Indicates that the argument is too large; errno is set to ERANGE. 2 cot Returns the cotangent of its radian argument. Format #include double cot (double x); float cotf (float x); (Alpha only) long double cotl (long double x); (Alpha only) double cotd (double x); (Alpha only) float cotdf (float x); (Alpha only) long double cotdl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number. 3 Description The cot functions return the cotangent of their argument, measured in radians. The cotd functions return the cotangent of their argument, measured in degrees. x = 0 is an invalid argument. 3 Return_Values x The cotangent of the argument. HUGE_VAL Indicates that the argument is zero; errno is set to ERANGE. 2 creat Creates a new file. Format #include int creat (const char *file_spec, mode_t mode); (ISO POSIX-1) int creat (const char *file_spec, mode_t mode, . . . ); (DEC C Extension) 3 Arguments file_spec A null-terminated string containing any valid file specification. mode An unsigned value that specifies the file-protection mode. The compiler performs a bitwise AND operation on the mode and the complement of the current protection mode. You can construct modes by using the bitwise OR operator (|) to create mode combinations. The modes are as follows: 0400 OWNER:READ 0200 OWNER:WRITE 0100 OWNER:EXECUTE 0040 GROUP:READ 0020 GROUP:WRITE 0010 GROUP:EXECUTE 0004 WORLD:READ 0002 WORLD:WRITE 0001 WORLD:EXECUTE The system is given the same privileges as the owner. A WRITE privilege implies a DELETE privilege. NOTE To create files with OpenVMS RMS default protections using the UNIX system-call functions umask, mkdir, creat, and open, call mkdir, creat, and open with a file-protection mode argument of 0777 in a program that never specifically calls umask. These default protections include correctly establishing protections based on ACLs, previous versions of files, and so on. In programs that do vfork/exec calls, the new process image inherits whether umask has ever been called or not from the calling process image. The umask setting and whether the umask function has ever been called are both inherited attributes. . . . An optional argument list of character strings of the following form: "keyword = value", . . . ,"keyword = value" Or in the case of "acc" or "err", this form: "keyword" Here, keyword is an RMS field in the file access block (FAB) or record access block (RAB); value is valid for assignment to that field. Some fields permit you to specify more than one value. In these cases, the values are separated by commas. The RMS callback keywords "acc" and "err" are the only keywords that do not take values. Instead, they are followed by a pointer to the callback routine to be used, followed by a pointer to a user-specified value to be used as the first argument of the callback routine. For example, to set up an access callback routine called acc_callback whose first argument is a pointer to the integer variable first_arg in a call to open, you can use the following statement: open("file.dat", O_RDONLY, 0 ,"acc", acc_callback, &first_arg) The second and third arguments to the callback routine must be pointers to a FAB and RAB, respectively, and the routine must have a return type of int. If the callback returns a value less than 0, the open, creat, or fopen fails. The error callback can correct the error condition and return a status greater than or equal to 0 to continue the creat call. Assuming the previous open statement, the function prototype for acc_callback would be similar to the following statement: #include int acc_callback(int *first_arg, struct FAB *fab, struct RAB *rab); FAB and RAB are defined in the header file, and the actual pointers passed to the routine are pointers to the RAB and FAB being used to open the file file.dat. If an access callback routine is established, then it will be called in the open-type routine immediately before the call to the RMS function sys$create or sys$open. If an error callback routine is established and an error status is returned from the sys$create or sys$open function, then the callback routine will be invoked immediately after the status is checked and the error value is discovered. NOTE Any manipulation of the RAB or FAB in a callback function could lead to serious problems in later calls to the Compaq C RTL I/O functions. RMS Valid Keywords and Values describes the RMS keywords and values. Table REF-3 RMS Valid Keywords and Values Keyword Value Description "acc" callbacAccess callback routine. "alq = n" decimalAllocation quantity. "bls = n" decimalBlock size. "ctx = bin" string No translation of '\n' to the terminal. Use this for writing binary data to files. "ctx=cvt" string Negates a previous setting of "ctx=nocvt". This is the default. "ctx = string No conversion of Fortran carriage-control nocvt" bytes. "ctx = rec" string Force record mode access. "ctx = stm" string Force stream mode access. "ctx=xplct" string Causes records to be written only when explicitly specified by a call to fflush, close, or fclose. "deq = n" decimalDefault extension quantity. "dna = string Default file-name string. filespec" "err" callbacError callback routine. "fop = val, File-processing options: val , . . . " ctg Contiguous. cbt Contiguous-best-try. dfw Deferred write; only applicable to files opened for shared access. dlt Delete file on close. tef Truncate at end-of-file. cif Create if nonexistent. sup Supersede. scf Submit as command file on close. spl Spool to system printer on close. tmd Temporary delete. tmp Temporary (no file directory). nef Not end-of-file. rck Read check compare operation. wck Write check compare operation. mxv Maximize version number. rwo Rewind file on open. pos Current position. rwc Rewind file on close. sqo File can only be processed in a sequential manner. "fsz = n" decimalFixed header size. "gbc = n" decimalThe requested number of global buffers for a file. "mbc = n" decimalMultiblock count. "mbf = n" decimalMultibuffer count. "mrs = n" decimalMaximum record size. "pmt=usr- string Prompts for terminal input. Any RMS input prmpt" from a terminal device will be preceded by "usr-prmpt" when this option and "rop=pmt" are specified. "rat = val, Record attributes: val . . . " cr Carriage-return control. blk Disallow records to span block boundaries. ftn FORTRAN print control. none Explicitly forces no carriage control. prn Print file format. "rfm = val" Record format: fix Fixed-length record format. stm RMS stream record format. stmlf Stream format with line-feed terminator. stmcr Stream format with carriage-return terminator. var Variable-length record format. vfc Variable-length record with fixed control. udf Undefined. "rop = val, Record-processing operations: val . . . " asy Asynchronous I/O. cco Cancel Ctrl/O (used with Terminal I/O). cvt Capitalizes characters on a read from the terminal. eof Positions the record stream to the end-of- file for the connect operation only. nlk Do not lock record. pmt Enables use of the prompt specified by "pmt=usr-prmpt" on input from the terminal. pta Eliminates any information in the type- ahead buffer on a read from the terminal. rea Locks record for a read operation for this process, while allowing other accessors to read the record. rlk Locks record for write. rne Suppresses echoing of input data on the screen as it is entered on the keyboard. rnf Indicates that Ctrl/U, Ctrl/R, and DELETE are not to be considered control commands on terminal input, but are to be passed to the application program. rrl Reads regardless of lock. syncstsReturns success status of RMS$_SYNCH if the requested service completes its task immediately. tmo Timeout I/O. tpt Allows put/write services using sequential record access mode to occur at any point in the file, truncating the file at that point. ulk Prohibits RMS from automatically unlocking records. wat Wait until record is available, if currently locked by another stream. rah Read ahead. wbh Write behind. "rtv=n" decimalThe number of retrieval pointers that RMS has to maintain in memory (0 to 127,255). "shr = val, File sharing options: val, . . . " del Allows users to delete. get Allows users to read. mse Allows multi-stream connects. nil Prohibits file sharing. put Allows users to write. upd Allows users to update. upi Allows one or more writers. nql No query locking (file level). "tmo = n" decimalI/O timeout value. In addition to these options, any option that takes a key value (such as "fop" or "rat") can be negated by prefixing the value with "no". For example, specify "fop=notmp" to clear the "tmp" bit in the "fop" field. NOTES o While these options provide much flexibility and functionality, many of them can also cause severe problems if not used correctly. o You cannot share the default Compaq C for OpenVMS stream file I/O. If you wish to share files, you must specify "ctx=rec" to force record access mode. You must also specify the appropriate "shr" options depending on the type of access you want. o If you intend to share a file opened for append, you must specify appropriate share and record-locking options, to allow other accessors to read the record. The reason for doing this: the file is positioned at end-of-file through reading records in a loop until end-of-file is reached. For more information on these options, see the OpenVMS Record Management Services Reference Manual manual. 3 Description The Compaq C RTL opens the new file for reading and writing, and returns the corresponding file descriptor. If the file exists: o A version number one greater than any existing version is assigned to the newly created file. o By default, the new file inherits certain attributes from the existing version of the file unless those attributes are specified in the creat call. The following attributes are inherited: - Record format (fab$b_rfm) - Maximum record size (fab$w_mrs) - Carriage control (fab$b_rat) - File protection If the file did not previously exist: o It is given the file protection that results from performing a bitwise AND on the mode argument and the complement of the current protection mask. o It defaults to stream format with line-feed record separator and implied carriage-return attributes. See also open, close, read, write, and lseek. 3 Return_Values n A file descriptor. -1 Indicates errors, including protection violations, undefined directories, and conflicting file attributes. 2 [no]crmode In the UNIX system environment, the crmode and nocrmode functions set and unset the terminal from cbreak mode. In cbreak mode, a single input character can be processed without pressing Return. This mode of single-character input is only supported with the Curses input routine getch. Format #include crmode() nocrmode() 3 Example /* Program to demonstrate the use of crmod() and curses */ #include main() { WINDOW *win1; char vert = '.', hor = '.', str[80]; /* Initialize standard screen, turn echo off. */ initscr(); noecho(); /* Define a user window. */ win1 = newwin(22, 78, 1, 1); /* Turn on reverse video and draw a box on border. */ setattr(_REVERSE); box(stdscr, vert, hor); mvwaddstr(win1, 2, 2, "Test cbreak input"); refresh(); wrefresh(win1); /* Set cbreak, do some input, and output it. */ crmode(); getch(); nocrmode(); /* Turn off cbreak. */ mvwaddstr(win1, 5, 5, str); mvwaddstr(win1, 7, 7, "Type something to clear the screen"); wrefresh(win1); /* Get another character, then delete the window. */ getch(); wclear(win1); touchwin(stdscr); endwin(); } In this example, the first call to getch returns as soon as one character is entered, because crmode was called before getch was called. The second time getch is called, it waits until the Return key is pressed before processing the character entered, because nocrmode was called before getch was called the second time. 2 ctermid Returns a character string giving the equivalence string of SYS$COMMAND. This is the name of the controlling terminal. Format #include char *ctermid (char *str); 3 Function_Variants This function also has variants named _ctermid32 and _ctermid64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument str Must be a pointer to an array of characters. If this argument is NULL, the file name is stored internally and might be overwritten by the next ctermid call. Otherwise, the file name is stored beginning at the location indicated by the argument. The argument must point to a storage area of length L_ctermid (defined by the header file). 3 Return_Value pointer Points to a character string. 2 ctime,_ctime_r Converts a time in seconds, since 00:00:00 January 1, 1970, to an ASCII string in the form generated by the asctime function. Format #include char *ctime (const time_t *bintim); char *ctime_r (const time_t *bintim, char *buffer); (ISO POSIX-1) 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Argument bintim A pointer to a variable that specifies the time value (in seconds) to be converted. buffer A pointer to a character array that is at least 26 bytes long. This array is used to store the generated date-and-time string. 3 Description The ctime and ctime_r functions convert the time pointed to by bintim into a 26-character string, and return a pointer to the string. The difference between the ctime_r and ctime functions is that the former puts its result into a user-specified buffer. The latter puts its result into thread-specific static memory allocated by the Compaq C RTL, which can be overwritten by subsequent calls to ctime or asctime; you must make a copy if you want to save it. On success, ctime returns a pointer to the string; ctime_r returns its second argument. On failure, these functions return the NULL pointer. The type time_t is defined in the header file as follows: typedef long int time_t The ctime function behaves as if it called tzset. NOTE Generally speaking, UTC-based time functions can affect in- memory time-zone information, which is process-wide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_ r, ctime_r, gmtime_r and localtime_r, is both thread-safe and AST-reentrant. If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant. 3 Return_Value x A pointer to the 26-character ASCII string, if successful. NULL Indicates failure. 2 cuserid Returns a pointer to a character string containing the name of the user initiating the current process. Format #include (X/Open, POSIX-1) #include (X/Open) char *cuserid (char *str); 3 Function_Variants This function also has variants named _cuserid32 and _cuserid64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument str If this argument is NULL, the user name is stored internally. If the argument is not NULL, it points to a storage area of length L_cuserid (defined by the header file), and the name is written into that storage. If the user name is a null string, the function returns NULL. 3 Return_Values pointer Points to a string. NULL If the user name is a null string. 2 DECC$CRTL_INIT Allows you to call the Compaq C RTL from other languages or to use the Compaq C RTL when your main function is not in C. It initializes the run-time environment and establishes both an exit and condition handler. VAXC$CRTL_INIT is a synonym for DECC$CRTL_ INIT. Either name invokes the same routine. Format #include void DECC$CRTL_INIT(void); 3 Description The following example shows a Pascal program that calls the Compaq C RTL using the DECC$CRTL_INIT function: $ PASCAL EXAMPLE1 $ LINK EXAMPLE1 $ TY EXAMPLE1.PAS PROGRAM TESTC(input, output); PROCEDURE DECC$CRTL_INIT; extern; BEGIN DECC$CRTL_INIT; END A shareable image need only call this function if it contains a Compaq C function for signal handling, environment variables, I/O, exit handling, a default file protection mask, or if it is a child process that should inherit context. Although many of the initialization activities are performed only once, DECC$CRTL_INIT can safely be called multiple times. On OpenVMS VAX systems, DECC$CRTL_INIT establishes the Compaq C RTL internal OpenVMS exception handler in the frame of the routine that calls DECC$CRTL_INIT each time DECC$CRTL_INIT is called. At least one frame in the current call stack must have that handler established for OpenVMS exceptions to get mapped to UNIX signals. 2 decc$feature_get_index Returns an index for accessing feature values. Format int decc$feature_get_index (char *name); 3 Argument name Pointer to a character string passed as a name in the list of supported features. 3 Description This function looks up the string passed as name in the list of supported features. If the name is found, decc$feature_get_ index returns a (nonnegative) index that can be used to set or retrieve the values for the feature. The comparison for name is case insensitive. On error, -1 is returned and errno is set to indicate the error. Also see feature_get_name, feature_get_value, and feature_set_ value. 3 Return_Values n A nonnegative index that can be used to set or retrieve the values for the feature. -1 Indicates an error; errno is set. 3 Example #include #include #include #include #include int decc$feature_get_index (char *name); char *decc$feature_get_name (int index); int decc$feature_get_value (int index, int mode); int decc$feature_set_value (int index, int mode, int value); int set_only; static char *sval(int i) { static char buf[128]; if (i) sprintf(buf, "%d", i); else strcpy(buf, "."); return buf; } /* ** Convert a string to lowercase ** */ char *strtolower( char *str ) { char *ret = str; char c; if (!str) return str; for (ret = str; c = *str; str++) *str = tolower( c ); return ret; } /* ** Print all available features and their values ** */ void print_feature_settings( void ) { char *name; int i; int skipped = 0; /* ** C RTL Feature settings ------------ Logical name --------------- Cur Def Min Max Ini DECC$EXEC_FILEATTR_INHERITANCE 1 . . 1 1 DECC$FILENAME_UNIX_ONLY 1 . . 1 2 DECC$FILE_SHARING 1 . . 1 2 DECC$POSIX_SEEK_STREAM_FILE 1 . . 1 2 DECC$STDIO_CTX_EOL 1 . . 1 1 DECC$TRACE 1 . . 1 1 DECC$ARGV_PARSE_STYLE 1 . . 1 1 DECC$EFS_CASE_PRESERVE 1 . . 1 2 DECC$EFS_CASE_SPECIAL 1 . . 1 1 */ puts("** C RTL Feature settings"); puts(" ------------ Logical name --------------- Cur Def Min Max Ini"); for (i = 0; name = decc$feature_get_name(i); i++) { int init = decc$feature_get_value(i, 4); if ((set_only < 0 || set_only > 1) || (set_only == 1 && init > 0) || (set_only == 0 && init < 1) ) { int default_val = decc$feature_get_value(i, 0); int current_val = decc$feature_get_value(i, 1); int min_val = decc$feature_get_value(i, 2); int max_val = decc$feature_get_value(i, 3); char f_name[256]; strcpy( f_name, name ); if (strlen(f_name) > 4) strtolower(f_name+4); printf(" %-40s", f_name); printf(" %6s", sval(current_val)); printf(" %6s", sval(default_val)); printf(" %6s", sval(min_val)); printf(" %6s", sval(max_val)); printf(" %3s", sval(init)); puts(""); } } puts(""); puts ("** C RTL features that cannot be set by API"); for (i++; name = decc$feature_get_name(i); i++) { int init = decc$feature_get_value(i, 4); if ((set_only < 0 || set_only > 1) || (set_only == 1 && init > 0) || (set_only == 0 && init < 1) ) { int default_val = decc$feature_get_value(i, 0); int current_val = decc$feature_get_value(i, 1); int min_val = decc$feature_get_value(i, 2); int max_val = decc$feature_get_value(i, 3); char f_name[256]; strcpy( f_name, name ); if (strlen(f_name) > 4) strtolower(f_name+4); printf(" %-40s", f_name); printf(" %6s", sval(current_val)); printf(" %6s", sval(default_val)); printf(" %6s", sval(min_val)); printf(" %6s", sval(max_val)); printf(" %3s", sval(init)); puts(""); } } } #ifdef LIB_INIT /* ** Sets current value for a feature */ static int set_feature_default(char *name, int value) { int index; int sts; errno = 0; index = decc$feature_get_index(name); if (index == -1 || ((sts = decc$feature_set_value(index, 1, value)) == -1)) { perror(name); return -1; } return 0; } static void set_coe ( void ) { set_feature_default("DECC$FILENAME_UNIX_ONLY" , TRUE); set_feature_default("DECC$FILE_SHARING" , TRUE); set_feature_default("DECC$POSIX_SEEK_STREAM_FILE" , TRUE); set_feature_default("DECC$EFS_CASE_PRESERVE" , TRUE); set_feature_default("DECC$ARGV_CASE_PARSE_STYLE" , TRUE); } int lib$initialize(); #pragma nostandard globaldef { "LIB$INITIALIZ" } readonly _align (LONGWORD) int spare[8] = {0}; globaldef { "LIB$INITIALIZE" } readonly _align (LONGWORD) void (*x_set_coe)() = set_coe; /* ** Force a reference to LIB$INITIALIZE to ensure it ** exists in the image. */ globaldef int (*lib_init_ref)() = lib$initialize; #pragma standard #endif int main(int argc, char **argv) { if (argc > 1) set_only = atol(argv[1]); else set_only = -1; print_feature_settings(); } 2 decc$feature_get_name Returns a feature name. Format char *decc$feature_get_name (int index); 3 Argument index An integer value from 0 to the highest allocated feature. 3 Description This function returns a pointer to a null-terminated string containing the name of the feature for the entry specified by index. The index value can be 0 to the highest allocated feature. If there is no feature corresponding to the index value, then the function returns a NULL pointer. On error, NULL is returned and errno is set to indicate the error. Also see feature_get_index, feature_get_value, and feature_set_ value. 3 Return_Values x Pointer to a null-terminated string containing the name of the feature for the entry specified by index. NULL Indicates an error; errno is set. 3 Example See decc$feature_get_index for an example of retrieving and setting C RTL features. 2 decc$feature_get_value Returns a feature value depending on the mode argument. Format int decc$feature_get_value (int index, int mode); 3 Argument index An integer value from 0 to the highest allocated feature. mode An integer indicating which feature value to return. Values for mode: 0 - default value 1 - current value 2 - minimum value 3 - maximum value 4 - Initialization state 3 Description This function retrieves a value for the feature specified by index. The mode determines which value is returned. The default value is what is used if not set by a logical name or overidden by a call to decc$feature_set_value. If mode=4, the initialization state is returned. Values for the initialization state are: 0 - not initialized 1 - set by logical name 2 - forced by decc$feature_set_value -1 - initialized to default value On error, -1 is returned and errno is set to indicate the error. Also see feature_get_index, feature_get_name, and feature_set_ value. 3 Return_Values n An integer corresponding to the specified index and mode arguments. -1 Indicates an error; errno is set. 3 Example See decc$feature_get_index for an example of retrieving and setting C RTL features. 2 decc$feature_set_value Sets the default value or the current value for the feature specified by index. Format int decc$feature_set_value (int index, int mode, int value); 3 Argument index An integer value from 0 to the highest allocated feature. mode An integer indicating whether to set the default or current feature value. Values for mode: 0 - default value 1 - current value value The feature value to be set. 3 Description This function sets the default value or the current value (as determined by the mode argument) for the feature specified by index. If this function is successful, it returns the previous value. On error, -1 is returned and errno is set to indicate the error. Also see feature_get_index, feature_get_name, and feature_get_ value. 3 Return_Values n The previous feature value. -1 Indicates an error; errno is set. 3 Example See decc$feature_get_index for an example of retrieving and setting C RTL features. 2 decc$fix_time Converts OpenVMS binary system times to UNIX binary times. Format #include unsigned int decc$fix_time (void *vms_time); 3 Argument vms_time The address of a quadword containing an OpenVMS binary time: unsigned int quadword[2]; unsigned int *vms_time = quadword; 3 Description This routine converts an OpenVMS binary system time (a 64-bit quadword containing the number of 100-nanosecond ticks since 00:00 November 17, 1858) to a UNIX binary time (a longword containing the number of seconds since 00:00 January 1, 1970). This routine is useful for converting binary times returned by OpenVMS system services and RMS services to the format used by some Compaq C RTL routines, such as ctime and localtime. 3 Return_Values x A longword containing the number of seconds since 00:00 January 1, 1970. (unsigned int)(-1) Indicates an error. Be aware, that a return value of (unsigned int)(-1) can also represent a valid date of Sun Feb 7 06:28:15 2106. 3 Example #include #include #include /* VMS Specific SYS$ routines) */ main() { unsigned int current_vms_ time[2]; /* quadword for OpenVMS time */ unsigned int number_of_ seconds; /* number of seconds */ /* first get the current system time */ sys$gettim(¤t_vms_time[0]); /* fix the time */ number_of_seconds = decc$fix_time(¤t_vms_time[0]); printf("Number of seconds since 00:00 January 1, 1970 = %d", number_of_seconds); } This example shows how to use the decc$fix_time routine in Compaq C. It also shows the use of the SYS$GETTIM system service. 2 decc$from_vms Converts OpenVMS file specifications to UNIX style file specifications. Format #include int decc$from_vms (const char *vms_filespec, int action_routine, int wild_flag); 3 Arguments vms_filespec The address of a null-terminated string containing a name in OpenVMS file specification format. action_routine The address of a routine that takes as its only argument a null- terminated string containing the translation of the given OpenVMS file name to a valid UNIX style file name. If the action_routine returns a nonzero value (TRUE), file translation continues. If it returns a zero value (FALSE), no further file translation takes place. wild_flag Either 0 or 1, passed by value. If a 0 is specified, wildcards found in vms_filespec are not expanded. Otherwise, wildcards are expanded and each one is passed to action_routine. Only expanded file names that correspond to existing UNIX style files are included. 3 Description This routine converts the given OpenVMS file specification into the equivalent UNIX style file specification. It allows you to specify OpenVMS wildcards, which are translated into a list of corresponding existing files in UNIX style file specification format. 3 Return_Value x The number of file names that result from the specified OpenVMS file specification. 3 Example /* This example must be run as a foreign command */ /* and be supplied with a VMS file specification */ #include #include int main(int argc, char *argv[]) { int number_found; /* number of files found */ int print_name(); /* name printer */ printf("Translating: %s\n", argv[1]); number_found = decc$from_vms(argv[1], print_name, 1); printf("\n%d files found", number_found); } /* print the name on each line */ print_name(char *name) { printf("\n%s", name); /* will continue as long as success status is returned */ return (1); } This example shows how to use the decc$from_vms routine in Compaq C. It produces a simple form of the ls command that lists existing files that match an OpenVMS file specification supplied on the command line. The matching files are displayed in UNIX style file specification format. 2 decc$match_wild Matches a string to a pattern. Format #include int decc$match_wild (char *test_string, char *string_pattern); 3 Arguments test_string The address of a null-terminated string. string_pattern The address of a string containing the pattern to be matched. This pattern can contain wildcards (such as asterisks (*), question marks (?), and percent signs (%) as well as regular expressions (such as the range [a-z]). 3 Description This routine determines whether the specified test string is a member of the set of strings specified by the pattern. 3 Return_Values 1 (TRUE) The string matches the pattern. 0 (FALSE) The string does not match the pattern. 3 Example /* Define as a foreign command and then provide two */ /* arguments match_wild string_to_ test pattern */ #include #include int main(int argc, char *argv[]) { if (decc$match_wild(argv[1], argv[2])) printf("\n%s matches %s", argv[1], argv[2]); else printf("\n%s does not match %s", argv[1], argv[2]); } 2 decc$record_read Reads a record from a file. Format #include int decc$record_read (FILE *fp, void *buffer, int nbytes); 3 Arguments fp A file pointer. The specified file pointer must refer to a file currently opened for reading. buffer The address of contiguous storage in which the input data is placed. nbytes The maximum number of bytes involved in the read operation. 3 Description This function is specific to OpenVMS systems and should not be used when writing portable applications. The decc$record_read function is functionally equivalent to the read function, except that the first argument is a file pointer, not a file descriptor. 3 Return_Values x The number of characters read. -1 Indicates a read error, including physical input errors, illegal buffer addresses, protection violations, undefined file descriptors, and so forth. 2 decc$record_write Writes a record to a file. Format #include int decc$record_write (FILE *fp, void *buffer, int nbytes); 3 Arguments fp A file pointer. The specified file pointer must refer to a file currently opened for writing or updating. buffer The address of contiguous storage from which the output data is taken. nbytes The maximum number of bytes involved in the write operation. 3 Description This function is specific to OpenVMS systems and should not be used when writing portable applications. The decc$record_write function is functionally equivalent to the write function, except that the first argument is a file pointer, not a file descriptor. 3 Return_Values x The number of bytes written. -1 Indicates errors, including undefined file descriptors, illegal buffer addresses, and physical I/O errors. 2 decc$set_child_standard_streams For a child spawned by a function from the exec family of functions, associates specified file descriptors with a child's standard streams: stdin, stdout, and stderr. Format #include int decc$set_child_standard_streams (int fd1, int fd2, int fd3); 3 Arguments fd1 The file associated with this file descriptor in the parent process is associated with file descriptor number 0 (stdin) in the child process. If -1 is specified, the file associated with the parent's file descriptor number 0 is used (the default). fd2 The file associated with this file descriptor in the parent process is associated with file descriptor number 1 (stdout) in the child process. If -1 is specified, the file associated with the parent's file descriptor number 1 is used (the default). fd3 The file associated with this file descriptor in the parent process is associated with file descriptor number 2 (stderr) in the child process. If -1 is specified, the file associated with the parent's file descriptor number 2 is used (the default). 3 Description This function allows mapping of specified file descriptors to the child's stdin/out/err streams, thereby compensating, to a certain degree, the lack of a real fork function on OpenVMS systems. On UNIX systems, the code between fork and exec is executed in the context of the child process: parent: create pipes p1, p2 and p3 fork child: map stdin to p1 like dup2(stdin, p1); map stdout to p2 like dup2(stdout, p2); map stderr to p3 like dup2(stderr, p3); exec (child reads from stdin and writes to stdout and stderr) exit parent: communicates with the child using pipes On OpenVMS systems, the same task could be achieved as follows: parent: create pipes p1, p2 and p3 decc$set_child_standard_streams(p1, p2, p3); vfork exec (child reads from stdin and writes to stdout and stderr) parent: communicates with the child using pipes Once established through the call to decc$set_child_standard_ streams, the mapping of the child's standard streams remains in effect until explicitly disabled by one of the following calls: decc$set_child_standard_streams(-1, -1, -1); OR decc$set_child_standard_streams(0, 1, 2); Usually, the child process inherits all its parent's open file descriptors. However, if file descriptor number n was specified in the call to decc$set_child_standard_streams, it is not inherited by the child process as file descriptor number n; instead, it becomes one of the child's standard streams. NOTES o Standard streams can be redirected only to pipes. o If the parent process redefines the DCL DEFINE command, this redefinition is not in effect in a subprocess with user-defined channels. The subprocess always sees the standard DCL DEFINE command. o It is the responsibility of the parent process to consume all the output written by the child process to stdout and stderr. Depending on how the subprocess writes to stdout and stderr - in wait or nowait mode-the subprocess might be placed in LEF state waiting for the reader. For example, DCL writes to SYS$OUTPUT and SYS$ERROR in a wait mode, so a child process executing a DCL command procedure will wait until all the output is read by the parent process. Recommendation: Read the pipes associated with the child process' stdout and stderr in a loop until an EOF message is received, or declare write attention ASTs on these mailboxes. o The amount of data written to SYS$OUTPUT depends on the verification status of the process (SET VERIFY/NOVERIFY command); the subprocess inherits the verification status of the parent process. It is the caller's responsibility to set the verification status of the parent process to match the expected amount of data written to SYS$OUTPUT by the subprocess. o Some applications, like DTM, define SYS$ERROR as SYS$OUTPUT. If stderr is not redefined by the caller, it is set in the subprocess as the parent's SYS$ERROR, which in this case translates to the parent's SYS$OUTPUT. If the caller redefines stdout to a pipe and does not redefine stderr, output sent to stderr goes to the pipe associated with stdout, and the amount of data written to this mailbox may be more than expected. Although redefinition of any subset of standard channels is supported, it is always safe to explicitly redefine all of them (or at least stdout and stderr) to avoid this situation. o For a child process executing a DCL command procedure, SYS$COMMAND is set to the pipe specified for the child's stdin so that the parent process can feed the child requesting data from SYS$COMMAND through the pipe. For DCL command procedures, it is impossible to pass data from the parent to the child by means of the child's SYS$INPUT because for a command procedure, DCL defines SYS$INPUT as the command file itself. 3 Return_Value x The number of file descriptors set for the child. This number does not include file descriptors specified as -1 in the call. -1 indicates that an invalid file descriptor was specified; errno is set to EBADF. 3 Example parent.c ======== #include #include #include int decc$set_child_standard_streams(int, int, int); main() { int fdin[2], fdout[2], fderr[2]; char msg[] = "parent writing to child's stdin"; char buf[80]; int nbytes; pipe(fdin); pipe(fdout); pipe(fderr); if ( vfork() == 0 ) { decc$set_child_standard_ streams(fdin[0], fdout[1], fderr[1]); execl( "child", "child" ); } else { write(fdin[1], msg, sizeof(msg)); nbytes = read(fdout[0], buf, sizeof(buf)); buf[nbytes] = '\0'; puts(buf); nbytes = read(fderr[0], buf, sizeof(buf)); buf[nbytes] = '\0'; puts(buf); } } child.c ======= #include #include main() { char msg[] = "child writing to stderr"; char buf[80]; int nbytes; nbytes = read(0, buf, sizeof(buf)); write(1, buf, nbytes); write(2, msg, sizeof(msg)); } child.com ========= $ read sys$command s $ write sys$output s $ write sys$error "child writing to stderr" This example program returns the following for both child.c and child.com: $ run parent parent writing to child's stdin child writing to stderr Note that in order to activate child.com, you must explicitly specify execl("child.com", ...) in the parent.c program. 2 decc$set_reentrancy Controls the type of reentrancy that reentrant Compaq C RTL routines will exhibit. Format #include int decc$set_reentrancy (int type); 3 Argument type The type of reentrancy desired. Use one of the following values: o C$C_MULTITHREAD - Designed to be used in conjunction with the DECthreads product. It performs DECthreads locking and never disables ASTs. DECthreads must be available on your system to use this form of reentrancy. o C$C_AST - Uses the _BBSSI (VAX only) or __TESTBITSSI (Alpha only) built-in function to perform simple locking around critical sections of RTL code, and it may additionally disable asynchronous system traps (ASTs) in locked regions of code. This type of locking should be used when AST code contains calls to Compaq C RTL I/O routines, or when the user application disables ASTs. o C$C_TOLERANT - Uses the _BBSSI (VAX only) or __TESTBITSSI (Alpha only) built-in function to perform simple locking around critical sections of RTL code, but ASTs are not disabled. This type of locking should be used when ASTs are used and must be delivered immediately. TOLERANT is the default reentrancy type. o C$C_NONE - Gives optimal performance in the Compaq C RTL, but does absolutely no locking around critical sections of RTL code. It should only be used in a single-threaded environment when there is no chance that the thread of execution will be interrupted by an AST that would call the Compaq C RTL. The reentrancy type can be raised but never lowered. The ordering of reentrancy types from low to high is C$C_NONE, C$C_TOLERANT, C$C_AST and C$C_MULTITHREAD. For example, once an application is set to multithread, a call to set the reentrancy to AST is ignored. A call to decc$set_reentrancy that attempts to lower the reentrancy type returns a value of -1. 3 Description Use this function to change the type of reentrancy exhibited by reentrant routines. decc$set_reentrancy must be called exclusively at the non-AST level. In an application using DECthreads, DECthreads automatically sets the reentrancy to multithread. 3 Return_Value type The type of reentrancy used before this call. -1 The reentrancy was set to a lower type. 2 decc$to_vms Converts UNIX style file specifications to OpenVMS file specifications. Format #include int decc$to_vms (const char *unix_style_filespec, int (*action_routine)(char *unix_style_filespec, int type_of_file), int allow_wild, int no_directory); 3 Arguments unix_style_filespec The address of a null-terminated string containing a name in UNIX style file specification format. action_routine The address of a routine that accepts the following arguments: o A pointer to a null-terminated string that contains the UNIX style file name to be translated to a valid OpenVMS file name o An integer that has one of the following values: Value Translation 0 (DECC$K_ A file on a remote system that is not running FOREIGN) the OpenVMS or VAXELN operating system. 2 (DECC$K_ The OpenVMS translation of the UNIX style DIRECTORY) file name is a directory. 1 (DECC$K_FILE) The translation is a file. These values can be defined symbolically with the symbols DECC$K_FOREIGN, DECC$K_DIRECTORY, and DECC$K_FILE. See the example for more information. If action_routine returns a nonzero value (TRUE), file translation continues. If it returns a 0 value (FALSE), no further file translation takes place. allow_wild Either 0 or 1, passed by value. If a 0 is specified, wildcards found in unix_style_filespec are not expanded. Otherwise, wildcards are expanded and each one is passed to action_routine. Only expanded file names that correspond to existing OpenVMS files are included. no_directory An integer that has one of the following values: Value Translation 0 Directory is not allowed. 1 Prevent expansion of the string as a directory name. 2 Forced to be a directory name. 3 Description This routine converts the given UNIX style file specification into the equivalent OpenVMS file specification (in all uppercase letters). It allows you to specify UNIX style wildcards, which are translated into a list of corresponding OpenVMS files. 3 Return_Value x The number of file names that result from the specified UNIX style file specification. 3 Example /* Translate "Unix" wildcard file names to VMS names */ /* Define as a foreign command and provide the name */ /* as an argument. */ #include #include int print_name(char *, int); int main(int argc, char *argv[]) { int number_found; /* number of files found */ printf("Translating: %s\n", argv[1]); number_found = decc$to_vms(argv[1], print_name, 1, 0); printf("%d files found\n", number_found); } /* action routine that prints name and type on each line */ int print_name(char *name, int type) { if (type == DECC$K_DIRECTORY) printf("directory: %s\n", name); else if (type == DECC$K_FOREIGN) printf("remote non-VMS: %s\n", name); else printf("file: %s\n", name); /* Translation continues as long as success status is returned */ return (1); } This example shows how to use the decc$to_vms routine in Compaq C. It takes a UNIX style file specification argument and displays, in OpenVMS file specification format, the name of each existing file that matches it. 2 decc$translate_vms Translates OpenVMS file specifications to UNIX style file specifications. Format #include char *decc$translate_vms (const char *vms_filespec); 3 Argument vms_filespec The address of a null-terminated string containing a name in OpenVMS file specification format. 3 Description This function translates the given OpenVMS file specification into the equivalent UNIX style file specification, whether or not the file exists. The translated name string is stored in a thread-specific memory, which is overwritten by each call to decc$translate_vms from the same thread. This function differs from the decc$from_vms function, which does the conversion for existing files only. 3 Return_Values x The address of a null-terminated string containing a name in UNIX style file specification format. 0 Indicates that the file name is null or syntactically incorrect. -1 Indicates that the file specification contains an ellipsis (for example, [ . . . ]a.dat), but is otherwise correct. You cannot translate the OpenVMS ellipsis syntax into a valid UNIX style file specification. 3 Example /* Demonstrate translation of a "UNIX" name to VMS form */ /* define a foreign command and pass the name as the */ /* argument. */ #include #include int main(int argc, char *argv[]) { char *ptr; /* translation result */ ptr = decc$translate_vms( argv[1] ); if ((int) ptr == 0 || (int) ptr == -1) printf( "could not translate %s\n", argv[1]); else printf( "%s is translated to %s\n", argv[1], ptr ); } 2 decc$validate_wchar Confirms that its argument is a valid wide character in the current program's locale. Format #include int decc$validate_wchar (wchar_t wc); 3 Argument wc Wide character to be validated. 3 Description This function provides a convenient way to verify whether a specified argument of wchar_t type is a valid wide character in the current program's locale. One reason to call decc$validate_wchar is that the isw* wide- character classification functions and macros do not validate their argument before dereferencing the classmask array describing character properties. Passing an isw* function a value that exceeds the maximum wide-character value for the current program's locale can result in an attempt to access memory beyond the allocated classmask array. A standard way to validate a wide character is to call the wctomb function, but this way is less convenient because it requires declaring a multibyte character array of sufficient size and passing it to wctomb. 3 Return_Values 1 Indicates that the specified wide character is a valid wide character in the current program's locale. 0 Indicates that the specified wide character is not a valid wide character in the current program's locale. errno is not set. 2 decc$write_eof_to_mbx Writes an end-of-file message to the mailbox. Format #include int decc$write_eof_to_mbx (int fd); 3 Argument fd File descriptor associated with the mailbox. 3 Description This function writes end-of-file message to the mailbox. For a mailbox that is not a pipe, the write function called with an nbytes argument value of 0 sends an end-of-file message to the mailbox. For a pipe, however, the only way to write an end-of- file message to the mailbox is to close the pipe. If the child's standard input is redirected to a pipe through a call to the decc$set_child_standard_streams function, the parent process can call decc$write_eof_to_mbx for this pipe to send an EOF message to the child. It has the same effect as if the child read the data from a terminal, and Ctrl/Z was pressed. After a call to decc$write_eof_to_mbx, the pipe can be reused for communication with another child, for example. This is the purpose of decc$write_eof_to_mbx: to allow reuse of the pipe instead of having to close it just to send an end-of-file message. 3 Return_Values 0 Indicates success -1 Indicates failure; errno and vaxc$errno are set according to the failure status returned by SYS$QIOW. 3 Example /* decc$write_eof_to_mbx_example.c */ #include #include #include #include #include #include #include #include #include int decc$write_eof_to_mbx( int ); main() { int status, nbytes, failed = 0; int fd, fd2[2]; short int channel; $DESCRIPTOR(mbxname_dsc, "TEST_MBX"); char c; /* first try a mailbox created by SYS$CREMBX */ status = sys$crembx(0, &channel, 0, 0, 0, 0, &mbxname_dsc, 0, 0); if ( status != SS$_NORMAL ) { printf("sys$crembx failed: %s\n",strerror(EVMSERR, status)); failed = 1; } if ((fd = open(mbxname_dsc.dsc$a_pointer, O_RDWR, 0)) == -1 ) { perror("? open mailbox"); failed = 1; } if ( decc$write_eof_to_mbx(fd) == -1 ) { perror("? decc$write_eof_to_mbx to mailbox"); failed = 1; } if ( (nbytes = read(fd, &c, 1)) != 0 || errno != 0 ) { perror("? read mailbox"); printf("? nbytes = %d\n", nbytes); failed = 1; } if ( close(fd) == -1 ) { perror("? close mailbox"); failed = 1; } /* Now do the same thing with a pipe */ errno = 0; /* Clear errno for consistency */ if ( pipe(fd2) == -1 ) { perror("? opening pipe"); failed = 1; } if ( decc$write_eof_to_mbx(fd2[1]) == -1 ) { perror("? decc$write_eof_to_mbx to pipe"); failed = 1; } if ( (nbytes = read(fd2[0], &c, 1)) != 0 || errno != 0 ) { perror("? read pipe"); printf("? nbytes = %d\n", nbytes); failed = 1; } /* Close both file descriptors involved with the pipe */ if ( close(fd2[0]) == -1 ) { perror("close(fd2[0])"); failed = 1; } if ( close(fd2[1]) == -1 ) { perror("close(fd2[1])"); failed = 1; } if ( failed ) puts("?Example program failed"); else puts("Example ran to completion"); } This example program produces the following result: Example ran to completion 2 [w]delch Delete the character on the specified window at the current position of the cursor. The delch function operates on the stdscr window. Format #include int delch(); int wdelch (WINDOW *win); 3 Argument win A pointer to the window. 3 Description All of the characters to the right of the cursor on the same line are shifted to the left, and a blank character is appended to the end of the line. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 delete Deletes a file. Format #include int delete (const char *file_spec); 3 Argument file_spec A pointer to the string that is an OpenVMS or UNIX style file specification. The file specification can include a wildcard in its version number (but not in any other part of the file spec). So, for example, files of the form filename.txt;* can be deleted. 3 Description If you specify a directory in the file name and it is a search list that contains an error, Compaq C for OpenVMS Systems interprets it as a file error. The remove and delete functions are functionally equivalent in the Compaq C RTL. See also remove. NOTE The delete routine is not available to C++ programmers because it conflicts with the C++ reserved word delete. C++ programmers should use the ANSI/ISO C standard function remove instead. 3 Return_Values 0 Indicates success. nonzero value Indicates that the operation has failed. 2 [w]deleteln Delete the line at the current position of the cursor. The deleteln function acts on the stdscr window. Format #include int deleteln(); int wdeleteln (WINDOW *win); 3 Argument win A pointer to the window. 3 Description Every line below the deleted line moves up, and the bottom line becomes blank. The current (y,x) coordinates of the cursor remain unchanged. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 delwin Deletes the specified window from memory. Format #include int delwin (WINDOW *win); 3 Argument win A pointer to the window. 3 Description If the window being deleted contains a subwindow, the subwindow is invalidated. Delete subwindows before deleting their parent. The delwin function refreshes all windows covered by the deleted window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 difftime Computes the difference, in seconds, between the two times specified by the time1 and time2 arguments. Format #include double difftime (time_t time2, time_t time1); 3 Arguments time2 A time value of type time_t. time1 A time value of type time_t. 3 Description The type time_t is defined in the header file as follows: typedef unsigned long int time_t 3 Return_Value n time2 - time1 in seconds expressed as a double. 2 dirname Reports the parent directory name of a file path name. Format #include char *dirname (char *path); 3 Function_Variants This function also has variants named _dirname32 and _dirname64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument path The file path name. 3 Description This function takes a pointer to a character string that contains a UNIX path name and returns a pointer to a string that is a path name of the parent directory of that file. Trailing '/' (slash) characters in the path are not counted as part of the path. The dirname function returns a pointer to the string "." (dot), when the path argument: o Does not contain a '/' (slash). o Is a NULL pointer. o Points to an empty string. The dirname function can modify the string pointed to by the path argument. The dirname and basename functions together yield a complete path name. The expression dirname(path) obtains the path name of the directory where basename(path) is found. See also basename. 3 Return_Values x A pointer to a string that is the parent directory of the path argument. "." The path argument: o Does not contain a '/' (slash). o Is a NULL pointer. o Points to an empty string. 3 Example Using the dirname function, the following example reads a path name, changes the current working directory to the parent directory, and opens a file. char path [MAXPATHLEN], *pathcopy; int fd; fgets(path, MAXPATHLEN, stdin); pathcopy = strdup(path); chdir(dirname(pathcopy)); fd = open(basename(path), O_RDONLY); 2 div Returns the quotient and the remainder after the division of its arguments. Format #include div_t div (int numer, int denom); 3 Arguments numer A numerator of type int. denom A denominator of type int. 3 Description The type div_t is defined in the standard header file as follows: typedef struct { int quot, rem; } div_t; 2 dlclose Deallocates the address space for a shared library. Format #include void dlclose (void *handle); 3 Arguments handle Pointer to the shared library. 3 Description The dlclose function deallocates the address space allocated by the Compaq C RTL for the handle. There is no way on OpenVMS systems to "unload" a shareable image dynamically loaded by the LIB$FIND_IMAGE_SYMBOL routine, which is the routine called by the dlsym function. In other words, there is no way on OpenVMS systems to release the address space occupied by the shareable image brought into memory by dlsym. 2 dlerror Returns a string describing the last error that occurred from a call to dlopen, dlclose, or dlsym. Format #include char *dlerror (void); 3 Return_Values x A string describing the last error that occurred from a call to dlopen, dlclose, or dlsym. 2 dlopen Provides an interface to the dynamic library loader to allow shareable images to be loaded and called at run time. Format #include void *dlopen (char *pathname, int mode); 3 Arguments pathname The name of the shareable image. This name is saved for subsequent use by the dlsym function. mode This argument is ignored on OpenVMS systems. 3 Description This function provides an interface to the dynamic library loader to allow shareable images to be loaded and called at run time. The dlopen function does not load a shareable image but rather saves its pathname argument for subsequent use by the dlsym function. dlsym is the function that actually loads the shareable image through a call to LIB$FIND_IMAGE_SYMBOL. The pathname argument of the dlopen function must be the name of the shareable image. This name is passed as-is by the dlsym function to the LIB$FIND_IMAGE_SYMBOL routine as the filename argument. No image-name argument is specified in the call to LIB$FIND_IMAGE_SYMBOL, so default file specification of SYS$SHARE:.EXE is applied to the image name. The dlopen function returns a handle that is used by a dlsym or dlclose call. If an error occurs, a NULL pointer is returned. 3 Return_Values x A handle to be used by a dlsym or dlclose call. NULL Indicates an error. 2 dlsym Returns the address of the symbol name found in a shareable image. Format #include void *dlsym (void *handle, char *name); 3 Arguments handle Pointer to the shareable image. 3 Description The dlsym function returns the address of the symbol name found in the shareable image corresponding to handle. If the symbol is not found, a NULL pointer is returned. 3 Return_Values x Address of the symbol name found. NULL Indicates that the symbol was not found. 2 drand48 Generates uniformly distributed pseudorandom number sequences. Returns 48-bit, nonnegative, double-precision floating-point values. Format #include double drand48 (void); 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. It returns non-negative, double-precision, floating-point values uniformly distributed over the range of y values such that 0.0 y < 1.0. Before you call drand48, use either srand48, seed48, or lcong48 to initialize the random number generator. You must initalize prior to invoking the drand48 function because it stores the last 48-bit Xi generated into an internal buffer. (Although it is not recommended, constant default initializer values are supplied automatically if the drand48, lrand48, or mrand48 functions are called without first calling an initialization function.) The drand48 function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke lcong48, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The values returned by drand48 are computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of returned data item, are copied from the high-order (most significant) bits of Xi and transformed into the returned value. See also srand48, seed48, lcong48, lrand48, and mrand48. 3 Return_Values n A nonnegative, double-precision, floating- point value. 2 dup,_dup2 Allocate a new descriptor that refers to a file specified by a file descriptor returned by open, creat, or pipe. Format #include int dup (int file_desc1); int dup2 (int file_desc1, int file_desc2); 3 Arguments file_desc1 The file descriptor being duplicated. file_desc2 The new file descriptor to be assigned to the file designated by file_desc1. 3 Description The dup function causes a previously unallocated descriptor to refer to its argument, while the dup2 function causes its second argument to refer to the same file as its first argument. The argument file_desc1 is invalid if it does not describe an open file; file_desc2 is invalid if the new file descriptor cannot be allocated. If file_desc2 is connected to an open file, that file is closed. 3 Return_Values n The new file descriptor. -1 Indicates that an invalid argument was passed to the function. 2 [no]echo Set the terminal so that characters may or may not be echoed on the terminal screen. This mode of single-character input is only supported with Curses. Format #include void echo (void); void noecho (void); 3 Description The noecho function may be helpful when accepting input from the terminal screen with wgetch and wgetstr; it prevents the input characters from being written onto the screen. 2 ecvt Converts its argument to a null-terminated string of ASCII digits and returns the address of the string. The string is stored in a thread-specific memory location created by the Compaq C RTL. Format #include char *ecvt (double value, int ndigits, int *decpt, int *sign); 3 Arguments value An object of type double that is converted to a null-terminated string of ASCII digits. ndigits The number of ASCII digits to be used in the converted string. decpt The position of the decimal point relative to the first character in the returned string. A negative int value means that the decimal point is decpt number of spaces to the left of the returned digits, (the spaces being filled with zeros). A 0 value means that the decimal point is immediately to the left of the first digit in the returned string. sign An integer value that indicates whether the value argument is positive or negative. If value is negative, the function places a nonzero value at the address specified by sign. Otherwise, the function assigns 0 to the address specified by sign. 3 Description This function converts value to a null-terminated string of length ndigits, and returns a pointer to it. The resulting low-order digit is rounded to the correct digit for outputting ndigits digits in C E-format. The decpt argument is assigned the position of the decimal point relative to the first character in the string. Repeated calls to the ecvt function overwrite any existing string. The ecvt, fcvt, and gcvt functions represent the following special values specified in the IEEE Standard for floating-point arithmetic: Value Representation Quiet NaN NaNQ Signalling NaNS NaN +Infinity Infinity -Infinity -Infinity The sign associated with each of these values is stored into the sign argument. In IEEE floating-point representation, a value of 0 (zero) can be positive or negative, as set by the sign argument. See also gcvt and fcvt. 3 Return_Value x The value of the converted string. 2 endpwent Closes the user database. Format #include #include void endpwent (void); 3 Description This function closes the user database. The user database basic user attributes are accessed with the getpwent, getpwuid, getpwnam, or setpwent functions. See also getpwent, getpwuid, getpwnam, and setpwent. 2 endwin Clears the terminal screen and frees any virtual memory allocated to Curses data structures. Format #include void endwin (void); 3 Description A program that calls Curses functions must call the endwin function before exiting to restore the previous environment of the terminal screen. 2 erand48 Generate uniformly distributed pseudorandom number sequences. Returns 48-bit nonnegative, double-precision, floating-point values. Format #include double erand48 (unsigned short int xsubi[3]); 3 Argument xsubi An array of three short int, which form a 48-bit integer when concatentated together. 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. It returns nonnegative, double-precision, floating-point values uniformly distributed over the range of y values, such that, 0.0 The erand48 function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The erand48 function requires that the calling program pass an array as the xsubi argument. For the first call, the array must be initialized to the value of the pseudorandom number sequence. Unlike the drand48 function, it is not necessary to call an initialization function prior to the first call. By using different arguments, the erand48 function allows separate modules of a large program to generate several independent sequences of pseudorandom numbers; for example, the sequence of numbers that one module generates does not depend upon how many times the function is called by other modules. 3 Return_Values n A nonnegative, double-precision, floating- point value. 2 [w]erase Erase the window by painting it with blanks. The erase function acts on the stdscr window. Format #include int erase(); int werase (WINDOW *win); 3 Argument win A pointer to the window. 3 Description Both the erase and werase functions leave the cursor at the current position on the terminal screen after completion; they do not return the cursor to the home coordinates of (0,0). 3 Return_Values OK Indicates success. ERR Indicates an error. 2 erf Returns the error function of its argument. Format #include double erf (double x); float erff (float x); (Alpha only) long double erfl (long double x); (Alpha only) double erfc (double x); (Alpha only) float erfcf (float x); (Alpha only) long double erfcl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number. 3 Description The erf functions return the error function of x, where erf(x), erff(x), and erfl(x) equal (2/sqrt(pi)) times the area under the curve e**(-t**2) between 0 and x. The erfc functions return (1.0 - erf(x)). The erfc function can result in an underflow as x gets large. 3 Return_Values x The value of the error function (erf) or complementary error function (erfc). NaN x is NaN; errno is set to EDOM. 0 Underflow ocurred; errno is set to ERANGE. 2 execl Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execl (const char *file_spec, const char *arg0, . . . , (char *)0); (ISO POSIX-1) int execl (char *file_spec, . . . ); (Compatability) 3 Arguments file_spec The full file specification of a new image to be activated in the child process. arg0, ... A sequence of pointers to null-terminated character strings. If the POSIX-1 format is used, at least one argument must be present and must point to a string that is the same as the new process file name (or its last component). (This pointer can also be the NULL pointer, but then execle would accomplish nothing.) The last pointer must be the NULL pointer. This is also the convention if the compatibility format is used. 3 Description To understand how the exec functions operate, consider how the OpenVMS system calls any Compaq C program, as shown in the following syntax: int main (int argc, char *argv[], char *envp[]); The identifier argc is the argument count; argv is an array of argument strings. The first member of the array (argv[0]) contains the name of the image. The arguments are placed in subsequent elements of the array. The last element of the array is always the NULL pointer. An exec function calls a child process in the same way that the run-time system calls any other Compaq C program. The exec functions pass the name of the image to be activated in the child; this value is placed in argv[0]. However, the functions differ in the way they pass arguments and environment information to the child: o Arguments can be passed in separate character strings (execl, execle, and execlp) or in an array of character strings (execv, execve, and execvp). o The environment can be explicitly passed in an array (execle and execve) or taken from the parent's environment (execl, execv, execlp, and execvp). If vfork was called before invoking an exec function, then when the exec function completes, control is returned to the parent process at the point of the vfork call. If vfork was not called, the exec function waits until the child has completed execution and then exits the parent process. See vfork. 3 Return_Value -1 Indicates failure. 2 execle Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execle (char *file_spec, char *arg0, . . . , (char *)0, char *envp[]); (ISO POSIX-1) int execle (char *file_spec, . . . ); (Compatability) 3 Arguments file_spec The full file specification of a new image to be activated in the child process. arg0, ... A sequence of pointers to null-terminated character strings. If the POSIX-1 format is used, at least one argument must be present and must point to a string that is the same as the new process file name (or its last component). (This pointer can also be the NULL pointer, but then execle would accomplish nothing.) The last pointer must be the NULL pointer. This is also the convention if the compatibility format is used. envp An array of strings that specifies the program's environment. Each string in envp has the following form: name = value The name can be one of the following names and the value is a null-terminated string to be associated with the name: o HOME-Your login directory o TERM-The type of terminal being used o PATH-The default device and directory o USER-The name of the user who initiated the process The last element in envp must be the NULL pointer. When the operating system executes the program, it places a copy of the current environment vector (envp) in the external variable environ. 3 Description See execl for a description of how the exec functions operate. 3 Return_Value -1 Indicates failure. 2 execlp Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execlp (const char *file_name, const char *arg0, . . . , (char *)0); (ISO POSIX-1) int execlp (char *file_name, . . . ); (Compatability) 3 Arguments file_name The file name of a new image to be activated in the child process. The device and directory specification for the file is obtained by searching the environment name VAXC$PATH. argn A sequence of pointers to null-terminated character strings. By convention, at least one argument must be present and must point to a string that is the same as the new process file name (or its last component). . . . A sequence of pointers to strings. At least one pointer must exist to terminate the list. This pointer must be the NULL pointer. 3 Description See execl for a description of how the exec functions operate. 3 Return_Value -1 Indicates failure. 2 execv Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execv (char *file_spec, char *argv[]); 3 Arguments file_spec The full file specification of a new image to be activated in the child process. argv An array of pointers to null-terminated character strings. These strings constitute the argument list available to the new process. By convention, argv[0] must point to a string that is the same as the new process file name (or its last component). argv is terminated by a NULL pointer. 3 Description See execl for a description of how the exec functions operate. 3 Return_Value -1 Indicates failure. 2 execve Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execve (const char *file_spec, char *argv[], char *envp[]); 3 Arguments file_spec The full file specification of a new image to be activated in the child process. argv An array of pointers to null-terminated character strings. These strings constitute the argument list available to the new process. By convention, argv[0] must point to a string that is the same as the new process file name (or its last component). argv is terminated by a NULL pointer. envp An array of strings that specifies the program's environment. Each string in envp has the following form: name = value The name can be one of the following names and the value is a null-terminated string to be associated with the name: o HOME-Your login directory o TERM-The type of terminal being used o PATH-The default device and directory o USER-The name of the user who initiated the process The last element in envp must be the NULL pointer. When the operating system executes the program, it places a copy of the current environment vector (envp) in the external variable environ. 3 Description See execl for a description of how the exec functions operate. 3 Return_Value -1 Indicates failure. 2 execvp Passes the name of an image to be activated in a child process. This function is nonreentrant. Format #include int execvp (const char *file_name, char *argv[]); 3 Arguments file_name The file name of a new image to be activated in the child process. The device and directory specification for the file is obtained by searching the environment name VAXC$PATH. argv An array of pointers to null-terminated character strings. These strings constitute the argument list available to the new process. By convention, argv[0] must point to a string that is the same as the new process file name (or its last component). argv is terminated by a NULL pointer. 3 Description See execl for a description of how the exec functions operate. 3 Return_Value -1 Indicates failure. 2 exit,__exit Terminate execution of the program from which they are called. These functions are nonreentrant. Format #include void exit (int status); #include void _exit (int status); 3 Argument status A status value of EXIT_SUCCESS (0), EXIT_FAILURE (1), or a number from 2 to 255: o A status value of 0 or EXIT_SUCCESS is translated to the OpenVMS SS$_NORMAL status code to return the OpenVMS success value. o A status value of 1 or EXIT_FAILURE is translated to an error- level exit status. The status value is passed to the parent process. o Any other status value is left the same. To use these status values as described, include and compile with the _POSIX_EXIT feature-test macro set (either with /DEFINE=_POSIX_EXIT or with #define _POSIX_EXIT at the top of your file, before any file inclusions). This behavior is available only on OpenVMS Version 7.0 and higher systems. 3 Description If the process was invoked by the DIGITAL Command Language (DCL), the status is interpreted by DCL and a message is displayed. If the process was a child process created using vfork or an exec function, then the child process exits and control returns to the parent. The two functions are identical; the _exit function is retained for reasons of compatibility with VAX C. The exit and _exit functions make use of the $EXIT system service. If your process is being invoked by the RUN command using any of the hibernation and scheduled wakeup qualifiers, the process might not correctly return to hibernation state when an exit or _exit call is made. NOTE EXIT_SUCCESS and EXIT_FAILURE are portable across any ANSI C compiler to indicate success or failure. On OpenVMS systems, they are mapped to OpenVMS condition codes with the severity set to success or failure, respectively. Values in the range of 2 to 255 can be used by a child process to communicate a small amount of data to the parent. The parent retreives this data using the wait, wait3, wait4, or waitpid functions. 2 exp Returns the base e raised to the power of the argument. Format #include double exp (double x); float expf (float x); (Alpha only) long double expl (long double x); (Alpha only) double expm1 (double x); (Alpha only) float expm1f (float x); (Alpha only) long double expm1l (long double x); (Alpha only) 3 Argument x A real value. 3 Description The exp functions compute the value of the exponential function, defined as e**x, where e is the constant used as a base for natural logarithms. The expm1 functions compute exp(x) - 1 accurately, even for tiny x. If an overflow occurs, the exp functions return the largest possible floating-point value and set errno to ERANGE. The constant HUGE_VAL is defined in the header file to be the largest possible floating-point value. 3 Return_Values x The exponential value of the argument. HUGE_VAL Overflow occurred; errno is set to ERANGE. 0 Underflow occurred; errno is set to ERANGE. NaN x is NaN; errno is set to EDOM. 2 fabs Returns the absolute value of its argument. Format #include double fabs (double x); float fabsf (float x); (Alpha only) long double fabsl (long double x); (Alpha only) 3 Argument x A real value. 3 Return_Value x The absolute value of the argument. 2 fchown Changes the owner and group of a file. Format #include int fchown (int fildes, uid_t owner, gid_t group); 3 Arguments fildes An open file descriptor. owner A user ID corresponding to the new owner of the file. group A group ID corresponding to the group of the file. 3 Description The fchown function has the same effect as chown except that the file whose owner and group are to be changed is specified by the file descriptor fildes. 3 Return_Values 0 Indicates success. -1 Indicates failure. The function sets errno to one of the following values: The fchown function will fail if: o EBADF - The fildes argument is not an open file descriptor. o EPERM - The effective user ID does not match the owner of the file, or the process does not have appropriate privilege. o EROFS - The file referred to by fildes resides on a read-only file system. The fchown function may fail if: o EINVAL - The owner or group ID is not a value supported by the implementation. o EIO - A physical I/O error has occurred. o EINTR - The fchown function was interrupted by a signal that was caught. 2 fclose Closes a file by flushing any buffers associated with the file control block and freeing the file control block and buffers previously associated with the file pointer. Format #include int fclose (FILE *file_ptr); 3 Argument file_ptr A pointer to the file to be closed. 3 Description When a program terminates normally, the fclose function is automatically called for all open files. The fclose function tries to write buffered data by using an implicit call to fflush. If the write fails (because the disk is full or the user's quota is exceeded, for example), fclose continues executing. It closes the VMS channel, deallocates any buffers, and releases the memory associated with the file descriptor (or FILE pointer). Any buffered data is lost, and the file descriptor (or FILE pointer) no longer refers to the file. If your program needs to recover from errors when flushing buffered data, it should make an explicit call to fsync (or fflush) before calling fclose. 3 Return_Values 0 Indicates success. EOF Indicates that the file control block is not associated with an open file. 2 fcntl Performs controlling operations on an open file. Format #include #include #include int fcntl (int file_desc, int request [, int file_desc2]); 3 Arguments file_desc An open file descriptor obtained from a successful open, fcntl, or pipe function. request The operation to be performed. file_desc2 A variable that depends on the value of the request argument. 3 Description The fcntl function performs controlling operations on the open file specified by the file_desc argument. The values for the request argument are defined in the header file , and include the following: F_DUPFD Returns a new file descriptor that is the lowest numbered available (that is, not already open) file descriptor greater than or equal to the third argument (file_desc2) taken as an integer of type int. The new file descriptor refers to the same file as the original file descriptor (file_desc). The FD_ CLOEXEC flag associated with the new file descriptor is cleared to keep the file open across calls to one of the exec functions. The following two calls are equivalent: fid = dup(file_desc); fid = fcntl(file_desc, F_DUPFD, 0); The following call fid = dup2(file_desc, file_desc2); is similar (but not equivalent) to: close(file_desc2); fid = fcntl(file_desc, F_DUPFD, file_desc2); F_GETFD Gets the value of the close-on-exec flag associated with the file descriptor file_desc. File descriptor flags are associated with a single file descriptor and do not affect other file descriptors that refer to the same file. The file_desc2 argument should not be specified. F_SETFD Sets the close-on-exec flag associated with file_ desc to the value of the third argument, taken as type int: If the third argument is 0 (zero), the file remains open across the exec functions, which means that a child process spawned by the exec function inherits this file descriptor from the parent. If the third argument is FD_CLOEXEC, the file is closed on successful execution of the next exec function, which means that the child process spawned by the exec function will not inherit this file descriptor from the parent. 3 Return_Values n Upon successful completion, the value returned depends on the value of the request argument as follows: o F_DUPFD - Returns a new file descriptor. o F_GETFD - Returns FD_CLOEXEC or 0 (zero). o F_SETFD - Returns a value other than -1. -1 Indicates that an error occurred. The function sets errno to the following value: o EBADF - The file_desc argument is not a valid open file descriptor and the file_ desc2 argument is negative or greater than or equal to the per-process limit. o EFAULT - The file_desc2 argument is an invalid address. o EINVAL - The request argument is F_DUPFD and the file_desc2 argument is negative or greater than or equal to OPEN_MAX. Either the OPEN_MAX value or the per- process soft descriptor limit is checked. An illegal value was provided for the request argument. o EMFILE - The request argument is F_DUPFD and too many or OPEN_MAX file descriptors are currently open in the calling process, or no file descriptors greater than or equal to argument are available. Either the OPEN_MAX value or the per- process soft descriptor limit is checked. o ENOMEM - The system was unable to allocate memory for the requested file descriptor. 2 fcvt Converts its argument to a null-terminated string of ASCII digits and returns the address of the string. The string is stored in a thread-specific location created by the Compaq C RTL. Format #include char *fcvt (double value, int ndigits, int *decpt, int *sign); 3 Arguments value An object of type double that is converted to a null-terminated string of ASCII digits. ndigits The number of ASCII digits after the decimal point to be used in the converted string. decpt The position of the decimal point relative to the first character in the returned string. The returned string does not contain the actual decimal point. A negative int value means that the decimal point is decpt number of spaces to the left of the returned digits (the spaces are filled with zeros). A 0 value means that the decimal point is immediately to the left of the first digit in the returned string. sign An integer value that indicates whether the value argument is positive or negative. If value is negative, the fcvt function places a nonzero value at the address specified by sign. Otherwise, the functions assign 0 to the address specified by sign. 3 Description This function converts value to a null-terminated string and returns a pointer to it. The resulting low-order digit is rounded to the correct digit for outputting ndigits digits in C F-format. The decpt argument is assigned the position of the decimal point relative to the first character in the string. In C F-format, ndigits is the number of digits desired after the decimal point. Very large numbers produce a very long string of digits before the decimal point, and ndigit of digits after the decimal point. For large numbers, it is preferable to use the gcvt or ecvt function so that E-format is used. Repeated calls to the fcvt function overwrite any existing string. The ecvt, fcvt, and gcvt functions represent the following special values specified in the IEEE Standard for floating-point arithmetic: Value Representation Quiet NaN NaNQ Signalling NaNS NaN +Infinity Infinity -Infinity -Infinity The sign associated with each of these values is stored into the sign argument. In IEEE floating-point representation, a value of 0 (zero) can be positive or negative, as set by the sign argument. See also gcvt and ecvt. 3 Return_Value x A pointer to the converted string. 2 fdopen Associates a file pointer with a file descriptor returned by an open, creat, dup, dup2, or pipe function. Format #include FILE *fdopen (int file_desc, char *a_mode); 3 Arguments file_desc The file descriptor returned by open, creat, dup, dup2, or pipe. a_mode The access mode indicator. See the fopen function for a description. Note that the access mode specified must agree with the mode used to open the file originally. This includes binary/text access mode ("b" mode on fdopen and the "ctx=bin" option on creat or open). 3 Description This function allows you to access a file, originally opened by one of the UNIX I/O functions, with Standard I/O functions. Ordinarily, a file can be accessed by either a file descriptor or by a file pointer, but not both, depending on the way you open it. 3 Return_Values pointer Indicates that the operation has succeeded. NULL Indicates that an error has occurred. 2 feof Tests a file to see if the end-of-file has been reached. Format #include int feof (FILE *file_ptr); 3 Argument file_ptr A file pointer. 3 Return_Values nonzero integer Indicates that the end-of-file has been reached. 0 Indicates that the end-of-file has not been reached. 2 ferror Returns a nonzero integer if an error occurred while reading or writing a file. Format #include int ferror (FILE *file_ptr); 3 Argument file_ptr A file pointer. 3 Description A call to ferror continues to return a nonzero integer until the file is closed or until clearerr is called. 3 Return_Values 0 Indicates success. nonzero integer Indicates that an error has occurred. 2 fflush Writes out any buffered information for the specified file. Format #include int fflush (FILE *file_ptr); 3 Argument file_ptr A file pointer. If this argument is a NULL pointer, all buffers associated with all currently open files are flushed. 3 Description The output files are normally buffered only if they are not directed to a terminal, except for stderr, which is not buffered by default. The fflush function flushes the Compaq C RTL buffers. However, RMS has its own buffers. The fflush function does not guarantee that the file will be written to disk. (See the description of fsync for a way to flush buffers to disk.) If the file pointed to by file_ptr was opened in record mode and if there is unwritten data in the buffer, then fflush always generates a record. 3 Return_Values 0 Indicates that the operation is successful. EOF Indicates that the buffered data cannot be written to the file, or that the file control block is not associated with an output file. 2 ffs Finds the index of the first bit set in a string. Format #include int ffs (int iteger); 3 Arguments integer The integer to be examined for the first bit set. 3 Description This function finds the first bit set (beginning with the least significant bit) and returns the index of that bit. Bits are numbered starting at 1 (the least significant bit). 3 Return_Values x The index of the first bit set. 0 If index is 0. 2 fgetc Returns the next character from a specified file. Format #include int fgetc (FILE *file_ptr); 3 Argument file_ptr A pointer to the file to be accessed. 3 Description See the getc macro. 3 Return_Values x The returned character. EOF Indicates the end-of-file or an error. 2 fgetname Returns the file specification associated with a file pointer. Format #include char *fgetname (FILE *file_ptr, char *buffer, . . . ); 3 Function_Variants This function also has variants named _fgetname32 and _fgetname64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments file_ptr A file pointer. buffer A pointer to a character string that is large enough to hold the file specification. . . . An optional additional argument that can be either 1 or 0. If you specify 1, the fgetname function returns the file specification in OpenVMS format. If you specify 0, fgetname returns the file specification in UNIX style format. If you do not specify this argument, fgetname returns the file name according to your current command language interpreter. 3 Description This function places the file specification at the address given in the buffer. The buffer should be an array large enough to contain a fully qualified file specification (the maximum length is 256 characters). 3 Return_Values n The address of the buffer. 0 Indicates an error. 3 Restriction This function is specific to the Compaq C RTL and is not portable. 2 fgetpos Stores the current file position for a given file. Format #include int fgetpos (FILE *stream, fpos_t *pos); 3 Arguments stream A file pointer. pos A pointer to an implementation-defined structure. The fgetpos function fills this structure with information that can be used on subsequent calls to fsetpos. 3 Description This function stores the current value of the file position indicator for the stream pointed to by stream into the object pointed to by pos. 3 Return_Values 0 Indicates successful completion. -1 Indicates that there are errors. 3 Example #include #include main() { FILE *fp; int stat, i; int character; char ch, c_ptr[130], d_ptr[130]; fpos_t posit; /* Open a file for writing. */ if ((fp = fopen("file.dat", "w+")) == NULL) { perror("open"); exit(1); } /* Get the beginning position in the file. */ if (fgetpos(fp, &posit) != 0) perror("fgetpos"); /* Write some data to the file. */ if (fprintf(fp, "this is a test\n") == 0) { perror("fprintf"); exit(1); } /* Set the file position back to the beginning. */ if (fsetpos(fp, &posit) != 0) perror("fsetpos"); fgets(c_ptr, 130, fp); puts(c_ptr); /* Should be "this is a test." */ /* Close the file. */ if (fclose(fp) != 0) { perror("close"); exit(1); } } 2 fgets Reads a line from the specified file, up to one less than the specified maximum number of characters or up to and including the new-line character, whichever comes first. The function stores the string in str. Format #include char *fgets (char *str, int maxchar, FILE *file_ptr); 3 Function_Variants This function also has variants named _fgets32 and _fgets64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str A pointer to a character string that is large enough to hold the information fetched from the file. maxchar The maximum number of characters to fetch. file_ptr A file pointer. 3 Description This function terminates the line with a null character (\0). Unlike gets, fgets places the new-line character that terminates the input line into the user buffer if more than maxchar characters have not already been fetched. When the file pointed to by file_ptr is opened in record mode, fgets treats the end of a record the same as a new-line character, so it reads up to and including a new-line character or to the end of the record. 3 Return_Values x Pointer to str. NULL Indicates the end-of-file or an error. The contents of str are undefined if a read error occurs. 3 Example #include #include #include main() { FILE *fp; char c_ptr[130]; /* Create a dummy data file */ if ((fp = fopen("file.dat", "w+")) == NULL) { perror("open"); exit(1); } fprintf(fp, "this is a test\n") ; fclose(fp) ; /* Open a file with some data -"this is a test" */ if ((fp = fopen("file.dat", "r+")) == NULL) { perror("open error") ; exit(1); } fgets(c_ptr, 130, fp); puts(c_ptr); /* Display what fgets got. */ fclose(fp); delete("file.dat") ; } 2 fgetwc Reads the next character from a specified file, and converts it to a wide-character code. Format #include wint_t fgetwc (FILE *file_ptr); 3 Arguments file_ptr A pointer to the file to be accessed. 3 Description Upon successful completion, the fgetwc function returns the wide- character code read from the file pointed to by file_ptr and converted to type wint_t. If the file is at end-of-file, the end-of-file indicator is set, and WEOF is returned. If an I/O read error occurred, then the error indicator is set, and WEOF is returned. Applications can use ferror or feof to distinguish between an error condition and an end-of-file condition. 3 Return_Values x The wide-character code of the character read. WEOF Indicates the end-of-file or an error. If a read error occurs, the function sets errno to one of the following: o EALREADY - An operation is already in progress on the same file. o EBADF - The file descriptor is not valid. o EILSEQ - Invalid character detected. 2 fgetws Reads a line of wide characters from a specified file. Format #include wchar_t *fgetws (wchar_t *wstr, int maxchar, FILE *file_ptr); 3 Function_Variants This function also has variants named _fgetws32 and _fgetws64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr A pointer to a wide-character string large enough to hold the information fetched from the file. maxchar The maximum number of wide characters to fetch. file_ptr A file pointer. 3 Description This function reads wide characters from the specified file and stores them in the array pointed to by wstr. The function reads up to maxchar-1 characters or until the newline character is read, converted, and transferred to wstr, or until an end-of-file condition is encountered. The function terminates the line with a null wide character. fgetws places the newline that terminates the input line into the user buffer, unless maxchar characters have already been fetched. 3 Return_Values x Pointer to wstr. NULL Indicates the end-of-file or an error occurred. The contents of wstr are undefined if a read error occurs. If a read error occurs, the function sets errno. For a list of possible errno values, see fgetwc. 3 Example #include #include #include #include main() { wchar_t wstr[80], *ret; FILE *fp; /* Create a dummy data file */ if ((fp = fopen("file.dat", "w+")) == NULL) { perror("open"); exit(1); } fprintf(fp, "this is a test\n") ; fclose(fp) ; /* Open a test file containing : "this is a test" */ if ((fp = fopen("file.dat", "r")) == (FILE *) NULL) { perror("File open error"); exit(EXIT_FAILURE); } ret = fgetws(wstr, 80, fp); if (ret == (wchar_t *) NULL) { perror("fgetws failure"); exit(EXIT_FAILURE); } fputws(wstr, stdout); fclose(fp); delete("file.dat"); } 2 fileno Returns the file descriptor associated with the specified file pointer. Format #include int fileno (FILE *file_ptr); 3 Argument file_ptr A file pointer. 3 Description If you are using DEC C Version 5.2 or lower, undefine the fileno macro: #if defined(fileno) #undef fileno #endif 3 Return_Value x Integer file descriptor. -1 Indicates an error. 2 finite Returns the integer value 1 (True) when its argument is a finite number, or 0 (False) if not. This function is OpenVMS Alpha only. Format #include int finite (double x); int finitef (float x); int double finitel (long double x); 3 Argument x A real value. 3 Description The finite functions return 1 when -Infinity < x < +Infinity. They return 0 when |x| = Infinity, or x is a NaN. 2 floor Returns the largest integer less than or equal to the argument. Format #include double floor (double x); float floorf (float x); (Alpha only) long double floorl (long double x); (Alpha only) 3 Argument x A real value. 3 Return_Values n The largest integer less than or equal to the argument. 2 fmod Computes the floating-point remainder. Format #include double fmod (double x, double y); float fmodf (float x, float y); (Alpha only) long double fmodl (long double x, long double y); (Alpha only) 3 Arguments x A real value. y A real value. 3 Description The fmod functions return the floating-point remainder of the first argument divided by the second. If the second argument is 0, the function returns 0. 3 Return_Values x The value f, which has the same sign as the argument x, such that x == i * y + f for some integer i, where the magnitude of f is less than the magnitude of y. 0 Indicates that y is 0. 2 fopen Opens a file by returning the address of a FILE structure. Format #include FILE *fopen (const char *file_spec, const char *a_mode); (ANSI C) FILE *fopen (const char *file_spec, const char *a_mode, . . . ); (DEC C Extension) 3 Arguments file_spec A character string containing a valid file specification. a_mode The access mode indicator. Use one of the following character strings: "r", "w", "a", "r+", "w+", "rb", "r+b", "rb+", "wb", "w+b", "wb+", "ab", "a+b", "ab+", or "a+". These access modes have the following effects: o "r" opens an existing file for reading. o "w" creates a new file, if necessary, and opens the file for writing. If the file exists, it creates a new file with the same name and a higher version number. o "a" opens the file for append access. An existing file is positioned at the end-of-file, and data is written there. If the file does not exist, the Compaq C RTL creates it. The update access modes allow a file to be opened for both reading and writing. When used with existing files, "r+" and "a+" differ only in the initial positioning within the file. The modes are as follows: o "r+" opens an existing file for read update access. It is opened for reading, positioned first at the beginning-of-file, but writing is also allowed. o "w+" opens a new file for write update access. o "a+" opens a file for append update access. The file is first positioned at the end-of-file (writing). If the file does not exist, the Compaq C RTL creates it. o "b" means binary access mode. In this case, no conversion of carriage-control information is attempted. . . . Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function. For more information, see the creat function. 3 Description If a version of the file exists, a new file created with fopen inherits certain attributes from the existing file unless those attributes are specified in the fopen call. The following attributes are inherited: Record format Maximum record size Carriage control File protection. If you specify a directory in the file name and it is a search list that contains an error, Compaq C for OpenVMS Systems interprets it as a file open error. The file control block can be freed with the fclose function, or by default on normal program termination. 3 Return_Values x File pointer. NULL Indicates an error. The constant NULL is defined in the header file to be the NULL pointer value. The function returns NULL to signal the following errors: o File protection violations o Attempts to open a nonexistent file for read access o Failure to open the specified file 2 fp_class Determine the class of IEEE floating-point values. This function is OpenVMS Alpha only. Format #include int fp_class (double x); int fp_classf (float x); int fp_classl (long double x); 3 Arguments x An IEEE floating-point number. 3 Description These functions determine the class of the specified IEEE floating-point number, returning a constant from the header file. They never cause an exception, even for signaling NaNs (Not-a-Number). These functions implement the recommended class(x) function in the appendix of the IEEE 754-1985 standard for binary floating-point arithmetic. The constants in refer to the following classes of values: FP_SNAN Signaling NaN (Not-a-Number) FP_QNAN Quiet NaN FP_POS_INF +Infinity FP_NEG_INF -Infinity FP_POS_NORM positive normalized FP_NEG_NORM negative normalized FP_POS_ positive denormalized DENORM FP_NEG_ negative denormalized DENORM FP_POS_ZERO +0.0 (positive zero) FP_NEG_ZERO -0.0 (negative zero) 3 Return_Values x A constant from the header file. 2 fpathconf Retrieves file implementation characteristics. Format #include long int fpathconf (int filedes, int name); 3 Arguments filedes An open file descriptor. name The configuration attribute to query. If this attribute is not applicable to the file specified by the filesdes argument, fpathconf returns an error. 3 Description This function allows an application to retrieve the characteristics of operations supported by the file system underlying the file named by the filesdes argument. Read, write, or execute permission of the named file is not required, but you must be able to search all directories in the path leading to the file. Symbolic values for the name argument are defined in the header file as follows: _PC_LINK_MAX The maximum number of links to the file. If the filedes argument refers to a directory, the value returned applies to the directory itself. _PC_MAX_ The maximum number of bytes in a canonical input CANON line. This is applicable only to terminal devices. _PC_MAX_ The number of types allowed in an input queue. INPUT This is applicable only to terminal devices. _PC_NAME_MAX Maximum number of bytes in a filename (not including a terminating null). The byte range value is between 13 and 255. This is applicable only to a directory file. The value returned applies to filenames within the directory. _PC_PATH_MAX Maximum number of bytes in a pathname (not including a terminating null). The value is never larger than 65,535. This is applicable only to a directory file. The value returned is the maximum length of a relative pathname when the specified directory is the working directory. _PC_PIPE_BUF Maximum number of bytes guaranteed to be written atomically. This is applicable only to a FIFO. The value returned applies to the referenced object. If the path argument refers to a directory, the value returned applies to any FIFO that exists or can be created within the directory. _PC_CHOWN_ The value returned applies to any files (other RESTRICTED than directories) that exist or can be created within the directory. This is applicable only to a directory file. _PC_NO_TRUNC Returns 1 if supplying a component name longer than allowed by NAME_MAX causes an error. Returns 0 (zero) if long component names are truncated. This is applicable only to a directory file. _PC_VDISABLE This is always 0 (zero); no disabling character is defined. This is applicable only to a terminal device. 3 Return_Values x The resultant value for the configuration attribute specified in the name argument. -1 Indicates an error; errno is set to one of the following values: o EINVAL - The name argument specifies an unknown or inapplicable characteristic. o EBADF - the filedes argument is not a valid file descriptor. 2 fprintf Performs formatted output to a specified file. Format #include int fprintf (FILE *file_ptr, const char *format_spec, . . . ); 3 Arguments file_ptr A pointer to the file to which the output is directed. format_spec A pointer to a character string that contains the format specification. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, the output sources can be omitted. Otherwise, the function calls must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Any excess output sources are ignored. 3 Description An example of a conversion specification follows: #include main() { int temp = 4, temp2 = 17; fprintf(stdout, "The answers are %d, and %d.", temp, temp2); } Sample output (to the stdout file) from the previous example is as follows: The answers are 4, and 17. 3 Return_Values x The number of bytes written, excluding the null terminator. Negative value Indicates an error. The function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This might indicate that conversion to a numeric value failed because of overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 fputc Writes a character to a specified file. Format #include int fputc (int character, FILE *file_ptr); 3 Arguments character An object of type int. file_ptr A file pointer. 3 Description This function writes a single character to a file and returns the character. See also putc. 3 Return_Values x The character written to the file. Indicates success. EOF Indicates an output error. 2 fputs Writes a character string to a file without copying the string's null terminator (\0). Format #include int fputs (const char *str, FILE *file_ptr); 3 Arguments str A pointer to a character string. file_ptr A file pointer. 3 Description See also puts. Unlike puts, the fputs function does not append a new-line character to the output string. 3 Return_Values Nonnegative value Indicates success. EOF Indicates an error. 2 fputwc Converts a wide character to its corresponding multibyte value, and writes the result to a specified file. Format #include wint_t fputwc (wint_t wc, FILE *file_ptr); 3 Arguments wc An object of type wint_t. file_ptr A file pointer. 3 Description This function writes a wide character to a file and returns the character. See also putwc. 3 Return_Values x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno to the following: o EILSEQ - Invalid wide-character code detected. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 fputws Writes a wide-character string to a file without copying the null terminating character. Format #include int fputws (const wchar_t *wstr, FILE *file_ptr); 3 Arguments wstr A pointer to a wide-character string. file_ptr A file pointer. 3 Description The function converts the specified wide-character string to a multibyte character string and writes it to the specified file. The function does not append a terminating null byte corresponding to the null wide-character to the output string. 3 Return_Values Nonnegative value Indicates success. -1 Indicates an error. The function sets errno. For a list of the values see fputwc. 2 fread Reads a specified number of items from the file. Format #include size_t fread (void *ptr, size_t size_of_item, size_t number_items, FILE *file_ptr); 3 Arguments ptr A pointer to the location, within memory, where you place the information being read. The type of the object pointed to is determined by the type of the item being read. size_of_item The size of the items being read, in bytes. number_items The number of items to be read. file_ptr A pointer that indicates the file from which the items are to be read. 3 Description The type size_t is defined in the header file as follows: typedef unsigned int size_t The reading begins at the current location in the file. The items read are placed in storage beginning at the location given by the first argument. You must also specify the size of an item, in bytes. If the file pointed to by file_ptr was opened in record mode, fread will read size_of_item multiplied by number_items bytes from the file. That is, it does not necessarily read number_items records. 3 Return_Values n The number of bytes read divided by size_of_ item. 0 Indicates the end-of-file or an error. 2 free Makes available for reallocation the area allocated by a previous calloc, malloc, or realloc call. Format #include void free (void *ptr); 3 Argument ptr The address returned by a previous call to malloc, calloc, or realloc. If ptr is a NULL pointer, no action occurs. 3 Description The ANSI C standard defines free as not returning a value; therefore, the function prototype for free is declared with a return type of void. However, since a free can fail, and since previous versions of the Compaq C RTL have declared free to return an int, the implementation of free does return 0 on success and -1 on failure. 2 freopen Substitutes the file named by a file specification for the open file addressed by a file pointer. The latter file is closed. Format #include FILE *freopen (const char *file_spec, const char *a_mode, FILE *file_ptr, . . . ); 3 Arguments file_spec A pointer to a string that contains a valid OpenVMS or UNIX style file specification. After the function call, the given file pointer is associated with this file. a_mode The access mode indicator. See the fopen function for a description. file_ptr A file pointer. . . . Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function. 3 Description This function is typically used to associate one of the predefined names stdin, stdout, or stderr with a file. 3 Return_Values file_ptr The file pointer, if freopen is successful. NULL Indicates an error. 2 frexp Calculates the fractional and exponent parts of a floating-point value. Format #include double frexp (double value, int *eptr); float frexp (float value, int *eptr); (Alpha only) long double frexp (long double value, int *eptr); (Alpha only) 3 Arguments value A floating-point number of type double, float, or long double. eptr A pointer to an int where frexp places the exponent. 3 Description The frexp functions break the floating-point number (value) into a normalized fraction and an integral power of 2, as follows: value = fraction * (2exp) The fractional part is returned as the return value. The exponent is placed in the integer variable pointed to by eptr. 3 Example #include main () { double val = 16.0, fraction; int exp; fraction = frexp(val, &exp); printf("fraction = %f\n",fraction); printf("exp = %d\n",exp); } In this example, frexp converts the value 16 to .5 * 2 . The example produces the following output: fraction = 0.500000 exp = 5 |value| = Infinity or NaN is an invalid argument. 3 Return_Value x The fractional part of value. 0 Both parts of the result are 0. NaN If value is NaN, NaN is returned, errno is set to EDOM, and the value of *eptr is unspecified. value If |value| = Infinity, value is returned, errno is set to EDOM, and the value of *eptr is unspecified. 2 fscanf Performs formatted input from a specified file, interpreting it according to the format specification. Format #include int fscanf (FILE *file_ptr, const char *format_spec, . . . ); 3 Arguments file_ptr A pointer to the file that provides input text. format_spec A pointer to a character string that contains the format specification. . . . Optional expressions whose results correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description An example of a conversion specification follows: #include main () { int temp, temp2; fscanf(stdin, "%d %d", &temp, &temp2); printf("The answers are %d, and %d.", temp, temp2); } Consider a file, designated by stdin, with the following contents: 4 17 The example conversion specification produces the following result: The answers are 4, and 17. 3 Return_Values x The number of successfully matched and assigned input items. EOF Indicates that the end-of-file was encountered or a read error occurred. If a read error occurs, the function sets errno to one of the following: o EILSEQ - Invalid character detected. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This can indicate that conversion to a numeric value failed due to overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 fseek Positions the file to the specified byte offset in the file. Format #include int fseek (FILE *file_ptr, long int offset, int direction); 3 Arguments file_ptr A file pointer. offset The offset, specified in bytes. direction An integer indicating the position to which the offset is added to calculate the new position. The new position is the beginning of the file if direction is SEEK_SET, the current value of the file position indicator if direction is SEEK_CUR, or end-of-file if direction is SEEK_END. 3 Description This function can position fixed-length record-access file with no carriage control or a stream-access file on any byte offset, but can position all other files only on record boundaries. The available Standard I/O functions position a variable-length or VFC record file at its first byte, at the end-of-file, or on a record boundary. Therefore, the arguments given to fseek must specify any of the following: o The beginning or end of the file o A 0 offset from the current position (an arbitrary record boundary) o The position returned by a previous, valid ftell call See the fgetpos and fsetpos functions for a portable way to seek to arbitrary locations with these types of record files. CAUTION If, while accessing a stream file, you seek beyond the end-of-file and then write to the file, the fseek function creates a hole by filling the skipped bytes with zeros. In general, for record files, fseek should only be directed to an absolute position that was returned by a previous valid call to ftell, or to the beginning or end of a file. If a call to fseek does not satisfy these conditions, the results are unpredictable. See also open, creat, dup, dup2, and lseek. 3 Return_Values 0 Indicates successful seeks. -1 Indicates improper seeks. 2 fseeko Positions the file to the specified byte offset in the file. Equivalent to fseek. Format #include int fseeko (FILE *file_ptr, off_t offset, int direction); 3 Arguments file_ptr A file pointer. offset The offset, specified in bytes. The off_t data type is either a 32-bit integer or 64-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE direction An integer indicating the position to which the offset is added to calculate the new position. The new position is the beginning of the file if direction is SEEK_SET, the current value of the file position indicator if direction is SEEK_CUR, or end-of-file if direction is SEEK_END. 3 Description The fseeko function is identical to the fseek function, except that the offset argument is of type off_t instead of long int. 2 fsetpos Sets the file position indicator for a given file. Format #include int fsetpos (FILE *stream, const fpos_t *pos); 3 Arguments stream A file pointer. pos A pointer to an implementation-defined structure. The fgetpos function fills this structure with information that can be used on subsequent calls to fsetpos. 3 Description Call the fgetpos function before using the fsetpos function. 3 Return_Values 0 Indicates success. -1 Indicates an error. 2 fstat Accesses information about the file specified by the file descriptor. Format #include int fstat (int file_desc, struct stat *buffer); 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Arguments file_desc A file descriptor. buffer A pointer to a structure of type stat_t, which is defined in the header file. The argument receives information about that particular file. The members of the structure pointed to by buffer are as follows: Member Type Definition st_dev dev_t Pointer to a physical device name st_ ino_t Three words to receive the file ID ino[3] st_mode mode_t File "mode" (prot, dir, . . . ) st_nlink nlink_t For UNIX system compatibility only st_uid uid_t Owner user ID st_gid gid_t Group member: from st_uid st_rdev dev_t UNIX system compatibility - always 0 st_size off_t File size, in bytes st_atime time_t File access time; always the same as st_ mtime st_mtime time_t Last modification time st_ctime time_t File creation time st_fab_ char Record format rfm st_fab_ char Record attributes rat st_fab_ char Fixed header size fsz st_fab_ unsigned Record size mrs The types dev_t, ino_t, off_t, mode_t, nlink_t, uid_t, gid_t, and time_t, are defined in the header file. However, when compiling for compatibility (/DEFINE=_DECC_V4_SOURCE), only dev_ t, ino_t, and off_t are defined. The off_t data type is either a 32-bit integer or 64-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE As of OpenVMS Version 7.0, times are given in seconds since the Epoch (00:00:00 GMT, January 1, 1970). The st_mode structure member is the status information mode and is defined in the header file. The st_mode bits follow: Bits Constant Definition 0170000 S_IFMT Type of file 0040000 S_ Directory IFDIR 0020000 S_ Character special IFCHR 0060000 S_ Block special IFBLK 0100000 S_ Regular IFREG 0030000 S_ Multiplexed char special IFMPC 0070000 S_ Multiplexed block special IFMPB 0004000 S_ Set user ID on execution ISUID 0002000 S_ Set group ID on execution ISGID 0001000 S_ Save swapped text even after use ISVTX 0000400 S_ Read permission, owner IREAD 0000200 S_ Write permission, owner IWRITE 0000100 S_ Execute/search permission, owner IEXEC 3 Description This function does not work on remote network files. NOTE (Alpha only) On OpenVMS Alpha systems, the stat, fstat, utime, and utimes functions have been enhanced to take advantage of the new file-system support for POSIX-compliant file timestamps. This support is available only on ODS-5 devices on OpenVMS Alpha systems beginning with a version of OpenVMS Alpha after Version 7.3. Before this change, the stat and fstat functions were setting the values of the st_ctime, st_mtime, and st_atime fields based on the following file attributes: st_ctime - ATR$C_CREDATE (file creation time) st_mtime - ATR$C_REVDATE (file revision time) st_atime - was always set to st_mtime because no support for file access time was available Also, for the file-modification time, utime and utimes were modifying the ATR$C_REVDATE file attribute, and ignoring the file-access-time argument. After the change, for a file on an ODS-5 device, the stat and fstat functions set the values of the st_ctime, st_ mtime, and st_atime fields based on the following new file attributes: st_ctime - ATR$C_ATTDATE (last attribute modification time) st_mtime - ATR$C_MODDATE (last data modification time) st_atime - ATR$C_ACCDATE (last access time) If ATR$C_ACCDATE is zero, as on an ODS-2 device, the stat and fstat functions set st_atime to st_mtime. For the file-modification time, the utime and utimes functions modify both the ATR$C_REVDATE and ATR$C_MODDATE file attributes. For the file-access time, these functions modify the ATR$C_ACCDATE file attribute. Setting the ATR$C_ MODDATE and ATR$C_ACCDATE file attributes on an ODS-2 device has no effect. For compatibility, the old behavior of stat, fstat, utime and utimes remains the default, regardless of the kind of device. The new behavior must be explicitly enabled at runtime by defining the DECC$EFS_FILE_TIMESTAMPS logical name to "ENABLE" before invoking the application. Setting this logical does not affect the behavior of stat, fstat, utime and utimes for files on an ODS-2 device. 3 Return_Values 0 Indicates successful completion. -1 Indicates an error other than a protection violation. -2 Indicates a protection violation. 2 fsync Flushes data all the way to the disk. Format #include int fsync (int fd); 3 Argument fd A file descriptor corresponding to an open file. 3 Description This function behaves much like the fflush function. The primary difference between the two is that fsync flushes data all the way to the disk while fflush flushes data only as far as the underlying RMS buffers. Also, with fflush, you can flush all buffers at once; with fsync you cannot. 3 Return_Values 0 Indicates successful completion. -1 Indicates an error. 2 ftell Returns the current byte offset to the specified stream file. Format #include long int ftell (FILE *file_ptr); 3 Argument file_ptr A file pointer. 3 Description This function measures the byte offset from the beginning of the file. For variable-length files, VFC files, or any file with carriage- control attributes, it the file is opened in record mode, then ftell returns the starting position of the current record, not the current byte offset. When using record files, the ftell function ignores any characters that have been pushed back using either ungetc or ungetwc. This behavior does not occur if stream files are being used. For a portable way to measure the exact offset for any type of file, see the fgetpos function. 3 Return_Values n The current offset. EOF Indicates an error. 2 ftello Returns the current byte offset to the specified stream file. Equivalent to ftell. Format #include off_t ftello (FILE *file_ptr); 3 Argument file_ptr A file pointer. 3 Description The ftello function is identical to the ftell function, except that the return value is of type off_t instead of long int. The off_t data type is either a 64-bit integer or a 32-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE 2 ftime Returns the elapsed time since 00:00:00, January 1, 1970, in the structure pointed at by timeptr. Format #include int ftime (struct timeb *timeptr); 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Argument timeptr A pointer to the structure timeb_t. 3 Description The typedef timeb_t refers to the following structure defined in the header file: typedef struct timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; The member time gives the time in seconds. The member millitm gives the fractional time in milliseconds. After a call to ftime, the timezone and dstflag members of the timeb structure have the values of the global variables timezone and dstflag, respectively. See the description of the tzset function for timezone and dstflag global variables. 3 Return_Values 0 Successful execution. The timeb_t structure is filled in. -1 Indicates an error. Failure might indicate that the system's time-differential factor (that is, the difference between the system time and UTC time) is not set correctly. If the value of the SYS$TIMEZONE_DIFFERENTIAL logical is wrong, the function fails with errno set to EINVAL. 2 ftruncate Truncates a file to a specified length. Format #include int ftruncate (int filedes, off_t length); 3 Arguments filedes The descriptor of a file that must be open for writing. length The new length of the file in bytes. The off_t data type is either a 32-bit integer or 64-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE 3 Description This function truncates a file at the specified position. For record files, the position must be a record boundary. Also, the files must be local, regular files. If the file was previously larger than length, extra data is lost. If the file was previously shorter than length, bytes between the old and new lengths are read as zeros. 3 Return_Values 0 Indicates success. -1 An error occurred; errno is set to indicate the error. 2 ftw Walks a file tree. Format #include int ftw (const char *path, int(*function)(const char *, const struct stat *, int), int depth); 3 Arguments path The directory hierarchy to be searched. function The function to be invoked for each file in the directory hierarchy. depth The maximum number of directory streams or file descriptors, or both, available for use by ftw. This argument should be in the range of 1 to OPEN_MAX. 3 Description This function recursively searches the directory hierarchy that descends from the directory specified by the path argument. For each file in the hierarchy, ftw calls the function specified by the function argument, passes it a pointer to a null- terminated character string containing the name of the file, a pointer to a stat structure containing information about the file, and an integer. The integer identifies the file type. Possible values, defined in are: FTW_F Regular file. FTW_D Directory. FTW_DNR Directory that cannot be read. FTW_NS A file on which stat could not successfully be executed. If the integer is FTW_DNR, then the files and subdirectories contained in that directory are not processed. If the integer is FTW_NS, then the stat structure contents are meaningless. For example, a file in a directory for which you have read permission but not execute (search) permission can cause the function argument to pass FTW_NS. The ftw function finishes processing a directory before processing any of its files or subdirectories. The ftw function continues the search until: o The directory hierarchy specified by the path argument is completed. o An invocation of the function specified by the function argument returns a nonzero value. o An error (such as an I/O error) is detected within the ftw function. Because the ftw function is recursive, it is possible for it to terminate with a memory fault because of stack overflow when applied to very deep file structures. The ftw function uses the malloc function to allocate dynamic storage during its operation. If ftw is forcibly terminated, as with a call to longjmp from the function pointed to by the function argument, ftw has no chance to free that storage. It remains allocated. A safe way to handle interrupts is to store the fact that an interrupt has occurred, and arrange to have the function specified by the function argument return a nonzero value the next time it is called. NOTE The ftw function is reentrant; make sure that the function supplied as argument function is also reentrant. See malloc, longjump, lstat, and stat. 3 Return_Values 0 Indicates success. x Indicates that the function specified by the function argument stops its search, and returns the value that was returned by the function. -1 Indicates an error; errno is set to one of the following values: o EACCES - Search permission is denied for any component of the path argument or read permission is denied for the path argument. o ENAMETOOLONG - The length of the path string exceeds PATH_MAX, or a pathname component is longer than NAME_MAX while [_POSIX_NO_TRUNC] is in effect. o ENOENT - The path argument points to the name of a file that does not exist or points to an empty string. o ENOMEM - There is insufficient memory for this operation. Also, if the function pointed to by the function argument encounters an error, errno can be set accordingly. 2 fwait Waits for I/O on a specific file to complete. Format #include int fwait (FILE *fp); 3 Argument fp A file pointer corresponding to an open file. 3 Description This function is used primarily to wait for completion of pending asynchronous I/O. 3 Return_Values 0 Indicates successful completion. -1 Indicates an error. 2 fwide Determines and sets the orientation of a stream. Format #include int fwide (FILE *stream, int mode); 3 Arguments stream A file pointer. mode A value that specifies the desired orientation of the stream. 3 Description This function determines the orientation of the stream pointed to by stream and sets the orientation of a non-oriented stream according to the mode argument in the following way: If the mode argument is Then the fwide function greater than makes the stream wide-oriented. zero less than zero makes the stream byte-oriented. zero does not alter the orientation of the stream. If the orientation of the stream has already been set, fwide does not alter it. Because no error status is defined for fwide, the calling application should check errno if fwide returns a 0. 3 Return_Values > 0 After the call, the stream is wide-oriented. < 0 After the call, the stream is byte-oriented. 0 After the call, the stream has no orientation or a stream argument is invalid; the function sets errno. 2 fwprintf Writes output to the stream under control of the wide-character format string. Format #include int fwprintf (FILE *stream, const wchar_t *format, . . . ); 3 Arguments stream A file pointer. format A pointer to a wide-character string containing the format specifications. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, the output sources can be omitted. Otherwise, the function calls must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Any excess output sources are ignored. 3 Description This function writes output to the stream pointed to by stream under control of the wide-character string pointed to by format, which specifies how to convert subsequent arguments to output. If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated, but are otherwise ignored. The fwprintf function returns when it encounters the end of the format string. The format argument is composed of zero or more directives that include: o Ordinary wide characters (not the percent sign (%)) o Conversion specifications 3 Return_Values n The number of wide characters written. Negative value Indicates an error. The function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This might indicate that conversion to a numeric value failed because of overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 3 Example The following example shows how to print a date and time in the form "Sunday, July 3, 10:02", followed by to five decimal places: #include #include #include /* . . . */ wchar_t *weekday, *month; /* pointers to */ /* wide-character strings */ int day, hours, min; fwprintf(stdout, L"%ls, %ls %d, %.2d:%.2d\n", weekday, month, day, hour, min); fwprintf(stdout, L"pi = %.5f\n", 4 * atan(1.0)); 2 fwrite Writes a specified number of items to the file. Format #include size_t fwrite (const void *ptr, size_t size_of_item, size_t number_items, FILE *file_ptr); 3 Arguments ptr A pointer to the memory location from which information is being written. The type of the object pointed to is determined by the type of the item being written. size_of_item The size, in bytes, of the items being written. number_items The number of items to be written. file_ptr A file pointer that indicates the file to which the items are being written. 3 Description The type size_t is defined in the header file as follows: typedef unsigned int size_t The writing begins at the current location in the file. The items are written from storage beginning at the location given by the first argument. You must also specify the size of an item, in bytes. If the file pointed to by file_ptr is a record file, the fwrite function outputs at least number_items records, each of length size_of_item. 3 Return_Value x The number of items written. The number of records written depends upon the maximum record size of the file. 2 fwscanf Reads input from the stream under control of the wide-character format string. Format #include int fwscanf (FILE *stream, const wchar_t *format, . . . ); 3 Arguments stream A file pointer. format A pointer to a wide-character string containing the format specification. . . . Optional expressions whose results correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description This function reads input from the stream pointed to by stream under the control of the wide-character string pointed to by format. If there are insufficient arguments for the format, the behavior is undefined. If the format is exhausted while arguments remain, the excess arguments are evaluated, but otherwise ignored. The format is composed of zero or more directives that include: o One or more white-space wide characters. o An ordinary wide character (neither a percent (%)) nor a white-space wide character). o Conversion specifications. Each conversion specification is introduced by the wide character %. If the stream pointed to by the stream argument has no orientation, fwscanf makes the stream wide-oriented. 3 Return_Values n The number of input items assigned, sometimes fewer than provided for, or even zero, in the event of an early matching failure. EOF Indicates an error; input failure occurs before any conversion. 2 gcvt Converts its argument to a null-terminated string of ASCII digits and returns the address of the string. Format #include char *gcvt (double value, int ndigit, char *buffer); 3 Function_Variants This function also has variants named _gcvt32 and _gcvt64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments value An object of type double that is converted to a null-terminated string of ASCII digits. ndigit The number of ASCII digits to use in the converted string. If ndigit is less than 6, the value of 6 is used. buffer A storage location to hold the converted string. 3 Description This function places the converted string in a buffer and returns the address of the buffer. If possible, gcvt produces ndigit significant digits in F-format, or if not possible, in E-format. Trailing zeros are suppressed. The ecvt, fcvt, and gcvt functions represent the following special values specified in the IEEE Standard for floating-point arithmetic: Value Representation Quiet NaN NaNQ Signalling NaNS NaN +Infinity Infinity -Infinity -Infinity The sign associated with each of these values is stored into the sign argument. In IEEE floating-point representation, a value of 0 (zero) can be positive or negative, as set by the sign argument. See also fcvt and ecvt. 3 Return_Value x The address of the buffer. 2 getc The getc macro returns the next character from a specified file. Format #include int getc (FILE *file_ptr); 3 Argument file_ptr A pointer to the file to be accessed. 3 Description Since getc is a macro, a file pointer argument with side effects (for example, getc (*f++)) might be evaluated incorrectly. In such a case, use the fgetc function instead. See the fgetc function. 3 Return_Values n The returned character. EOF Indicates the end-of-file or an error. 2 [w]getch Get a character from the terminal screen and echo it on the specified window. The getch function echos the character on stdscr. Format #include char getch(); char wgetch (WINDOW *win); 3 Argument win A pointer to the window. 3 Description The getch and wgetch functions refresh the specified window before fetching a character. For more information, see the scrollok function. 3 Return_Values x The returned character. ERR Indicates that the function makes the screen scroll illegally. 2 getchar Reads a single character from the standard input (stdin). Format #include int getchar (void); 3 Description The getchar function is identical to fgetc(stdin). 3 Return_Values x The next character from stdin, converted to int. EOF Indicates the end-of-file or an error. 2 getclock Gets the current value of the system-wide clock. Format #include int getclock (int clktyp, struct timespec *tp); 3 Arguments clktyp The type of system-wide clock. tp Pointer to a timespec structure space where the current value of the system-wide clock is stored. 3 Description This function sets the current value of the clock specified by clktyp into the location pointed to by tp. The clktyp argument is given as a symbolic constant name, as defined in the header file. Only the TIMEOFDAY symbolic constant, which specifies the normal time-of-day clock to access for system-wide time, is supported. For the clock specified by TIMEOFDAY, the value returned by this function is the elapsed time since the Epoch. The Epoch is referenced to 00:00:00 UTC (Coordinated Universal Time) 1 Jan 1970. The getclock function returns a timespec structure, which is defined in the header file as follows: struct timespec { unsigned long tv_sec /* Elapsed time in seconds since the Epoch*/ long tv_nsec /* Elapsed time as a fraction of a second */ /* since the Epoch (in nanoseconds) */ }; 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EINVAL - The clktyp argument does not specify a known system-wide clock. Or, the value of SYS$TIMEZONE_DIFFERENTIAL logical is wrong. o EIO - An error occurred when the system- wide clock specified by the clktyp argument was accessed. 2 getcwd Returns a pointer to the file specification for the current working directory. Format #include char *getcwd (char *buffer, size_t size); (ISO POSIX-1) char *getcwd (char *buffer, unsigned int size, . . . ); (DEC C Extension) 3 Function_Variants This function also has variants named _getcwd32 and _getcwd64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments buffer Pointer to a character string large enough to hold the directory specification. If buffer is a NULL pointer, getcwd obtains size bytes of space using malloc. In this case, you can use the pointer returned by getcwd as the argument in a subsequent call to free. size The length of the directory specification to be returned. . . . An optional argument that can be either 1 or 0. If you specify 1, the getcwd function returns the directory specification in OpenVMS format. If you specify 0, getcwd returns the directory specification (path name) in UNIX style format. If you do not specify this argument, getcwd returns the file name according to your current command-language interpreter. 3 Return_Values x A pointer to the file specification. NULL Indicates an error. 2 getdtablesize Gets the total number of file descriptors that a process can have open simultaneously. Format #include int getdtablesize (void); 3 Description This function returns the total number of file descriptors that a process can have open simultaneously. Each process is limited to a fixed number of open file descriptors. The number of file descriptors that a process can have open is the minumum of the following: o Compaq C RTL open file limit-65535 on OpenVMS Alpha; 2048 on OpenVMS VAX. o SYSGEN CHANNELCNT parameter-permanent I/O channel count. o Process open file quota FILLM parameter-number of open files that can be opened by a process at one time. 3 Return_Values x The number of file descriptors that a process can have open simultaneously. -1 Indicates an error. 2 getegid With POSIX IDs disabled, equivalent to getgid and returns the group number from the user identification code (UIC). With POSIX IDs enabled, returns the effective group ID. Format #include gid_t getegid (void); 3 Description This function can be used with POSIX-style identifiers or with UIC-based identifiers. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX-style IDs disabled (the default), the getegid and getgid functions are equivalent and return the group number from the current UIC. For example, if the UIC is [313,031], 313 is the group number. With POSIX-style IDs enabled, getegid returns the effective group ID of the calling process, and getgid returns the real group ID of the calling process. The real group ID is specified at login time. The effective group ID is more transient, and determines additional access permission during execution of a set-group-ID process. It is for such processes that the getgid function is most useful. See also geteuid and getuid. 3 Return_Value x The effective group ID (POSIX IDs enabled), or the group number from the UIC (POSIX IDs disabled). 2 getenv Searches the environment array for the current process and returns the value associated with a specified environment name. Format #include char *getenv (const char *name); 3 Argument name One of the following values: o HOME-Your login directory o TERM-The type of terminal being used o PATH-The default device and directory o USER-The name of the user who initiated the process o Logical name or CLI symbolic name o An environment variable set with setenv or putenv. The case of the specified name is important. 3 Description In certain situations, this function attempts to perform a logical name translation on the user-specified argument: 1. If the argument to getenv does not match any of the environment strings present in your environment array, getenv attempts to translate your argument as a logical name by searching the logical name tables indicated by the LNM$FILE_ DEV logical, as is done for file processing. getenv first does a case-sensitive lookup. If that fails, it does a case-insensitive lookup. In most instances, logical names are defined in uppercase, but getenv can also find logical names that include lowercase letters. getenv does not perform iterative logical name translation. 2. If no logical name exists, getenv attempts to translate the argument string as a command-language interpreter (CLI) symbol. If it succeeds, it returns the translated symbol text. If it fails, the return value is NULL. getenv does not perform iterative CLI translation. If your CLI is the DEC/Shell, the function does not attempt a logical name translation since Shell environment symbols are implemented as DCL symbols. NOTE In OpenVMS Version 7.1, a cache of VMS environment variables (that is, logical names and DCL symbols) has been added to the getenv function to avoid the library making repeated calls to translate a logical name or to obtain the value of a DCL symbol. By default, the cache is disabled. If your application does not need to track changes in OpenVMS environment variables that can occur during its execution, the cache can be enabled by setting the DECC$ENABLE_ GETENV_CACHE logical before invoking the application (any equivalence string). 3 Return_Values x Pointer to an array containing the translated symbol. An equivalence name is returned at index zero. NULL Indicates that the translation failed. 2 geteuid With POSIX IDs disabled, equivalent to getuid and returns the member number (in OpenVMS terms) from the user identification code (UIC). With POSIX IDs enabled, returns the effective user ID. Format #include uid_t geteuid (void); 3 Description This function can be used with POSIX-style identifiers or with UIC-based identifiers. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX-style IDs disabled (the default), the geteuid and getuid functions are equivalent and return the member number from the current UIC as follows: o For programs compiled with the _VMS_V6_SOURCE feature- test macro or programs that do not include the header file, the getuid and geteuid functions return the member number of the OpenVMS UIC. For example, if the UIC is [313,31], then the member number, 31, is returned. o For programs compiled without the _VMS_V6_SOURCE feature-test macro that do include the header file, the full UIC is returned. For example, if the UIC is [313, 31] then 20512799 (31 + 313 * 65536) is returned. With POSIX-style IDs enabled, geteuid returns the effective user ID of the calling process, and getuid returns the real user ID of the calling process. See also getegid and getgid. 3 Return_Value x The effective user ID (POSIX IDs enabled), or the member number from the current UIC or the full UIC (POSIX IDs disabled). 2 getgid With POSIX IDs disabled, equivalent to getegid and returns the group number from the user identification code (UIC). With POSIX IDs enabled, returns the real group ID. Format #include gid_t getgid (void); 3 Description This function can be used with POSIX-style identifiers or with UIC-based identifiers. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX-style IDs disabled (the default), the getegid and getgid functions are equivalent and return the group number from the current UIC. For example, if the UIC is [313,031], 313 is the group number. With POSIX-style IDs enabled, getegid returns the effective group ID of the calling process, and getgid returns the real group ID of the calling process. The real group ID is specified at login time. The effective group ID is more transient, and determines additional access permission during execution of a set-group-ID process. It is for such processes that the getgid function is most useful. See also geteuid and getuid. 3 Return_Value x The real group ID (POSIX IDs enabled), or the group number from the current UIC (POSIX IDs disabled). 2 getitimer Returns the value of interval timers. Format #include int getitimer (int which, struct itimerval *value); 3 Arguments which The type of interval timer. The Compaq C RTL supports only ITIMER_REAL. value Pointer to an itimerval structure whose members specify a timer interval and the time left to the end of the interval. 3 Description This function returns the current value for the timer specified by the which argument in the structure pointed to by value. A timer value is defined by the itimerval structure: struct itimerval { struct timeval it_interval; struct timeval it_value; }; The following table lists the values for the itimerval structure members: itimerval Member Value Meaning it_interval = 0 Disables a timer after its next expiration Assumes it_value is nonzero. it_interval = Specifies a value used in reloading it_value nonzero when the timer expires. it_value = 0 Disables a timer. it_value = Indicates the time to the next timer nonzero expiration. Time values smaller than the resolution of the system clock are rounded up to this resolution. The Compaq C RTL provides each process with one interval timer, defined in the header file as ITIMER_REAL. This timer decrements in real time and delivers a SIGALRM signal when the timer expires. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to EINVAL (The value argument specified a time that was too large to handle.) 2 getlogin Gets the login name. Format #include char *getlogin (void); 3 Description The getlogin function returns the login name of the user associated with the current session. 3 Return_Values x A pointer to a null-terminated string in a static buffer. NULL Indicates an error. Login name is not set. 2 getname Returns the file specification associated with a file descriptor. Format #include char *getname (int file_desc, char *buffer, . . . ); 3 Function_Variants This function also has variants named _getname32 and _getname64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments file_desc A file descriptor. buffer A pointer to a character string that is large enough to hold the file specification. . . . An optional argument that can be either 1 or 0. If you specify 1, the getname function returns the file specification in OpenVMS format. If you specify 0, the getname function returns the file specification in UNIX style format. If you do not specify this argument, the getname function returns the file name according to your current command-language interpreter (CLI). 3 Description This function places the file specification into the area pointed to by buffer and returns that address. The area pointed to by buffer should be an array large enough to contain a fully qualified file specification (the maximum length is 256 characters). 3 Return_Values x The address passed in the buffer argument. 0 Indicates an error. 2 getopt A command-line parser that can be used by applications that follow Unix command-line conventions. Format #include (X/Open, POSIX-1) #include (X/Open, POSIX-2) int getopt (int argc, char * const argv[], const char *optstring); extern char *optarg; extern int optind, opterr, optopt; 3 Arguments argc The argument count as passed to main. argv The argument array as passed to main. optstring A string of recognized option characters. If a character is followed by a colon, the option takes an argument. 3 Description The variable optind is the index of the next element of the argv vector to be processed. It is initialized to 1 by the system, and it is updated by getopt when it finishes with each element of argv. When an element of argv contains multiple option characters, it is unspecified how getopt determines which options have already been processed. The getopt function returns the next option character (if one is found) from argv that matches a character in optstring, if there is one that matches. If the option takes an argument, getopt sets the variable optarg to point to the option-argument as follows: o If the option was the last character in the string pointed to by an element of argv, then optarg contains the next element of argv, and optind is incremented by 2. If the resulting value of optind is not less than argc, getopt returns an error, indicating a missing option-argument. o Otherwise, optarg points to the string following the option character in that element of argv, and optind is incremented by 1. If one of the following is true, getopt returns -1 without changing optind: argv[optind] is a NULL pointer *argv[optind] is not the character - argv[optind] points to the string "-" If argv[optind] points to the string "- -" getopt returns -1 after incrementing optind. If getopt encounters an option character not contained in optstring, the question-mark character (?) is returned. If getopt detects a missing argument, the colon character (:) is returned if the first character of optstring is a colon; otherwise a question-mark character is returned. In either of the previous two cases, getopt sets the variable optopt to the option character that caused the error. If the application has not set the variable opterr to 0 and the first character of optstring is not a colon, getopt also prints a diagnostic message to stderr. 3 Return_Values x The next option character specified on the command line. A colon is returned if getopt detects a missing argument and the first character of optstring is a colon. A question mark is returned if getopt encounters an option character not in optstring or detects a missing argument and the first character of optstring is not a colon. -1 When all command-line options are parsed. 3 Example The following example shows how you might process the arguments for a utility that can take the mutually exclusive options a and b and the options f and o, both of which require arguments: #include int main (int argc, char *argv[ ]) { int c; int bflg, aflg, errflg; char *ifile; char *ofile; extern char *optarg; extern int optind, optopt; . . . while ((c = getopt(argc, argv, ":abf:o:)) != -1) { switch (c) { case 'a': if (bflg) errflg++; else aflg++; break; case 'b': if (aflg) errflg++; else { bflg++; bproc(); } break; case 'f': ifile = optarg; break; case 'o': ofile = optarg; break; case ':': /* -f or -o without operand */ fprintf (stderr, "Option -%c requires an operand\n"' optopt); errflg++; break; case '?': fprintf (stderr, "Unrecognized option -%c\n"' optopt); errflg++; } } if (errflg) { fprintf (stderr, "usage: ..."); exit(2); } for ( ; optind < argc; optind++) { if (access(argv[optind], R_OK)) { . . . } This sample code accepts any of the following as equivalent: cmd -ao arg path path cmd -a -o arg path path cmd -o arg -a path path cmd -a -o arg -- path path cmd -a -oarg path path cmd -aoarg path path 2 getpagesize Gets the system page size. Format #include int getpagesize (void); 3 Description This function returns the number of bytes in a page. The system page size is useful for specifying arguments to memory management system calls. The page size is a system page size and is not necessarily the same as the underlying hardware page size. 3 Return_Values x Always indicates success. Returns the number of bytes in a page. 2 getpid Returns the process ID of the current process. Format #include pid_t getpid (void); 3 Return_Value x The process ID of the current process. 2 getppid Returns the parent process ID of the calling process. Format #include pid_t getppid (void); 3 Return_Values x The parent process ID. 0 Indicates that the calling process does not have a parent process. 2 getpwent Accesses user entry information in the user database. Format #include #include struct passwd *getpwent (void); 3 Arguments passwd The password structure where you write the user attributes. 3 Description This function accesses basic user attributes about a specified user. The function returns the next user entry in a sequential search. The passwd structure is defined in the header file as follows: pw_name The name of the user. pw_ The encrypted password of the user. passwd pw_uid The ID of the user. pw_gid The group ID of the principle group of the user. pw_pecos The personal information about the user. pw_dir The home directory of the user. pw_shell The initial program for the user. NOTE All information generated by the getpwent function is stored in a per-thread static area and is overwritten on subsequent calls to the function. Password file entries that are too long are ignored. 3 Return_Values x A pointer to a valid password structure. NULL Indicates an error. 2 getpwnam Accesses user-name information in the user database. Format #include struct passwd *getpwnam (const char name); 3 Arguments name The name of the user for which the attributes are to be read. 3 Description This function returns the first user entry in the database with the pw_name member of the passwd structure that matches the name argument. The passwd structure is defined in the header file as follows: pw_name The user's login name. pw_uid The numerical user ID. pw_gid The numerical group ID. pw_dir The home directory of the user. pw_shell The initial program for the user. NOTE All information generated by the getpwnam function is stored in a static area and is overwritten on subsequent calls to the function. 3 Return_Values x A pointer to a valid password structure. NULL An error occurred. errno is set to indicate the error. 2 getpwuid Accesses user-ID information in the rights database. Format #include struct passwd *getpwuid (uid_t uid); 3 Arguments uid The ID of the user for which the attributes are to be read. 3 Description This function accesses the identifier names of all identifiers in the rights database. It returns the first user entry in the rights database with a pw_uid member of the passwd structure that matches the uid argument. The passwd structure is defined in the header file as follows: pw_name The user's login name. pw_uid The numerical user ID. pw_gid The numerical group ID. pw_dir The home directory of the user. pw_shell The initial program for the user. To check for error situations, applications should set errno to zero before calling getpwuid. If errno is nonzero on return, then an error occurred. NOTE All information generated by the getpwuid function is stored in a per-thread static area and is overwritten on subsequent calls to the function. 3 Return_Values x A pointer to a valid password structure. NULL An error occurred. errno is set to indicate the error. 2 gets Reads a line from the standard input (stdin). Format #include char *gets (char *str); 3 Function_Variants This function also has variants named _gets32 and _gets64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument str A pointer to a character string that is large enough to hold the information fetched from stdin. 3 Description The new-line character (\n) that ends the line is replaced by the function with an ASCII null character (\0). When stdin is opened in record mode, gets treats the end of a record the same as a new-line character and, therefore, reads up to and including a new-line character or to the end of the record. 3 Return_Values x A pointer to the str argument. NULL Indicates that an error has occurred or that the end-of-file was encountered before a new- line character was encountered. The contents of str are undefined if a read error occurs. 2 [w]getstr Get a string from the terminal screen, store it in the variable str, and echo it on the specified window. The getstr function works on the stdscr window. Format #include int getstr (char *str); int wgetstr (WINDOW *win, char *str); 3 Arguments win A pointer to the window. str Must be large enough to hold the character string fetched from the window. 3 Description The getstr and wgetstr functions refresh the specified window before fetching a string. The new-line terminator is stripped from the fetched string. For more information, see the scrollok function. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. 2 gettimeofday Gets date and time. Format #include int gettimeofday (struct timeval *tp, void *tpz); 3 Arguments tp Pointer to a timeval structure, defined in the header file. tpz A NULL pointer. If this argument is not a NULL pointer, it is ignored. 3 Description This function gets the current time (expressed as seconds and microseconds) since 00::00 Coordinated Universal Time, January 1, 1970. The current time is stored in the timeval structure pointed to by the tp argument. The tzp argument is intended to hold time-zone information set by the kernel. However, because the OpenVMS kernel does not set time-zone information, the tzp argument should be NULL. If it is not NULL, it is ignored. This function is supported for compatibility with BSD programs. If the value of the SYS$TIMEZONE_DIFFERENTIAL logical is wrong, the function fails with errno set to EINVAL. 3 Return_Values 0 Indicates success. -1 An error occurred. errno is set to indicate the error. 2 getuid With POSIX IDs disabled, equivalent to geteuid and returns the member number (in OpenVMS terms) from the user identification code (UIC). With POSIX IDs enabled, returns the real user ID. Format #include uid_t getuid (void); 3 Description This function can be used with POSIX-style identifiers or with UIC-based identifiers. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX-style IDs disabled (the default), the geteuid and getuid functions are equivalent and return the member number from the current UIC as follows: o For programs compiled with the _VMS_V6_SOURCE feature- test macro or programs that do not include the header file, the getuid and geteuid functions return the member number of the OpenVMS UIC. For example, if the UIC is [313,31], then the member number, 31, is returned. o For programs compiled without the _VMS_V6_SOURCE feature-test macro that do include the header file, the full UIC is returned. For example, if the UIC is [313, 31] then 20512799 (31 + 313 * 65536) is returned. With POSIX-style IDs enabled, geteuid returns the effective user ID of the calling process, and getuid returns the real user ID of the calling process. See also getegid and getgid. 3 Return_Value x The real user ID (POSIX IDs enabled), or the member number from the current UIC or the full UIC (POSIX IDs disabled). 2 getw Returns characters from a specified file. Format #include int getw (FILE *file_ptr); 3 Argument file_ptr A pointer to the file to be accessed. 3 Description This function returns the next four characters from the specified input file as an int. 3 Return_Values x The next four characters, in an int. EOF Indicates that the end-of-file was encountered during the retrieval of any of the four characters and all four characters were lost. Since EOF is an acceptable integer, use feof and ferror to check the success of the function. 2 getwc Reads the next character from a specified file, and converts it to a wide-character code. Format #include wint_t getwc (FILE *file_ptr); 3 Arguments file_ptr A pointer to the file to be accessed. 3 Description Since getwc is implemented as a macro, a file pointer argument with side effects (for example getwc (*f++)) might be evaluated incorrectly. In such a case, use the fgetwc function instead. See the fgetwc function. 3 Return_Values n The returned character. WEOF Indicates the end-of-file or an error. If an error occurs, the function sets errno. For a list of the values set by this function, see fgetwc. 2 getwchar Reads a single wide character from the standard input (stdin). Format #include wint_t getwchar (void); 3 Description The getwchar function is identical to fgetwc(stdin). 3 Return_Values x The next character from stdin, converted to wint_t. WEOF Indicates the end-of-file or an error. If an error occurs, the function sets errno. For a list of the values set by this function, see fgetwc. 2 getyx Puts the (y,x) coordinates of the current cursor position on win in the variables y and x. Format #include getyx (WINDOW *win, int y, int x); 3 Arguments win Must be a pointer to the window. y Must be a valid lvalue. x Must be a valid lvalue. 2 gmtime,_gmtime_r Converts time units to the broken-down UTC time. Format #include struct tm *gmtime (const time_t *timer); struct tm *gmtime_r (const time_t *timer, struct tm *result); (ISO POSIX-1) 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Arguments timer Points to a variable that specifies a time value in seconds since the Epoch. result A pointer to a tm structure where the result is stored. The tm structure is defined in the header, and is also shown in tm Structure in the description of localtime. 3 Description The gmtime and gmtime_r functions convert the time (in seconds since the Epoch) pointed to by timer into a broken-down time, expressed as Coordinated Universal Time (UTC), and store it in a tm structure. The difference between the gmtime_r and gmtime functions is that the former puts the result into a user-specified tm structure where the result is stored. The latter puts the result into thread-specific static memory allocated by the Compaq C RTL, and which is overwritten by subsequent calls to gmtime; you must make a copy if you want to save it. On success, gmtime returns a pointer to the tm structure; gmtime_ r returns its second argument. On failure, these functions return the NULL pointer. NOTE Generally speaking, UTC-based time functions can affect in- memory time-zone information, which is process-wide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_ r, ctime_r, gmtime_r and localtime_r, is both thread-safe and AST-reentrant. If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant. 3 Return_Values x Pointer to a tm structure. NULL Indicates an error; errno is set to one of the following values: o EINVAL - The timer argument is NULL. 2 gsignal Generates a specified software signal, which invokes the action routine established by a signal, ssignal, or sigvec function. Format #include int gsignal (int sig [, int sigcode]); 3 Arguments sig The signal to be generated. sigcode An optional signal code. For example, signal SIGFPE-the arithmetic trap signal-has 10 different codes, each representing a different type of arithmetic trap. The signal codes can be represented by mnemonics or numbers. The arithmetic trap codes are represented by the numbers 1 to 10, but the SIGILL codes are represented by the numbers 0 to 2. The code values are defined in the header file. 3 Description Calling this function has one of the following results: o If gsignal specifies a sig argument that is outside the range defined in the header file, then gsignal returns 0 and sets errno to EINVAL. o If signal, ssignal, or sigvec establishes SIG_DFL (default action) for the signal, then gsignal does not return. The image is exited with the OpenVMS error code corresponding to the signal. o If signal, ssignal, or sigvec establishes SIG_IGN (ignore signal) as the action for the signal, then gsignal returns its argument, sig. o signal, ssignal, or sigvec must be used to establish an action routine for the signal. That function is called and its return value is returned by gsignal. See also raise, signal, ssignal, and sigvec. 3 Return_Values 0 Indicates a sig argument that is outside the range defined in the header file; errno is set to EINVAL. sig Indicates that SIG_IGN (ignore signal) has been established as the action for the signal. x Indicates that signal, ssignal, or sigvec has established an action function for the signal. That function is called, and its return value is returned by gsignal. 2 hypot Returns the length of the hypotenuse of a right triangle. Format #include double hypot (double x, double y); float hypotf (float x, float y); (Alpha only) long double hypotl (long double x, long double y); (Alpha only) 3 Arguments x A real value. y A real value. 3 Description The hypot functions return the length of the hypotenuse of a right triangle, where x and y represent the perpendicular sides of the triangle. The length is calculated as: sqrt(x2 + y2) On overflow, the return value is undefined, and errno is set to ERANGE. 3 Return_Values x The length of the hypotenuse. HUGE_VAL Overflow occurred; errno is set to ERANGE. 0 Underflow occurred; errno is set to ERANGE. NaN x or y is NaN; errno is set to EDOM. 2 iconv Converts characters coded in one codeset to characters coded in another codeset. Format #include size_t iconv (iconv_t cd, char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft); 3 Arguments cd A conversion descriptor. This is returned by a successful call to iconv_open. inbuf A pointer to a variable that points to the first character in the input buffer. inbytesleft Initially, this argument is a pointer to a variable that indicates the number of bytes to the end of the input buffer (inbuf). When the conversion is completed, the variable indicates the number of bytes in inbuf not converted. outbuf A pointer to a variable that points to the first available byte in the output buffer. The output buffer contains the converted characters. outbytesleft Initially, this argument is a pointer to a variable that indicates the number of bytes to the end of the output buffer (outbuf). When the conversion is completed, the variable indicates the number of bytes left in outbuf. 3 Description This function converts characters in the buffer pointed to by inbuf to characters in another code set. The resulting characters are stored in the buffer pointed to by outbuf. The conversion type is specified by the conversion descriptor cd. This descriptor is returned from a successful call to iconv_open. If an invalid character is found in the input buffer, the conversion stops after the last successful conversion. The variable pointed to by inbytesleft is updated to reflect the number of bytes in the input buffer that are not converted. The variable pointed to by outbytesleft is updated to reflect the number of bytes remaining in the output buffer. 3 Return_Values x Number of non-identical conversions performed. Indicates successful conversion. In most cases 0 is returned. (size_t) -1 Indicates an error condition. The function sets errno to one of the following: o EBADF - The cd argument is not a valid conversion descriptor. o EILSEQ - The conversion stops when an invalid character detected. o E2BIG - The conversion stops because of insufficient space in the output buffer. o EINVAL - The conversion stops because of an incomplete character at the end of the input buffer. 2 iconv_close Deallocates a specified conversion descriptor and the resources allocated to the descriptor. Format #include int iconv_close (iconv_t cd); 3 Arguments cd The conversion descriptor to be deallocated. A conversion descriptor is returned by a successful call to iconv_open. 3 Return_Values 0 Indicates that the conversion descriptor was successfully deallocated. -1 Indicates an error occurred. The function sets errno to one of the following: o EBADF - The cd argument is not a valid conversion descriptor. o EVMSERR - Non-translatable VMS error occur. vaxc$errno contains the VMS error code. 2 iconv_open Allocates a conversion descriptor for a specified codeset conversion. Format #include iconv_t iconv_open (const char *tocode, const char *fromcode); 3 Arguments tocode The name of the codeset to which characters are converted. fromcode The name of the source codeset. See the "Developing International Software" chapter of the Compaq C RTL Reference Manual for information on obtaining a list of currently available codesets or for details on adding new codesets. 3 Return_Values x A conversion descriptor. Indicates the call was successful. This descriptor is used in subsequent calls to iconv (iconv_t) -1 Indicates an error occurred. The function sets errno to one of the following: o EMFILE - The process does not have enough I/O channels to open a file. o ENOMEM - Insufficient space is available. o EINVAL - The conversion specified by fromcode and tocode is not supported. o EVMSERR - Nontranslatable VMS error occur. vaxc$errno contains the VMS error code. A value of SS$_BADCHKSUM in vaxc$errno indicates that a conversion table file was found, but its contents is corrupted. A value of SS$_IDMISMATCH in vaxc$errno indicates that the conversion table file version does not match the version of the C Run-Time Library. 3 Example #include #include #include int main() { /* Declare variables to be used */ char fromcodeset[30]; char tocodeset[30]; int iconv_opened; iconv_t iconv_struct; /* Iconv descriptor */ /* Initialize variables */ sprintf(fromcodeset, "DECHANYU"); sprintf(tocodeset, "EUCTW"); iconv_opened = FALSE; /* Attempt to create a conversion descriptor for the */ /* codesets specified. If the return value from */ /* iconv_open is -1 then an error has occurred. */ /* Check the value of errno. */ if ((iconv_struct = iconv_open(tocodeset, fromcodeset)) == (iconv_t) - 1) { /* Check the value of errno */ switch (errno) { case EMFILE: case ENFILE: printf("Too many iconv conversion files open\n"); break; case ENOMEM: printf("Not enough memory\n"); break; case EINVAL: printf("Unsupported conversion\n"); break; default: printf("Unexpected error from iconv_open\n"); break; } } else /* Successfully allocated a conversion descriptor */ iconv_opened = TRUE; /* Was a conversion descriptor allocated */ if (iconv_opened) { /* Attempt to deallocate the conversion descriptor. */ /* If iconv_ close returns -1 then an error has */ /* occurred. */ if (iconv_close(iconv_struct) == -1) { /* An error occurred. Check the value of errno */ switch (errno) { case EBADF: printf("Conversion descriptor is invalid\n"); break; default: printf("Unexpected error from iconv_ close\n"); break; } } } return (EXIT_FAILURE); } 2 [w]inch Return the character at the current cursor position on the specified window without making changes to the window. The inch function acts on the stdscr window. Format #include char inch(); char winch (WINDOW *win); 3 Argument win A pointer to the window. 3 Return_Values x The returned character. ERR Indicates an input error. 2 index Search for a character in a string. Format #include char *index (const char *s, int c); 3 Function_Variants This function also has variants named _index32 and _index64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s The string to search. c The character to search for. 3 Description The index function is identical to the strchr function, and is provided for compatibility with some UNIX implementations. 2 initscr Initializes the terminal-type data and all screen functions. You must call initscr before using any of the curses functions. Format #include void initscr (void); 3 Description The OpenVMS Curses version of this function clears the screen before doing the initialization. The BSD-based Curses version does not. 2 initstate Initializes random number generators. Format #include char *initstate (unsigned int seed, char *state, int size); 3 Arguments seed An initial seed value. state Pointer to an array of state information. size The size of the state information array. 3 Description This function initializes random number generators. It lets you initialize for future use, a state array passed as an argument. The size in bytes of the state array is used by the initstate function to decide how sophisticated a random number generator to use; the larger the state array, the more random the numbers. Values for the amount of state information are 8, 32, 64, 128, and 256 bytes. Amounts less than 8 bytes generate an error, while other amounts are rounded down to the nearest known value. The seed argument specifies a starting point for the random number sequence and provides for restarting at the same point. The initstate function returns a pointer to the previous state information array. Once you initialize a state, the setstate function allows rapid switching between states. The array defined by the state argument is used for further random number generation until the initstate function is called or the setstate function is called again. The setstate function returns a pointer to the previous state array. After initialization, you can restart a state array at a different point in one of two ways: o Use the initstate function with the desired seed argument, state array, and size of the array. o Use the setstate function with the desired state, followed by the srandom function with the desired seed. The advantage of using both functions is that you do not have to save the state array size once you initialize it. See also setstate, srandom, and random. 3 Return_Values x A pointer to the previous state array information. 0 Indicates an error. Call made with less than 8 bytes of state information. Further specified in the global errno. 2 [w]insch Insert a character at the current cursor position in the specified window. The insch function acts on the stdscr window. Format #include int insch (char ch); int winsch (WINDOW *win, char ch); 3 Arguments win A pointer to the window. ch The character to be inserted. 3 Description After the character is inserted, each character on the line shifts to the right, and the last character in the line is deleted. For more information, see the scrollok function. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. 2 [w]insertln Insert a line above the line containing the current cursor position. The insertln function acts on the stdscr window. Format #include int insertln(); int winsertln (WINDOW *win); 3 Argument win A pointer to the window. 3 Description The current line and every line below it shifts down, and the bottom line disappears. The inserted line is blank and the current (y,x) coordinates remain the same. For more information, see the scrollok function. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. 2 [w]insstr Insert a string at the current cursor position in the specified window. The insstr function acts on the stdscr window. Format #include int insstr (char *str); int winsstr (WINDOW *win, char *str); 3 Arguments win A pointer to the window. str A pointer to the string to be inserted. 3 Description Each character after the string shifts to the right, and the last character disappears. These functions are specific to Compaq C for OpenVMS Systems and are not portable. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. For more information, see the scrollok function. 2 isalnum Indicates if a character is classed either as alphabetic or as a digit in the program's current locale. Format #include int isalnum (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If alphanumeric. 0 If not alphanumeric. 2 isalpha Indicates if a character is classed as an alphabetic character in the program's current locale. Format #include int isalpha (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If alphabetic. 0 If not alphabetic. 2 isapipe Indicates if a specified file descriptor is associated with a pipe. Format #include int isapipe (int file_desc); 3 Argument file_desc A file descriptor. 3 Description For more information about pipes, see the "Subprocess Functions" chapter of the Compaq C RTL Reference Manual. 3 Return_Values 1 Indicates an association with a pipe. 0 Indicates no association with a pipe. -1 Indicates an error (for example, if the file descriptor is not associated with an open file). 2 isascii Indicates if a character is an ASCII character. Format #include int isascii (int character); 3 Argument character An object of type char. 3 Return_Values nonzero If ASCII. 0 If not ASCII. 2 isatty Indicates if a specified file descriptor is associated with a terminal. Format #include int isatty (int file_desc); 3 Argument file_desc A file descriptor. 3 Return_Values 1 If the file descriptor is associated with a terminal. 0 If the file descriptor is not associated with a terminal. -1 Indicates an error (for example, if the file descriptor is not associated with an open file). 2 iscntrl Indicates if a character is classed as a control character in the program's current locale. Format #include int iscntrl (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a control character. zero If not a control character. 2 isdigit Indicates if a character is classed as a digit in the program's current locale. Format #include int isdigit (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a decimal digit. 0 If not a decimal digit. 2 isgraph Indicates if a character is classed as a graphic character in the program's current locale. Format #include int isgraph (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a graphic character. 0 If not a graphic character. 2 islower Indicates if a character is classed as a lowercase character in the program's current locale. Format #include int islower (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a lowercase alphabetic character. 0 If not a lowercase alphabetic character. 2 isnan Test for a NaN. Returns 1 if the argument is NaN; 0 if not. This function is OpenVMS Alpha only. Format #include int isnan (double x); int isnanf (float x); int isnanl (long double x); 3 Argument x A real value. 3 Description The isnan functions return the integer value 1 (True) if x is NaN (the IEEE floating point reserved not-a-number value); otherwise, they return the value 0 (False). 2 isprint Indicates if a character is classed as a printing character in the program's current locale. Format #include int isprint (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a printing character. 0 If not a printing character. 2 ispunct Indicates if a character is classed as a punctuation character in the program's current locale. Format #include int ispunct (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a punctuation character. 0 If not a punctuation character. 2 isspace Indicates if a character is classed as white space in the program's current locale; that is, if it is an ASCII space, tab (horizontal or vertical), carriage-return, form-feed, or new-line character. Format #include int isspace (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a white-space character. 0 If not a white-space character. 2 isupper Indicates if a character is classed as an uppercase character in the program's current locale. Format #include int isupper (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If an uppercase alphabetic character. 0 If not an uppercase alphabetic character. 2 iswalnum Indicates if a wide character is classed either as alphabetic or as a digit in the program's current locale. Format #include (ISO C) #include (XPG4) int iswalnum (wint_t wc); 3 Arguments wc An object of type wint_t. The value of character must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If alphanumeric. 0 If not alphanumeric. 2 iswalpha Indicates if a wide character is classed as an alphabetic character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswalpha (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If alphabetic. 0 If not alphabetic. 2 iswcntrl Indicates if a wide character is classed as a control character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswcntrl (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a control character. 0 If not a control character. 2 iswctype Indicates if a wide character has a specified property. Format #include (ISO C) #include (XPG4) int iswctype (wint_t wc, wctype_t wc_prop); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a valid wide-character code in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. wc_prop A valid property name in the current locale. This is set up by calling the wctype function. 3 Description This function tests whether wc has the character-class property wc_prop. Set wc_prop by calling the wctype function. See also wctype. 3 Return_Values nonzero If the character has the property wc_prop. 0 If the character does not have the property wc_prop. 3 Example #include #include #include #include #include #include /* This test will set up the "upper" character class using */ /* wctype() and then verify whether the characters 'a' and 'A' */ /* are members of this class */ #include main() { wchar_t w_char1, w_char2; wctype_t ret_val; char *char1 = "a"; char *char2 = "A"; ret_val = wctype("upper"); /* Convert char1 to wide-character format - w_char1 */ if (mbtowc(&w_char1, char1, 1) == -1) { perror("mbtowc"); exit(EXIT_FAILURE); } if (iswctype((wint_t) w_char1, ret_val)) printf("[%C] is a member of the character class upper\n", w_char1); else printf("[%C] is not a member of the character class upper\n", w_char1); /* Convert char2 to wide-character format - w_char2 */ if (mbtowc(&w_char2, char2, 1) == -1) { perror("mbtowc"); exit(EXIT_FAILURE); } if (iswctype((wint_t) w_char2, ret_val)) printf("[%C] is a member of the character class upper\n", w_char2); else printf("[%C] is not a member of the character class upper\n", w_char2); } Running the example program produces the following result: [a] is not a member of the character class upper [A] is a member of the character class upper 2 iswdigit Indicates if a wide character is classed as a digit in the program's current locale. Format #include (ISO C) #include (XPG4) int iswdigit (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a decimal digit. 0 If not a decimal digit. 2 iswgraph Indicates if a wide character is classed as a graphic character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswgraph (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a graphic character. 0 If not a graphic character. 2 iswlower Indicates if a wide character is classed as a lowercase character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswlower (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a lowercase character. 0 If not a lowercase character. 2 iswprint Indicates if a wide character is classed as a printing character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswprint (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a printing character. 0 If not a printing character. 2 iswpunct Indicates if a wide character is classed as a punctuation character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswpunct (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a punctuation character. 0 If not a punctuation character. 2 iswspace Indicates if a wide character is classed as a space character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswspace (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a whitespace character. 0 If not a whitespace character. 2 iswupper Indicates if a wide character is classed as an uppercase character in the program's current locale. Format #include (ISO C) #include (XPG4) int iswupper (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If an uppercase character. 0 If not an uppercase character. 2 iswxdigit Indicates if a wide character is a hexadecimal digit (0 to 9, A to F, or a to f) in the program's current locale. Format #include (ISO C) #include (XPG4) int iswxdigit (wint_t wc); 3 Arguments wc An object of type wint_t. The value of wc must be representable as a wchar_t in the current locale, or must equal the value of the macro WEOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a hexadecimal digit. 0 If not a hexadecimal digit. 2 isxdigit Indicates if a character is a hexadecimal digit (0 to 9, A to F, or a to f) in the program's current locale. Format #include int isxdigit (int character); 3 Argument character An object of type int. The value of character must be representable as an unsigned char in the current locale, or must equal the value of the macro EOF. If it has any other value, the behavior is undefined. 3 Return_Values nonzero If a hexadecimal digit. 0 If not a hexadecimal digit. 2 j0,_j1,_jn Compute Bessel functions of the first kind. This function is OpenVMS Alpha only. Format #include double j0 (double x); float j0f (float x); long double j0l (long double x); double j1 (double x); float j1f (float x); long double j1l (long double x); double jn (int n, double x); float jnf (int n, float x); long double jnl (int n, long double x); 3 Argument x A real value. n An integer. 3 Description The j0 functions return the value of the Bessel function of the first kind of order 0. The j1 functions return the value of the Bessel function of the first kind of order 1. The jn functions return the value of the Bessel function of the first kind of order n. The j1 and jn functions can result in an underflow as x gets small. The largest value of x for which this occurs is a function of n. 3 Return_Values x The relevant Bessel value of x of the first kind. 0 The value of the x argument is too large, or underflow occurred; errno is set to ERANGE. NaN x is NaN; errno is set to EDOM. 2 jrand48 Generate uniformly distributed pseudorandom number sequences. Returns 48-bit signed, long integers. Format #include long int jrand48 (unsigned short int xsubi[3]); 3 Arguments xsubi An array of three short int that form a 48-bit integer when concatentated together. 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. The function returns signed long integers uniformly distributed over the range of y values, such that -231 The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The jrand48 function requires that the calling program pass an array as the xsubi argument, which for the first call must be initialized to the initial value of the pseudorandom number sequence. Unlike the drand48 function, it is not necessary to call an initialization function prior to the first call. By using different arguments, jrand48 allows separate modules of a large program to generate several independent sequences of pseudorandom numbers. For example, the sequence of numbers that one module generates does not depend upon how many times the function is called by other modules. 3 Return_Values n Signed, long integers uniformly distributed over the range -231 2 kill Sends a signal to the process specified by a process ID. Format #include int kill (int pid, int sig); 3 Arguments pid The process ID. sig The signal code. 3 Description This function is restricted to C and C++ programs that include the main function. The kill function sends a signal to a process, as if the process had called raise. If the signal is not trapped or ignored by the target program, the program exits. OpenVMS VAX and Alpha implement different rules about what process you are allowed to send signals to. A program always has privileges to send a signal to a child started with vfork/exec. For other processes, the results are determined by the OpenVMS security model for your system. Because of an OpenVMS restriction, the kill function cannot deliver a signal to a target process that runs an image installed with privileges. Unless you have system privileges, the sending and receiving processes must have the same user identification code (UIC). On OpenVMS systems before Version 7.0, kill treats a signal value of 0 as if SIGKILL were specified. For OpenVMS Version 7.0 and higher systems, if you include and compile with the _POSIX_EXIT feature-test macro set, then: o If the signal value is 0, kill validates the process ID but does not send any signals. o If the process ID is not valid, kill returns -1 and sets errno to ESRCH. 3 Return_Values 0 Indicates that kill was successfully queued. -1 Indicates errors. The receiving process may have a different UIC and you are not a system user, or the receiving process does not exist. 2 labs Returns the absolute value of an integer as a long int. Format #include long int labs (long int j); 3 Argument j A value of type long int. 2 lcong48 Initializes a 48-bit uniformly distributed pseudorandom number sequences. Format #include void lcong48 (unsigned short int param[7]); 3 Arguments param An array that in turn specifies the initial Xi, the multiplier value a, and the addend value c. 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. You can use lcong48 to initialize the random number generator before you call any of the following functions: drand48 lrand48 mrand48 The lcong48 function specifies the initial Xi value, the multiplier value a, and the addend value c. The param array elements specify the following: param[0- Xi 2] param[3- Multiplier a value 5] param[6] 16-bit addend c value After lcong48 has been called, a subsequent call to either srand48 or seed48 restores the standard a and c as specified previously. The lcong48 function does not return a value. See also drand48, lrand48, mrand48, srand48, and seed48. 2 ldexp Returns its first argument multiplied by 2 raised to the power of its second argument; that is, x(2n). Format #include double ldexp (double x, int n); float ldexp (float x, int n); (Alpha only) long double ldexp (long double x, int n); (Alpha only) 3 Arguments x A base value of type double, float, or long double that is to be multiplied by 2n. n The integer exponent value to which 2 is raised. 3 Return_Values x(2n) The first argument multiplied by 2 raised to the power of the second argument. 0 Underflow occurred; errno is set to ERANGE. HUGE_VAL Overflow occurred; errno is set to ERANGE. Nan x is NaN; errno is set to EDOM. 2 ldiv Returns the quotient and the remainder after the division of its arguments. Format #include ldiv_t ldiv (long int numer, long int denom); 3 Arguments numer A numerator of type long int. denom A denominator of type long int. 3 Description The type ldiv_t is defined in the header file as follows: typedef struct { long quot, rem; } ldiv_t; See also div. 2 leaveok Signals Curses to leave the cursor at the current coordinates after an update to the window. Format #include leaveok (WINDOW *win, bool boolf); 3 Arguments win A pointer to the window. boolf A Boolean TRUE or FALSE value. If boolf is TRUE, the cursor remains in place after the last update and the coordinate setting on win changes accordingly. If boolf is FALSE, the cursor moves to the currently specified (y,x) coordinates of win. 3 Description This function defaults to moving the cursor to the current coordinates of win. The bool type is defined in the header file as follows: #define bool int 2 lgamma Computes the logarithm of the gamma function. This function is OpenVMS Alpha only. Format #include double lgamma (double x); float lgammaf (float x); long double lgammal (long double x); 3 Argument x A real number. x cannot be 0, a negative integer, or Infinity. 3 Description The lgamma functions return the logarithm of the absolute value of gamma of x, or ln(|G(x)|), where G is the gamma function. The sign of gamma of x is returned in the external integer variable signgam. The x argument cannot be 0, a negative integer, or Infinity. 3 Return_Values x The logarithmic gamma of the x argument. -HUGE_VAL The x argument is a negative integer; errno is set to ERANGE. NaN The x argument is NaN; errno is set to EDOM. 0 Underflow occurred; errno is set to ERANGE. HUGE_VAL Overflow occurred; errno is set to ERANGE. 2 link Creates a new link (directory entry) for an existing file. This function is supported only on volumes that have hard link counts enabled. Format #include link (const char *path1, const char *path2); 3 Arguments path1 Pointer to a path name naming an existing file. path2 Pointer to a path name naming the new directory entry to be created. 3 Description The link function atomically creates a new link for the existing file, and the link count of the file is incremented by one. The link function can be used on directory files. If link fails, no link is created and the link count of the file remains unchanged. 3 Return_Values 0 Successful completion. -1 Indicates an error. The function sets errno to one of the following values: o EEXIST - The link named by path2 exists. o EFTYPE - Wildcards appear in either path1 or path2. o EINVAL - One or both arguments specify a syntactically invalid path name. o ENAMETOOLONG - The length of path1 or path2 exceeds {PATH_MAX}, or a path name component is longer than {NAME_MAX}. o EXDEV - The link named by path2 and the file named by path1 are on different devices. 2 localeconv Sets the members of a structure of type struct lconv with values appropriate for formatting numeric quantities according to the rules of the current locale. Format #include struct lconv *localeconv (void); 3 Description This function returns a pointer to the lconv structure defined in the header file. This structure should not be modified by the program. It is overwritten by calls to localeconv, or by calls to the setlocale function that change the LC_NUMERIC, LC_ MONETARY, or LC_ALL categories. The members of the structure are: Member Description char *decimal_ The radix character point char *thousands_ The character used to separate groups of sep digits char *grouping The string that defines how digits are grouped in non-monetary values. char *int_curr_ The international currency symbol symbol char *currency_ The local currency symbol symbol char *mon_ The radix character used to format monetary decimal_point values char *mon_ The character used to separate groups of thousands_sep digits in monetary values char *mon_ The string that defines how digits are grouped grouping in a monetary value char *positive_ The string used to indicate a non-negative sign monetary value char *negative_ The string used to indicate a negative sign monetary value char int_frac_ The number of digits displayed after the radix digits character in a monetary value formatted with the international currency symbol. char frac_digits The number of digits displayed after the radix character in a monetary value char p_cs_ For positive monetary values, this is set to 1 precedes if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number. char p_sep_by_ For positive monetary values, this is set to space 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string. char n_cs_ For negative monetary values, this is set to 1 precedes if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number. char n_sep_by_ For negative monetary values, this is set to space 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string. char p_sign_posn An integer used to indicate where the positive_sign string should be placed for a non-negative monetary quantity. char n_sign_posn An integer used to indicate where the negative_sign string should be placed for a negative monetary quantity. Members of the structure of type char* are pointers to strings, any of which (except decimal_point) can point to "", indicating that the associated value is not available in the current locale or is zero length. Members of the structure of type char are positive numbers, any of which can be CHAR_MAX, indicating that the associated value is not available in the current locale. CHAR_MAX is defined in the header file. Be aware that the value of the CHAR_MAX macro in the header depends on whether the program is compiled with the /UNSIGNED_CHAR qualifier: o Use the CHAR_MAX macro as an indicator of a non-available value in the current locale only if the program is compiled without /UNSIGNED_CHAR (/NOUNSIGNED_CHAR is the default). o If the program is compiled with /UNSIGNED_CHAR, use the SCHAR_ MAX macro instead of the CHAR_MAX macro. In /NOUNSIGNED_CHAR mode, the values of CHAR_MAX and SCHAR_MAX are the same; therefore, comparison with SCHAR_MAX gives correct results regardless of the /[NO]UNSIGNED_CHAR mode used. The members grouping and mon_grouping point to a string that defines the size of each group of digits when formatting a number. Each group size is separated by a semicolon (;). For example, if grouping points to the string 5;3 and the thousands_ sep character is a comma (,), the number 123450000 would be formatted as 1,234,50000. The elements of grouping and mon_grouping are interpreted as follows: Value Interpretation CHAR_MAX No further grouping is performed. 0 The previous element is to be used repeatedly for the remainder of the digits. other The integer value is the number of digits that comprise the current group. The next element is examined to determine the size of the next group of digits before the current group. The values of p_sign_posn and n_sign_posn are interpreted as follows: Value Interpretation 0 Parentheses surround the number and currency symbol. 1 The sign string precedes the number and currency symbol. 2 The sign string succeeds the number and currency symbol. 3 The sign string immediately precedes the number and currency symbol. 4 The sign string immediately succeeds the number and currency symbol. 3 Return_Value x Pointer to the lconv structure. 3 Example #include #include #include #include #include /* The following test program will set up the British English */ /* locale, and then extract the International Currency symbol */ /* and the International Fractional Digits fields for this */ /* locale and print them. */ int main() { /* Declare variables */ char *return_val; struct lconv *lconv_ptr; /* Load a locale */ return_val = (char *) setlocale(LC_ALL, "en_GB.iso8859-1"); /* Did the locale load successfully? */ if (return_val == NULL) { /* It failed to load the locale */ printf("ERROR : The locale is unknown"); exit(EXIT_FAILURE); } /* Get the lconv structure from the locale */ lconv_ptr = (struct lconv *) localeconv(); /* Compare the international currency symbol string with an */ /* empty string. If they are equal, then the international */ /* currency symbol is not defined in the locale. */ if (strcmp(lconv_ptr->int_curr_symbol, "")) { printf("International Currency Symbol = %s\n", lconv_ptr->int_curr_symbol); } else { printf("International Currency Symbol ="); printf("[Not available in this locale]\n"); } /* Compare International Fractional Digits with CHAR_MAX. */ /* If they are equal, then International Fractional Digits */ /* are not defined in this locale. */ if ((unsigned char) (lconv_ptr->int_frac_digits) != CHAR_MAX) { printf("International Fractional Digits = %d\n", lconv_ptr->int_frac_digits); } else { printf("International Fractional Digits ="); printf("[Not available in this locale]\n"); } } Running the example program produces the following result: International Currency Symbol = GBP International Fractional Digits = 2 2 localtime,_localtime_r Converts a time value to broken-down local time. Format #include struct tm *localtime (const time_t *timer); struct tm *localtime_r (const time_t *timer, struct tm *result); (ISO POSIX-1) 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Argument timer A pointer to a time in seconds since the Epoch. You can generate this time by using the time function or you can supply a time. result A pointer to a tm structure where the result is stored. The tm structure is defined in the header file, and is also shown in tm Structure. 3 Description The localtime and localtime_r functions convert the time (in seconds since the Epoch) pointed to by timer into a broken-down time, expressed as a local time, and store it in a tm structure. The difference between the localtime_r and localtime functions is that the former stores the result into a user-specified tm structure. The latter stores the result into thread-specific static memory allocated by the Compaq C RTL, and which is overwritten by subsequent calls to localtime; you must make a copy if you want to save it. On success, localtime returns a pointer to the tm structure; localtime_r returns its second argument. On failure, these functions return the NULL pointer. The tm structure is defined in the header file and described in tm Structure. Table REF-4 tm Structure int tm_sec; Seconds after the minute (0-60) int tm_min; Minutes after the hour (0-59) int tm_hour; Hours since midnight (0-23) int tm_mday; Day of the month (1-31) int tm_mon; Months since January (1-11) int tm_year; Years since 1900 int tm_wday; Days since Sunday (0-6) int tm_yday; Days since January 1 (0-365) int tm_ Daylight Savings Time flag isdst; o tm_isdst = 0 for Standard Time o tm_isdst = 1 for Daylight Time long tm_ Seconds east of Greenwich (Negative values gmtoff; indicate seconds west of Greenwich) char *tm_ Time zone string, for example "GMT" zone; The type time_t is defined in the header file as follows: typedef long int time_t NOTE Generally speaking, UTC-based time functions can affect in- memory time-zone information, which is process-wide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_ r, ctime_r, gmtime_r and localtime_r, is both thread-safe and AST-reentrant. If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant. 3 Return_Value x Pointer to a tm structure. NULL Indicates failure. 2 log,_log2,_log10 Return the logarithm of their arguments. Format #include double log (double x); float logf (float x); (Alpha only) long double logl (long double x); (Alpha only) double log2 (double x); (Alpha only) float log2f (float x); (Alpha only) long double log2l (long double x); (Alpha only) double log10 (double x); float log10f (float x); (Alpha only) long double log10l (long double x); (Alpha only) 3 Argument x A real number. 3 Description The log functions compute the natural (base e) logarithm of x. The log2 functions compute the base 2 logarithm of x. The log10 functions compute the common (base 10) logarithm of x. 3 Return_Values x The logarithm of the argument (in the appropriate base). -HUGE_VAL x is 0 (errno is set to ERANGE), or x is negative (errno is set to EDOM). NaN x is NaN; errno is set to EDOM. 2 log1p Computes ln(1+y) accurately. This function is OpenVMS Alpha only. Format #include double log1p (double y); float log1pf (float y); long double log1pl (long double y); 3 Argument y A real number greater than -1. 3 Description The log1p functions compute ln(1+y) accurately, even for tiny y. 3 Return_Values x The natural logarithm of (1+y). -HUGE_VAL y is less than -1 (errno is set to EDOM), or y = -1 (errno is set to ERANGE). NaN y is NaN; errno is set to EDOM. 2 logb Returns the radix-independent exponent of the argument. This function is OpenVMS Alpha only. Format #include double logb (double x); float logbf (float x); long double logbl (long double x); 3 Argument x A nonzero, real number. 3 Description The logb functions return the exponent of x, which is the integral part of log(2)|x|, as a signed floating-point value, for nonzero x. 3 Return_Values x The exponent of x. -HUGE_VAL x = 0.0; errno is set to EDOM. +Infinity x is +Infinity or -Infinity. NaN y is NaN; errno is set to EDOM. 2 longjmp Provides a way to transfer control from a nested series of function invocations back to a predefined point without returning normally; that is, by not using a series of return statements. The longjmp function restores the context of the environment buffer. Format #include void longjmp (jmp_buf env, int value); 3 Arguments env The environment buffer, which must be an array of integers long enough to hold the register context of the calling function. The type jmp_buf is defined in the header file. The contents of the general-purpose registers, including the program counter (PC), are stored in the buffer. value Passed from longjmp to setjmp, and then becomes the subsequent return value of the setjmp call. If value is passed as 0, it is converted to 1. 3 Description When setjmp is first called, it returns the value 0. If longjmp is then called, naming the same environment as the call to setjmp, control is returned to the setjmp call as if it had returned normally a second time. The return value of setjmp in this second return is the value you supply in the longjmp call. To preserve the true value of setjmp, the function calling setjmp must not be called again until the associated longjmp is called. The setjmp function preserves the hardware general purpose registers, and the longjmp function restores them. After a longjmp, all variables have their values as of the time of the longjmp except for local automatic variables not marked volatile. These variables have indeterminate values. The setjmp and longjmp functions rely on the OpenVMS condition- handling facility to effect a nonlocal goto with a signal handler. The longjmp function is implemented by generating a Compaq C RTL specified signal and allowing the OpenVMS condition- handling facility to unwind back to the desired destination. The Compaq C RTL must be in control of signal handling for any Compaq C image. For Compaq C to be in control of signal handling, you must establish all exception handlers through a call to the VAXC$ESTABLISH function (rather than LIB$ESTABLISH). NOTE There are Alpha specific, non-standard decc$setjmp and decc$fast_longjmp functions. To use these non-standard functions instead of the standard ones, a program must be compiled with __FAST_SETJMP or __UNIX_SETJMP macros defined. Unlike the standard longjmp function, the decc$fast_longjmp function does not convert its second argument from 0 to 1. After a call to decc$fast_longjmp, a corresponding setjmp function returns with the exact value of the second argument specified in the decc$fast_longjmp call. 3 Restrictions You cannot invoke the longjmp function from a OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the Compaq C RTL, subject to the following nesting restrictions: o The longjmp function will not work if invoked from nested signal handlers. The result of the longjmp function, when invoked from a signal handler that has been entered as a result of an exception generated in another signal handler, is undefined. o Do not invoke the setjmp function from a signal handler unless the associated longjmp is to be issued before the handling of that signal is completed. o Do not invoke the longjmp function from within an exit handler (established with atexit or SYS$DCLEXH). Exit handlers are invoked after image tear-down, so the destination address of the longjmp no longer exists. o Invoking longjmp from within a signal handler to return to the main thread of execution might leave your program in an inconsistent state. Possible side effects include the inability to perform I/O or to receive any more UNIX signals. 2 longname Returns the full name of the terminal. Format #include void longname (char *termbuf, char *name); 3 Function_Variants This function also has variants named _longname32 and _longname64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments termbuf A string containing the name of the terminal. name A character-string buffer with a minimum length of 64 characters. 3 Description The terminal name is in a readable format so that you can double-check to be sure that Curses has correctly identified your terminal. The dummy argument termbuf is required for UNIX software compatibility and serves no function in the OpenVMS environment. If portability is a concern, you must write a set of dummy routines to perform the functionality provided by the database termcap in the UNIX system environment. 2 lrand48 Generates uniformly distributed pseudorandom number sequences. Returns 48-bit signed long integers. Format #include long int lrand48 (void); 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. It returns nonnegative, long integers uniformly distributed over the range of y values such that 0 Before you call the lrand48 function use either srand48, seed48, or lcong48 to initialize the random number generator. You must initialize prior to invoking the lrand48 function, because it stores the last 48-bit Xi generated into an internal buffer. (Although it is not recommended, constant default initializer values are supplied automatically if the drand48, lrand48, or mrand48 functions are called without first calling an initialization function.) The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The value returned by the lrand48 function is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of data item to be returned, are copied from the high-order (most significant) bits of Xi and transformed into the returned value. See also drand48, lcong48, mrand48, seed48, and srand48. 3 Return_Values n Signed nonnegative long integers uniformly distributed over the range 0 2 lseek Positions a file to an arbitrary byte position and returns the new position. Format #include off_t lseek (int file_desc, off_t offset, int direction); 3 Arguments file_desc An integer returned by open, creat, dup, or dup2. offset The offset, specified in bytes. The off_t data type is either a 64-bit integer or a 32-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE direction An integer indicating whether the offset is to be measured forward from the beginning of the file (direction=SEEK_SET), forward from the current position (direction=SEEK_CUR), or backward from the end of the file (direction=SEEK_END). 3 Description This function can position fixed-length record-access file with no carriage control or a stream-access file on any byte offset, but can position all other files only on record boundaries. The available Standard I/O functions position a record file at its first byte, at the end-of-file, or on a record boundary. Therefore, the arguments given to lseek must specify either the beginning or end of the file, a 0 offset from the current position (an arbitrary record boundary), or the position returned by a previous, valid lseek call. This function returns the new file position as an integer of type off_t which, like the offset parameter, is either a 64-bit integer if _LARGEFILE is defined, or a 32-bit integer if not. For a portable way to position an arbitrary byte location with any type of file, see the fgetpos and fsetpos functions. CAUTION If, while accessing a stream file, you seek beyond the end-of-file and then write to the file, the lseek function creates a hole by filling the skipped bytes with zeros. In general, for record files, lseek should only be directed to an absolute position that was returned by a previous valid call to lseek or to the beginning or end of a file. If a call to lseek does not satisfy these conditions, the results are unpredictable. See also open, creat, dup, dup2, and fseek. 3 Return_Values x The new file position. -1 Indicates that the file descriptor is undefined, or a seek was attempted before the beginning of the file. 2 lwait Waits for I/O on a specific file to complete. Format #include int lwait (int fd); 3 Argument fd A file descriptor corresponding to an open file. 3 Description This function is used primarily to wait for completion of pending asynchronous I/O. 3 Return_Values 0 Indicates successful completion. -1 Indicates an error. 2 malloc Allocates an area of memory. These functions are AST-reentrant. Format #include void *malloc (size_t size); 3 Function_Variants This function also has variants named _malloc32 and _malloc64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument size The total number of bytes to be allocated. 3 Description This function allocates a contiguous area of memory whose size, in bytes, is supplied as an argument. The space is not initialized. NOTE The malloc routines call the system routine LIB$VM_MALLOC. Because LIB$VM_MALLOC is designed as a general purpose routine to allocate memory, it is called upon in a wide array of scenarios to allocate and reallocate blocks efficiently. The most common usage is the management of smaller blocks of memory, and the most important aspect of memory allocation under these circumstances is efficiency. LIB$VM_MALLOC makes use of its own free space to satisfy requests, once the heap storage is consumed by splitting large blocks and merging adjacent blocks. Memory can still become fragmented, leaving unused blocks. Once heap storage is consumed, LIB$VM_MALLOC manages its own free space and merged blocks to satisfy requests, but varying sizes of memory allocations can cause blocks to be left unused. Because LIB$VM_MALLOC cannot be made to satisfy all situations in the best possible manner, you should perform your own memory management if you have special memory usage needs. This assures the best use of memory for your particular application. The OpenVMS Programming Concepts Manual explains the several memory allocation routines that are available. They are grouped into 3 levels of hierarchy: 1. At the highest level are the RTL Heap Management Routines LIB$GET_VM and LIB$FREE_VM, which provide a mechanism for allocating and freeing blocks of memory of arbitrary size. Also at this level are the routines based on the concept of zones, such as LIB$CREATE_VM_ZONE, and so on. 2. At the next level are the RTL Page Management routines LIB$GET_VM_PAGE and LIB$FREE_VM_PAGE, which allocate a specified number of contiguous pages. 3. At the lowest level are the Memory Management System Services such as $CRETVA and $EXPREG that provide extensive control over address space allocation. Note that at this level, you must manage the allocation precisely. 3 Return_Values x The address of the first byte, which is aligned on a quadword boundary. NULL Indicates that the function is unable to allocate enough memory. errno is set to ENOMEM. 2 mblen Determines the number of bytes comprising a multibyte character. Format #include int mblen (const char *s, size_t n); 3 Arguments s A pointer to the multibyte character. n The maximum number of bytes that comprise the multibyte character. 3 Description If the character is n bytes or less, this function returns the number of bytes comprising the multibyte character pointed to by s. If the character is greater than n bytes, the function returns -1 to indicate an error. This function is affected by the LC_CTYPE category of the program's current locale. 3 Return_Values x The number of bytes that comprise the multibyte character, if the next n or fewer bytes form a valid character. 0 If s is NULL or a pointer to the NULL character. -1 Indicates an error occurred. The function sets errno to EILSEQ - Invalid character detected. 2 mbrlen Determines the number of bytes comprising a multibyte character. Format #include size_t mbrlen (const char *s, size_t n, mbstate_t *ps); 3 Arguments s A pointer to a multibyte character. n The maximum number of bytes that comprise the multibyte character. ps A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state-dependent codesets. 3 Description The mbrlen function is equivalent to the call: mbrtowc(NULL, s, n, ps != NULL ? ps : &internal) Where internal is the mbstate_t object for the mbrlen function. If the multibyte character pointed to by s is of n bytes or less, the function returns the number of bytes comprising the character (including any shift sequences). If either an encoding error occurs or the next n bytes contribute to an incomplete but potentially valid multibyte character, the function returns -1 or -2, respectively. See also mbrtowc. 3 Return_Values x The number of bytes comprising the multibyte character. 0 Indicates that s is a NULL pointer or a pointer to a null byte. -1 Indicates an encoding error, in which case the next n or fewer bytes do not contribute to a complete and valid multibyte character. errno is set to EILSEQ; the conversion state is undefined. -2 Indicates an incomplete but potentially valid multibyte character (all n bytes have been processed). 2 mbrtowc Converts a multibyte character to its wide-character representation. Format #include size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps); 3 Arguments pwc A pointer to the resulting wide-character code. s A pointer to a multibyte character. n The maximum number of bytes that comprise the multibyte character. ps A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state-dependent codesets. 3 Description If s is a NULL pointer, mbrtowc is equivalent to the call: mbrtowc(NULL, "", 1, ps) In this case, the values of pwc and n are ignored. If s is not a NULL pointer, mbrtowc inspects at most n bytes beginning with the byte pointed to by s to determine the number of bytes needed to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character is completed, it determines the value of the corresponding wide character and then, if pwc is not a NULL pointer, stores that value in the object pointed to by pwc. If the corresponding wide character is the null wide character, the resulting state described is the initial conversion state. If mbrtowc is called as a counting function, which means that pwc is a NULL pointer and s is neither a NULL pointer nor a pointer to a null byte, the value of the internal mbstate_t object will remain unchanged. 3 Return_Values x The number of bytes comprising the multibyte character. 0 The next n or fewer bytes complete the multibyte character that corresponds to the null wide character (which is the value stored if pwc is not a NULL pointer). The wide- character code corresponding to a null byte is zero. -1 Indicates an encoding error. The next n or fewer bytes do not contribute to a complete and valid multibyte character. errno is set to EILSEQ. The conversion state is undefined. -2 Indicates an incomplete but potentially valid multibyte character (all n bytes have been processed). 2 mbstowcs Converts a sequence of multibyte characters into a sequence of corresponding wide-character codes. Format #include size_t mbstowcs (wchar_t *pwcs, const char *s, size_t n); 3 Arguments pwcs A pointer to the array containing the resulting sequence of wide- character codes. s A pointer to the array of multibyte characters. n The maximum number of wide-character codes that can be stored in the array pointed to by pwcs. 3 Description This function converts a sequence of multibyte characters from the array pointed to by s to a sequence of wide-character codes that are stored into the array pointed to by pwcs, up to a maximum of n codes. This function is affected by the LC_CTYPE category of the program's current locale. If copying takes place between objects that overlap, the behavior is undefined. 3 Return_Values x The number of array elements modified or required, not included any terminating zero code. The array will not be zero-terminated if the value returned is n. If pwcs is the NULL pointer, mbstowcs returns the number of elements required for the wide-character array. (size_t) -1 Indicates that an error occurred. The function sets errno to EILSEQ - Invalid character detected. 2 mbtowc Converts a multibyte character to its wide-character equivalent. Format #include int mbtowc (wchar_t *pwc, const char *s, size_t n); 3 Arguments pwc A pointer to the resulting wide-character code. s A pointer to the multibyte character. n The maximum number of bytes that comprise the next multibyte character. 3 Description If the character is n or fewer bytes, this function converts the multibyte character pointed to by s to its wide-character equivalent. If the character is invalid or greater than n bytes, the function returns -1 to indicate an error. If pwc is a NULL pointer and s is not a null pointer, the function determines the number of bytes that constitute the multibyte character pointed to by s (regardless of the value of n). This function is affected by the LC_CTYPE category of the program's current locale. 3 Return_Values x The number of bytes that comprise the valid character pointed to by s. 0 If s is either a NULL pointer or a pointer to the null byte. -1 Indicates an error occurred. The function sets errno to EILSEQ - Invalid character detected. 2 mbsinit Determines whether an mbstate_t object decribes an initial conversion state. Format #include int mbsinit (const mbstate_t *ps); 3 Arguments ps A pointer to the mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state- dependent codesets. 3 Description If ps is not a NULL pointer, this function determines whether the mbstate_t object pointed to by ps describes an initial conversion state. A zero mbstate_t object always describes an initial conversion state. 3 Return_Values nonzero The ps argument is a NULL pointer, or the mbstate_t object pointed to by ps describes an initial conversion state. 0 The mbstate_t object pointed to by ps does not describe an initial conversion state. 2 mbsrtowcs Converts a sequence of multibyte characters to a sequence of corresponding wide-character codes. Format #include size_t mbsrtowcs (wchar_t *dst, const char **src, size_t len, mbstate_t *ps); 3 Function_Variants This function also has variants named _mbsrtowcs32 and _ mbsrtowcs64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dst A pointer to the destination array containing the resulting sequence of wide-character codes. src An address of the pointer to an array containing a sequence of multibyte characters to be converted. len The maximum number of wide character codes that can be stored in the array pointed to by dst. ps A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state-dependent codesets. 3 Description This function converts a sequence of multibyte characters, beginning in the conversion state described by the object pointed to by ps, from the array indirectly pointed to by src, into a sequence of corresponding wide characters. If dst is not a NULL pointer, the converted characters are stored into the array pointed to by dst. Conversion continues up to and including a terminating null character, which is also stored. Conversion stops earlier for one of the following reasons: o A sequence of bytes is encountered that does not form a valid multibyte character. o If dst is not a NULL pointer, when len codes have been stored into the array pointed to by dst. If dst is not a NULL pointer, the pointer object pointed to by src is assigned either a NULL pointer, (if the conversion stopped because of reaching a terminating null wide character) or the address just beyond the last multibyte character converted (if any). If conversion stopped because of reaching a terminating null wide character, the resulting state described is the initial conversion state. 3 Return_Values n The number of multibyte characters successfully converted, sequence, not including the terminating null (if any). -1 Indicates an error. A sequence of bytes that do not form valid multibyte character was encountered. errno is set to EILSEQ; the conversion state is undefined. 2 memccpy Copies characters sequentially between strings in memory areas. Format #include void *memccpy (void *dest, void *source, int c, size_t n); 3 Function_Variants This function also has variants named _memccpy32 and _memccpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest A pointer to the location of a destination string. source A pointer to the location of a source string. c A character that you want to search for. n The number of charcter you want to copy. 3 Description This function operates on strings in memory areas. A memory area is a group of contiguous characters bound by a count and not terminated by a null character. The function does not check for overflow of the receiving memory area. The memccpy function is defined in the header file. The memccpy function sequentially copies characters from the location pointed to by source into the location pointed to by dest until one of the following occurs: o The character specified by c (converted to an unsigned char) is copied. o The number of characters specified by n is copied. 3 Return_Values x A pointer to the character following the character specified by c in the string pointed to by dest. NULL Indicates an error. The character c is not found after scanning n characters in the string. 2 memchr Locates the first occurrence of the specified byte within the initial size bytes of a given object. Format #include void *memchr (const void *s1, int c, size_t size); 3 Function_Variants This function also has variants named _memchr32 and _memchr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s1 A pointer to the object to be searched. c The byte value to be located. size The length of the object to be searched. If size is zero, memchr returns NULL. 3 Description Unlike strchr, the memchr function does not stop when it encounters a null character. 3 Return_Values pointer A pointer to the first occurrence of the byte. NULL Indicates that the specified byte does not occur in the object. 2 memcmp Compares two objects, byte by byte. The compare operation starts with the first byte in each object. Format #include int memcmp (const void *s1, const void *s2, size_t size); 3 Arguments s1 A pointer to the first object. s2 A pointer to the second object. size The length of the objects to be compared. If size is zero, the two objects are considered equal. 3 Description This function uses native byte comparison. The sign of the value returned is determined by the sign of the difference between the values of the first pair of unlike bytes in the objects being compared. Unlike the strcmp function, the memcmp function does not stop when a null character is encountered. 3 Return_Value x An integer less than, equal to, or greater than 0, depending on whether the lexical value of the first object is less than, equal to, or greater than that of the second object. 2 memcpy Copies a specified number of bytes from one object to another. Format #include void *memcpy (void *dest, const void *source, size_t size); 3 Function_Variants This function also has variants named _memcpy32 and _memcpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest A pointer to the destination object. source A pointer to the source object. size The length of the object to be copied. 3 Description This function copies size bytes from the object pointed to by source to the object pointed to by dest; it does not check for the overflow of the receiving memory area (dest). Unlike the strcpy function, the memcpy function does not stop when a null character is encountered. 3 Return_Value x The value of dest. 2 memmove Copies a specified number of bytes from one object to another. Format #include void *memmove (void *dest, const void *source, size_t size); 3 Function_Variants This function also has variants named _memmove32 and _memmove64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest A pointer to the destination object. source A pointer to the source object. size The length of the object to be copied. 3 Description In Compaq C for OpenVMS Systems, memmove and memcpy perform the same function. Programs that require portability should use memmove if the area pointed at by dest could overlap the area pointed at by source. 3 Return_Value x The value of dest. 3 Example #include #include main() { char pdest[14] = "hello there"; char *psource = "you are there"; memmove(pdest, psource, 7); printf("%s\n", pdest); } This example produces the following output: you are there 2 memset Sets a specified number of bytes in a given object to a given value. Format #include void *memset (void *s, int value, size_t size); 3 Function_Variants This function also has variants named _memset32 and _memset64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s An array pointer. value The value to be placed in s. size The number of bytes to be placed in s. 3 Description This function copies value (converted to an unsigned char) into each of the first size characters of the object pointed to by s. This function returns s. It does not check for the overflow of the receiving memory area pointed to by s. 3 Return_Value x The value of s. 2 mkdir Creates a directory. Format #include int mkdir (const char *dir_spec, mode_t mode); (ISO POSIX-1) int mkdir (const char *dir_spec, mode_t mode, . . . ); (DEC C Extension) 3 Arguments dir_spec A valid OpenVMS or UNIX style directory specification that may contain a device name. For example: DBA0:[BAY.WINDOWS] /* OpenVMS */ /dba0/bay/windows /* UNIX style */ This specification cannot contain a node name, file name, file extension, file version, or a wildcard character. The same restriction applies to the UNIX style directory specifications. mode A file protection. See the chmod function for information about the specific file protections. The file protection of the new directory is derived from the mode argument, the process's file protection mask (see the umask function), and the parent-directory default protections. In a manner consistent with the OpenVMS behavior for creating directories, mkdir never applies delete access to the directory. An application that needs to set delete access should use an explicit call to chmod to set write permission. See the Description section of this function for more information about how the file protection is set for the newly created directory. . . . Represents the following optional arguments. These arguments have fixed position in the argument list, and cannot be arbitrarily placed. unsigned int uic The user identification code (UIC) that identifies the owner of the created directory. If this argument is 0, the Compaq C RTL gives the created directory the UIC of the parent directory. If this argument is not specified, the Compaq C RTL gives the created directory your UIC. This optional argument is specific to the Compaq C RTL and is not portable. unsigned short max_versions The maximum number of file versions to be retained in the created directory. The system automatically purges the directory keeping, at most, max_versions number of every file. If this argument is 0, the Compaq C RTL does not place a limit on the maximum number of file versions. If this argument is not specified, the Compaq C RTL gives the created directory the default version limit of the parent directory. This optional argument is specific to the Compaq C RTL and is not portable. unsigned short r_v_number The volume (device) on which to place the created directory if the device is part of a volume set. If this argument is not specified, the Compaq C RTL arbitrarily places the created directory within the volume set. This optional argument is specific to the Compaq C RTL and is not portable. 3 Description If dir_spec specifies a path that includes directories, which do not exist, intermediate directories are also created. This differs from the behavior of the UNIX system where these intermediate directories must exist and will not be created. If you do not specify any optional arguments, the Compaq C RTL gives the directory your UIC and the default version limit of the parent directory, and arbitrarily places the directory within the volume set. You cannot get the default behavior for the uic or max_versions arguments if you specify any arguments after them. NOTE The way to create files with OpenVMS RMS default protections using the UNIX system-call functions umask, mkdir, creat, and open is to call mkdir, creat, and open with a file- protection mode argument of 0777 in a program that never specifically calls umask. These default protections include correctly establishing protections based on ACLs, previous versions of files, and so on. In programs that do vfork/exec calls, the new process image inherits whether umask has ever been called or not from the calling process image. The umask setting and whether the umask function has ever been called are both inherited attributes. The file protection supplied by the mode argument is modified by the process's file protection mask in such a way that the file protection for the new directory is set to the bitwise AND of the mode argument and the complement of the file protection mask. Default file protections are supplied to the new directory from the parent-directory such that if a protection value bit in the new directory is zero, then the value of this bit is inherited from the parent-directory. However, bits in the parent directory's file protection that indicate delete access do not cause corresponding bits to be set in the new directory's file protection. 3 Return_Values 0 Indicates success. -1 Indicates failure. 3 Examples 1.umask (0002); /* turn world write access off */ mkdir ("sys$disk:[.parentdir.childdir]", 0222); /* turn write access on */ Parent directory file protection: System:RWD, Owner:RWD, Group:R, World:R The file protection derived from the combination of the mode argument and the file protection mask set by umask is (0222) & ~(0002), which is 0220. When the parent directory defaults are applied to this protection, the protection for the new directory becomes: File protection: System:RWD, Owner:RWD, Group:RWD, World:R 2.umask (0000); mkdir ("sys$disk:[.parentdir.childdir]", 0444); /* turn read access on */ Parent directory file protection: System:RWD, Owner:RWD, Group:RWD, World:RWD The file protection derived from the combination of the mode argument and the file protection mask set by umask is (0444) & ~(0000) which is 0444. When the parent directory defaults are applied to this protection, the protection for the new directory is: File protection: System:RW, Owner:RW, Group:RW, World:RW Note that delete access is not inherited. 2 mkstemp Constructs a unique filename. Format #include int mkstemp (char *template); 3 Arguments template A pointer to a string that is replaced with a unique filename. The string in the template argument must be a filename with six trailing Xs. 3 Description This function replaces the six trailing Xs of the string pointed to by template with a unique set of characters, and returns a file descriptor for the file open for reading and writing. The string pointed to by template should look like a file name with six trailing X's. The mkstemp function replaces each X with a character from the portable file-name character set, making sure not to duplicate an existing file name. If the string pointed to by template does not contain six trailing Xs, -1 is returned. 3 Return_Values x An open file descriptor. -1 Indicates an error. (The string pointed to by template does not contain six trailing Xs.) 2 mktemp Creates a unique file name from a template. Format #include char *mktemp (char *template); 3 Function_Variants This function also has variants named _mktemp32 and _mktemp64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument template A pointer to a buffer containing a user-defined template. You supply the template in the form, namXXXXXX. The six trailing Xs are replaced by a unique series of characters. You may supply the first three characters. Because the template argument is overwritten, do not specify a string literal (const object). 3 Description The use of mktemp is not recommended for new applications. See the tmpnam and mkstemp functions for the preferable alternatives. 3 Return_Value x A pointer to the template, with the template modified to contain the created file name. If this value is a pointer to a null string, it indicates that a unique file name cannot be created. 2 mktime Converts a local-time structure into time since the Epoch. Format #include time_t mktime (struct tm *timeptr); 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Argument timeptr A pointer to the local time structure. 3 Description This function converts the local-time structure, pointed to by timeptr, to a time in seconds since the Epoch in the same manner as the values returned by the time function. If the local time cannot be encoded, then mktime returns the value (time_t)(-1). The time_t type is defined in the header file as follows: typedef unsigned long int time_t; Local time-zone information is set as if mktime called tzset. If the tm_isdst field in the local-time structure pointed to by timeptr is positive, mktime initially presumes that Daylight Savings Time (DST) is in effect for the specified time. If tm_isdst is 0, mktime initially presumes that DST is not in effect. If tm_isdst is negative, mktime attempts to determine whether or not DST is in effect for the specified time. 3 Return_Values x The specified calendar time encoded as a value of type time_t. (time_t)(-1) If the local time cannot be encoded. Be aware that a return value of (time_t)(-1) can also represent the valid date: Sun Feb 7 06:28:15 2106. 2 mmap Maps file system object into virtual memory. Format #include #include void mmap (void *addr, size_t len, int prot, int flags, int filedes, off_t off); (X/Open, POSIX-1) void mmap (void *addr, size_t len, int prot, int flags, int filedes, off_t off ...); (DEC C Extension) 3 Function_Variants This function also has variants named _mmap32 and _mmap64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments addr The starting address of the new region (truncated to a page boundary). len The length in bytes of the new region (rounded up to a page boundary). prot Access permission, as defined in the header file. Specify either PROT_NONE, PROT_READ, or PROT_WRITE. flags Attributes of the mapped region as the results of a bitwise- inclusive OR operation on any combination of the following: o MAP_FILE or MAP_ANONYMOUS o MAP_VARIABLE or MAP_FIXED o MAP_SHARED or MAP_PRIVATE filedes The file that you want to map to the new mapped file region returned by the open function. off The offset, specified in bytes. The off_t data type is either a 64-bit integer or a 32-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE . . . An optional integer specifying additional flags for the SYS$CRMPSC system service for MAP_SHARED. This optional argument (Compaq C Extension) of the mmap function was introduced in OpenVMS Version 7.2. 3 Description This function creates a new mapped file region, a new private region, or a new shared memory region. Your application must ensure correct synchronization when using mmap in conjunction with any other file access method, such as read and write, and standard input/output. Before calling mmap, the calling application must also ensure that all bytes in the range [off, off+len] are written to the file (using the fsync function, for example). If this requirement is not met, mmap fails with errno set to ENXIO (No such device or address). The addr and len arguments specify the requested starting address and length in bytes for the new region. The address is a multiple of the page size returned by sysconf(_SC_PAGE_SIZE). If the len argument is not a multiple of the page size returned by sysconf(_SC_PAGE_SIZE), then the result of any reference to an address between the end of the region and the end of the page containing the end of the region is undefined. The flags argument specifies attributes of the mapped region. Values for flags are constructed by a bitwise-inclusive OR operation on the flags from the following list of symbolic names defined in the header file: MAP_FILE Create a mapped file region. MAP_ Create an unnamed memory region. ANONYMOUS MAP_VARIABLE Place region at the computed address. MAP_FIXED Place region at fixed address. MAP_SHARED Share changes. MAP_PRIVATE Changes are private. The MAP_FILE and MAP_ANONYMOUS flags control whether the region you want to map is a mapped file region or an anonymous shared memory region. One of these flags must be selected. If MAP_FILE is set in the flags argument: o A new mapped file region is created, mapping the file associated with the filedes argument. o The off argument specifies the file byte offset where the mapping starts. This offset must be a multiple of the page size returned by sysconf(_SC_PAGE_SIZE). o If the end of the mapped file region is beyond the end of the file, the result of any reference to an address in the mapped file region corresponding to an offset beyond the end of the file is unspecified. If MAP_ANONYMOUS is set in the flags argument: o A new memory region is created and initialized to all zeros. o If the filedes argument is not -1, the mmap function fails. The new region is placed at the requested address if the requested address is not null and it is possible to place the region at this address. When the requested address is null or the region cannot be placed at the requested address, the MAP_ VARIABLE and MAP_FIXED flags control the placement of the region. One of these flags must be selected. If MAP_VARIABLE is set in the flags argument: o If the requested address is null or if it is not possible for the system to place the region at the requested address, the region is placed at an address selected by the system. If MAP_FIXED is set in the flags argument: o If the requested address is not null, the mmap function succeeds even if the requested address is already part of another region. (If the address is within an existing region, the effect on the pages within that region and within the area of the overlap produced by the two regions is the same as if they were unmapped. In other words, whatever is mapped between addr and addr + len is unmapped.) o If the requested address is null and MAP_FIXED is specified, the results are undefined. The MAP_PRIVATE and MAP_SHARED flags control the visibility of modifications to the mapped file or shared memory region. One of these flags must be selected. If MAP_SHARED is set in the flags argument: o If the region is a mapped region, modifications to the region are visible to other processes that mapped the same region using MAP_SHARED. o If the region is a mapped file region, modifications to the region are written to the file. (Note that the modifications are not immediately written to the file because of buffer cache delay; that is, the write to the file does not occur until there is a need to reuse the buffer cache. If the modifications must be written to the file immediately, use the msync function to ensure that this is done.) If MAP_PRIVATE is set in the flags argument: o Modifications to the mapped region by the calling process are not visible to other processes that mapped the same region using either MAP_PRIVATE or MAP_SHARED. o Modifications to the mapped region by the calling process are not written to the file. It is unspecified whether modifications by processes that mapped the region using MAP_SHARED are visible to other processes that mapped the same region using MAP_PRIVATE. The prot argument specifies access permissions for the mapped region. Specify one of the following: PROT_NONE No access PROT_READ Read-only PROT_WRITE Read/Write access After the successful completion of the mmap function, you can close the filedes argument without effect on the mapped region or on the contents of the mapped file. Each mapped region creates a file reference, similar to an open file descriptor, that prevents the file data from being deallocated. NOTE The following rules apply to OpenVMS specific file references: o Because of the additional file reference, if filedes is not opened for file sharing, mmap reopens it with file sharing enabled. o The additional file reference that remains for mapped regions implies that a later open, fopen, or create call to the file that is mapped must specify file sharing. Modifications made to the file using the write function are visible to mapped regions, and modifications to a mapped region are visible with the read function. NOTE Beginning with OpenVMS Version 7.2, while processing a MAP_ SHARED request, the mmap function constructs the flags argument of the SYS$CRMPSC service as a bitwise inclusive OR of those bits it sets by itself to fulfill the MAP_ SHARED request and those bits specified by the caller in the optional argument. By default, for MAP_SHARED the mmap function creates a temporary group global section. The optional mmap argument provides the caller with direct access to the features of the SYS$CRMPSC system service. Using the optional argument, the caller can create, for example, a system global section (SEC$M_SYSGBL bit) or permanent global section (SEC$M_PERM bit). For example, to create a system permanent global section, the caller can specify (SEC$M_SYSGBL | SEC$M_PERM) in the optional argument. The mmap function does not check or set any privileges. So it is the responsibility of the caller to set appropriate privileges, such as SYSGBL privilege for SEC$M_SYSGBL, and PRMGBL for SEC$M_PERM, before calling mmap with the optional argument. See also read, write, open, fopen, creat, and sysconf. 3 Return_Values x The address where the mapping is placed. MAP_FAILED Indicates an error; errno is set to one of the following values: o EACCES - The file referred to by filedes is not open for read access, or the file is not open for write access and PROT_WRITE was set for a MAP_SHARED mapping operation. o EBADF - The filedes argument is not a valid file descriptor. o EINVAL -The flags or prot argument is invalid, or the addr argument or off argument is not a multiple of the page size returned by sysconf(_SC_PAGE_SIZE). Or MAP_ANONYMOUS was specified in flags and filedes is not -1. o ENODEV - The file descriptor filedes refers to an object that cannot be mapped, such as a terminal. o ENOMEM - There is not enough address space to map len bytes. o ENXIO - The addresses specified by the range [off, off + len] are invalid for filedes. o EFAULT - The addr argument is an invalid address. 2 modf Decomposes a floating-point number. Format #include double modf (double x, double *iptr); float modff (float x, float *iptr); (Alpha only) long double modfl (long double x, long double *iptr); (Alpha only) 3 Arguments x An object of type double, float, or long double. iptr A pointer to an object of type double, float, or long double, to match the type of x. 3 Description The modf functions decompose their first argument x into a positive fractional part f and an integer part i, each of which has the same sign as x. The functions return f and assign i to the object pointed to by the second argument (iptr). 3 Return_Values x The fractional part of the argument x. NaN x is NaN; errno is set to EDOM and *iptr is set to NaN. 0 Underflow occurred; errno is set to ERANGE. 2 [w]move Change the current cursor position on the specified window to the coordinates (y,x). The move function acts on the stdscr window. Format #include int move (int y, int x); int wmove (WINDOW *win, int y, int x); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. 3 Description For more information, see the scrollok function. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. 2 mprotect Modifies access protections of memory mapping. Format #include int mprotect (void *addr, size_t len, int prot); 3 Arguments addr The address of the region that you want to modify. len The length in bytes of the region that you want to modify. prot Access permission, as defined in the header file. Specify either PROT_NONE, PROT_READ, or PROT_WRITE. 3 Description This function modifies the access protection of a mapped file or shared memory region. The addr and len arguments specify the address and length in bytes of the region that you want to modify. The len argument must be a multiple of the page size as returned by sysconf(_SC_ PAGE_SIZE). If len is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE), the length of the region is rounded up to the next multiple of the page size. The prot argument specifies access permissions for the mapped region. Specify one of the following: PROT_NONE No access PROT_READ Read-only PROT_WRITE Read/Write access The mprotect function does not modify the access permission of any region that lies outside of the specified region, except that the effect on addresses between the end of the region, and the end of the page containing the end of the region, is unspecified. If the mprotect function fails under a condition other than that specified by EINVAL, the access protection of some of the pages in the range [addr, addr + len] can change. Suppose the error occurs on some page at an addr2; mprotect can modify protections of all whole pages in the range [addr, addr2]. See also sysconf. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EACCESS - The prot argument specifies a protection that conflicts with the access permission set for the underlying file. o EINVAL - The prot argument is invalid, or the addr argument is not a multiple of the page size as returned by sysconf(_SC_PAGE_ SIZE). o EFAULT - The range [addr, addr + len] includes an invalid address. 2 mrand48 Generates uniformly distributed pseudorandom number sequences. Returns 48-bit signed long integers. Format #include long int mrand48 (void); 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. It returns signed long integers uniformly distributed over the range of y values such that -231 Before you call the mrand48 function, use either srand48, seed48, or lcong48 to initialize the random number generator. You must initialize the mrand48 function prior to invoking it, because it stores the last 48-bit Xi generated into an internal buffer. (Although it is not recommended, constant default initializer values are supplied automatically if the drand48, lrand48, or mrand48 functions are called without first calling an initialization function.) The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The values returned by the mrand48 function is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate bits, according to the type of returned data item, are copied from the high-order (most significant) bits of Xi and transformed into the returned value. See also drand48, lrand48, lcong48, seed48, and srand48. 3 Return_Values n Returns signed long integers uniformly distributed over the range -231 2 msync Synchronizes a mapped file. Format #include int msync (void *addr, size_t len, int flags); 3 Arguments addr The address of the region that you want to synchronize. len The length in bytes of the region that you want to synchronize. flags One of the following symbolic constants defined in the header file: MS_SYNC Synchronous cache flush MS_ASYNC Asynchronous cache flush MS_ Invalidate cashed pages INVALIDATE 3 Description This function controls the caching operations of a mapped file region. Use msync to: o Ensure that modified pages in the region transfer to the underlying storage device of the file. o Control the visibility of modifications with respect to file system operations. The addr and len arguments specify the region to be synchronized. The len argument must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE); otherwise, the length of the region is rounded up to the next multiple of the page size. If the flags argument is set to: flags Argument Then the msync Function... MS_SYNC Does not return until the system completes all I/O operations. MS_ASYNC Returns after the system schedules all I/O operations. MS_INVALIDATE Invalidates all cached copies of the pages. The operating system must obtain new copies of the pages from the file system the next time the application references them. After a successful call to the msync function with the flags argument set to: o MS_SYNC - All previous modifications to the mapped region are visible to processes using the read argument. Previous modifications to the file using the write function are lost. o MS_INVALIDATE - All previous modifications to the file using the write function are visible to the mapped region. Previous direct modifications to the mapped region are lost. See also read, write, and sysconf. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EIO - An I/O error occurred while reading from or writing to the file system. o ENOMEM - The range specified by [addr, addr + len] is invalid for a process' address space, or the range specifies one or more unmapped pages. o EINVAL - The addr argument is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). o EFAULT - The range [addr, addr + len] includes an invalid address. 2 munmap Unmaps a mapped region. Format #include int munmap (void *addr, size_t len); 3 Arguments addr The address of the region that you want to unmap. len The length in bytes of that region the you want to unmap. 3 Description This function unmaps a mapped file or shared memory region. The addr and len arguments specify the address and length in bytes, respectively, of the region to be unmapped. The len argument must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE); otherwise, the length of the region is rounded up to the next multiple of the page size. The result of using an address that lies in an unmapped region and not in any subsequently mapped region is undefined. See also sysconf. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o ENIVAL - The addr argument is not a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE). o EFAULT - The range [addr, addr + len] includes an invalid address. 2 mv[w]addch Move the cursor to coordinates (y,x) and add a character to the specified window. Format #include int mvaddch (int y, int x, char ch); int mvwaddch (WINDOW *win, int y, int x, char ch); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. ch If this argument is a new-line character (\n), the mvaddch and mvwaddch functions clear the line to the end, and move the cursor to the next line at the same x coordinate. A carriage return (\r) moves the cursor to the beginning of the specified line. A tab (\t) moves the cursor to the next tabstop within the window. 3 Description This routine performs the same function as mvwaddch, but on the stdscr window. When mvwaddch is used on a subwindow, it writes the character onto the underlying window as well. 3 Return_Values OK Indicates success. ERR Indicates that writing the character would cause the screen to scroll illegally. For more information, see the scrollok function. 2 mv[w]addstr Move the cursor to coordinates (y,x) and add the specified string, to which str points, to the specified window. Format #include int mvaddstr (int y, int x, char *str); int mvwaddstr (WINDOW *win, int y, int x, char *str); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. str A pointer to the character string. 3 Description This routine performs the same function as mvwaddstr, but on the stdscr window. When mvwaddstr is used on a subwindow, the string is written onto the underlying window as well. 3 Return_Values OK Indicates success. ERR Indicates that the function causes the screen to scroll illegally, but it places as much of the string onto the window as possible. For more information, see the scrollok function. 2 mvcur Moves the terminal's cursor from (lasty,lastx) to (newy,newx). Format #include int mvcur (int lasty, int lastx, int newy, int newx); 3 Arguments lasty The cursor position. lastx The cursor position. newy The resulting cursor position. newx The resulting cursor position. 3 Description In Compaq C for OpenVMS Systems, mvcur and move perform the same function. See also move. 3 Return_Values OK Indicates success. ERR Indicates that moving the window put part or all of the window off the edge of the terminal screen. The terminal screen remains unaltered. 2 mv[w]delch Move the cursor to coordinates (y,x) and delete the character on the specified window. The mvdelch function acts on the stdscr window. Format #include int mvdelch (int y, int x); int mvwdelch (WINDOW *win, int y, int x); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. 3 Description Each of the following characters on the same line shifts to the left, and the last character becomes blank. 3 Return_Values OK Indicates success. ERR Indicates that deleting the character would cause the screen to scroll illegally. For more information, see the scrollok function. 2 mv[w]getch Move the cursor to coordinates (y,x), get a character from the terminal screen, and echo it on the specified window. The mvgetch function acts on the stdscr window. Format #include int mvgetch (int y, int x); int mvwgetch (WINDOW *win, int y, int x); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. 3 Description The mvgetch and mvwgetch functions refresh the specified window before fetching the character. 3 Return_Values x The returned character. ERR Indicates that the function causes the screen to scroll illegally. For more information, see the scrollok function. 2 mv[w]getstr Move the cursor to coordinates (y,x), get a string from the terminal screen, store it in the variable str which must be large enough to contain the string, and echo it on the specified window. The mvgetstr function acts on the stdscr window. Format #include int mvgetstr (int y, int x, char *str); int mvwgetstr (WINDOW *win, int y, int x, char *str); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. str The string that is displayed. 3 Description The mvgetstr and mvwgetstr functions strip the new-line terminator (\n) from the string. 3 Return_Values OK Indicates success. ERR Indicates that the function causes the screen to scroll illegally. 2 mv[w]inch Move the cursor to coordinates (y,x) and return the character on the specified window without making changes to the window. The mvinch function acts on the stdscr window. Format #include int mvinch (int y, int x); int mvwinch (WINDOW *win, int y, int x); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. 3 Return_Values x The returned character. ERR Indicates an input error. 2 mv[w]insch Move the cursor to coordinates (y,x) and insert the character ch into the specified window. The mvinsch function acts on the stdscr window. Format #include int mvinsch (int y, int x, char ch); int mvwinsch (WINDOW *win, int y, int x, char ch); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. ch The character to be inserted at the window's coordinates. 3 Description After the character is inserted, each character on the line shifts to the right, and the last character on the line is deleted. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. For more information, see the scrollok function. 2 mv[w]insstr Move the cursor to coordinates (y,x) and insert the specified string into the specified window. The mvinsstr function acts on the stdscr window. Format #include int mvinsstr (int y, int x, char *str); int mvwinsstr (WINDOW *win, int y, int x, char *str); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. str The string that is displayed. 3 Description Each character after the string shifts to the right, and the last character disappears. The mvinsstr and mvwinsstr functions are specific to Compaq C for OpenVMS Systems and are not portable. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally. For more information, see the scrollok function. 2 mvwin Moves the starting position of the window to the specified (y,x) coordinates. Format #include mvwin (WINDOW *win, int y, int x); 3 Arguments win A pointer to the window. y A window coordinate. x A window coordinate. 3 Description When moving subwindows, the mvwin function does not rewrite the contents of the subwindow on the underlying window at the new position. If you write anything to the subwindow after the move, the function also writes to the underlying window. 3 Return_Values OK Indicates success. ERR Indicates that moving the window put part or all of the window off the edge of the terminal screen. The terminal screen remains unaltered. 2 newwin Creates a new window with numlines lines and numcols columns starting at the coordinates (begin_y,begin_x) on the terminal screen. Format #include WINDOW *newwin (int numlines, int numcols, int begin_y, int begin_x); 3 Arguments numlines If it is 0, the newwin function sets that dimension to LINES (begin_y). To get a new window of dimensions LINES by COLS, use the following line: newwin (0, 0, 0, 0) numcols If it is 0, the newwin function sets that dimension to COLS (begin_x). Thus, to get a new window of dimensions LINES by COLS, use the following line: newwin (0, 0, 0, 0) begin_y A window coordinate. begin_x A window coordinate. 3 Return_Values x The address of the allocated window. ERR Indicates an error. 2 nextafter Returns the next machine-representable number following x in the direction of y. This function is OpenVMS Alpha only. Format #include double nextafter (double x, double y); float nextafterf (float x, float y); long double nextafterl (long double x, long double y); 3 Argument x A real number. y A real number. 3 Description The nextafter functions return the next machine-representable floating-point number following x in the direction of y. If y is less than x, nextafter returns the largest representable floating-point number less than x. 3 Return_Values x The next representable floating-point value following x in the direction of y. HUGE_VAL Overflow; errno is set to ERANGE. NaN x or y is NaN; errno is set to EDOM. 2 nice Increases or decreases process priority relative to the process current priority by the amount of the argument. This function is nonreentrant. Format #include int nice (int increment); 3 Argument increment As a positive argument, decreases priority; as a negative argument, increases priority. Issuing nice(0) restores the base priority. The resulting priority cannot be less than 1, or greater than the process's base priority. If it is, the nice function quietly does nothing. 3 Description When a process calls the vfork function, the resulting child inherits the parent's priority. See also vfork. 3 Return_Values 0 Indicates success. -1 Indicates failure. 2 nint Returns the nearest integral value to the argument. This function is OpenVMS Alpha only. Format #include double nint (double x); float nintf (float x,); long double nintl (long double x); 3 Argument x A real number. 3 Description The nint functions return the nearest integral value to x, except halfway cases are rounded to the integral value larger in magnitude. This corresponds to the FORTRAN generic intrinsic function nint. 3 Return_Values n The nearest integral value to x. NaN x is NaN; errno is set to EDOM. 2 [no]nl The nl and nonl functions are provided only for UNIX software compatibility and have no function in the OpenVMS environment. Format #include void nl (void); void nonl (void); 2 nl_langinfo Returns a pointer to a string that contains information obtained from the program's current locale. Format #include char *nl_langinfo (nl_item item); 3 Arguments item The name of a constant that specifies the information required. These constants are defined in . The following constants are valid: Constant Category Description D_T_FMT LC_TIME String for formatting date and time D_FMT LC_TIME String for formatting date T_FMT LC_TIME String for formatting time T_FMT_AMPM LC_TIME Time format with AM/PM string AM_STR LC_TIME String that represents AM in 12-hour clock notation PM_STR LC_TIME String that represents PM in 12-hour clock notation DAY_1 LC_TIME The name of the first day of the week . . . DAY_7 LC_TIME The name of the seventh day of the week ABDAY_1 LC_TIME The abbreviated name of the first day of the week . . . ABDAY_7 LC_TIME The abbreviated name of the seventh day of the week MON_1 LC_TIME The name of the first month in the year . . . MON_12 LC_TIME The name of the twelfth month in the year ABMON_1 LC_TIME The abbreviated name of the first month in the year . . . ABMON_12 LC_TIME The abbreviated name of the twelfth month in the year ERA LC_TIME Era description strings ERA_D_FMT LC_TIME Era date format string ERA_T_FMT LC_TIME Era time format ERA_D_T_FMT LC_TIME Era date and time format ALT_DIGITS LC_TIME Alternative symbols for digits RADIXCHAR LC_NUMERIC The radix character THOUSEP LC_NUMERIC The character used to separate groups of digits in non-monetary values YESEXP LC_MESSAGES The expression for affirmative responses to yes/no questions NOEXP LC_MESSAGES The expression for negative responses to yes/no questions CRNCYSTR LC_MONETARY The currency symbol. It is preceded by one of the following: o A minus (-) if the symbol is to appear before the value o A plus (+) if the symbol is to appear after the value o A period (.) if the symbol replaces the radix character CODESET LC_CTYPE Codeset name 3 Description If the current locale does not have language information defined, the function returns information from the C locale. The program should not modify the string returned by the function. This string might be overwritten by subsequent calls to nl_langinfo. If the setlocale function is called after a call to nl_langinfo, then the pointer returned by the previous call to nl_langinfo will be unspecified. In this case, the nl_langinfo function should be called again. 3 Return_Values x Pointer to the string containing the requested information. If item is invalid, the function returns an empty string. 3 Example #include #include #include /* This test sets up the British English locale, and then */ /* inquires on the data and time format, first day of the week, */ /* and abbreviated first day of the week. */ #include #include int main() { char *return_val; char *nl_ptr; /* set the locale, with user supplied locale name */ return_val = setlocale(LC_ALL, "en_gb.iso8859-1"); if (return_val == NULL) { printf("ERROR : The locale is unknown"); exit(1); } printf("+-----------------------------------------------+\n"); /* Get the date and time format from the locale. */ printf("D_T_FMT = "); /* Compare the returned string from nl_langinfo with */ /* an empty string. */ if (!strcmp((nl_ptr = (char *) nl_langinfo(D_T_FMT)), "")) { /* The string returned was empty this could mean that either */ /* 1) The locale does not contain a value for this item */ /* 2) The value for this item is an empty string */ printf("nl_langinfo returned an empty string\n"); } else { /* Display the date and time format */ printf("%s\n", nl_ptr); } /* Get the full name for the first day of the week from locale */ printf("DAY_1 = "); /* Compare the returned string from nl_langinfo with */ /* an empty string. */ if (!strcmp((nl_ptr = (char *) nl_langinfo(DAY_1)), "")) { /* The string returned was empty this could mean that either */ /* 1) The locale does not contain a value for the first */ /* day of the week */ /* 2) The value for the first day of the week is */ /* an empty string */ printf("nl_langinfo returned an empty string\n"); } else { /* Display the full name of the first day of the week */ printf("%s\n", nl_ptr); } /* Get the abbreviated name for the first day */ /* of the week from locale. */ printf("ABDAY_1 = "); /* Compare the returned string from nl_langinfo */ /* with an empty string. */ if (!strcmp((nl_ptr = (char *) nl_langinfo(ABDAY_1)), "")) { /* The string returned was empty this could mean that either */ /* 1) The locale does not contain a value for the first */ /* day of the week */ /* 2) The value for the first day of the week is an */ /* empty string */ printf("nl_langinfo returned an empty string\n"); } else { /* Display the abbreviated name of the first day of the week */ printf("%s\n", nl_ptr); } } Running the example program produces the following result: +-----------------------------------------------+ D_T_FMT = %a %e %b %H:%M:%S %Y DAY_1 = Sunday ABDAY_1 = Sun 2 nrand48 Generates uniformly distributed pseudorandom number sequences. Returns 48-bit signed long integers. Format #include long int nrand48 (unsigned short int xsubi[3]); 3 Arguments xsubi An array of three short int that, when concatentated together, form a 48-bit integer. 3 Description This function generates pseudorandom numbers using the linear congruential algorithm and 48-bit integer arithmetic. The nrand48 function returns nonnegative, long integers uniformly distributed over the range of y values, such that 0 The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The nrand48 function requires that the calling program pass an array as the xsubi argument, which for the first call must be initialized to the initial value of the pseudorandom number sequence. Unlike the drand48 function, it is not necessary to call an initialization function prior to the first call. By using different arguments, the nrand48 function allows separate modules of a large program to generate several independent sequences of pseudorandom numbers. For example, the sequence of numbers that one module generates does not depend upon how many times the functions are called by other modules. 3 Return_Values n Returns nonnegative, long integers over the range 0 2 open Opens a file for reading, writing, or editing. It positions the file at its beginning (byte 0). Format #include int open (const char *file_spec, int flags, mode_t mode); (ANSI C) int open (const char *file_spec, int flags, . . . ); (DEC C Extension) 3 Arguments file_spec A null-terminated character string containing a valid file specification. If you specify a directory in the file_spec and it is a search list that contains an error, Compaq C interprets it as a file open error. flags The following values are defined in the header file: O_RDONLY Open for reading only O_WRONLY Open for writing only O_RDWR Open for reading and writing O_NDELAY Open for asynchronous input O_APPEND Append on each write O_CREAT Create a file if it does not exist O_TRUNC Create a new version of this file O_EXCL Error if attempting to create existing file These flags are set using the bitwise OR operator (|) to separate specified flags. Opening a file with O_APPEND causes each write on the file to be appended to the end. (In contrast, with the VAX C RTL the behavior of files opened in append mode was to start at EOF and, thereafter, write at the current file position.) If O_TRUNC is specified and the file exists, open creates a new file by incrementing the version number by 1, leaving the old version in existence. If O_CREAT is set and the named file does not exist, the Compaq C RTL creates it with any attributes specified in the fourth and subsequent arguments ( . . . ). If O_EXCL is set with O_CREAT and the named file exists, the attempted open returns an error. mode An unsigned value that specifies the file-protection mode. The compiler performs a bitwise AND operation on the mode and the complement of the current protection mode. You can construct modes by using the bitwise OR operator (|) to separate specified modes. The modes are: 0400 OWNER:READ 0200 OWNER:WRITE 0100 OWNER:EXECUTE 0040 GROUP:READ 0020 GROUP:WRITE 0010 GROUP:EXECUTE 0004 WORLD:READ 0002 WORLD:WRITE 0001 WORLD:EXECUTE The system is given the same access privileges as the owner. A WRITE privilege also implies a DELETE privilege. . . . Optional file attribute arguments. The file attribute arguments are the same as those used in the creat function. For more information, see the creat function. 3 Description If a version of the file exists, a new file created with open inherits certain attributes from the existing file unless those attributes are specified in the open call. The following attributes are inherited: record format, maximum record size, carriage control, and file protection. NOTES o If you intend to do random writing to a file, the file must be opened for update by specifying a flags value of O_RDWR. o To create files with OpenVMS RMS default protections by using the UNIX system-call functions umask, mkdir, creat, and open, call mkdir, creat, and open with a file-protection mode argument of 0777 in a program that never specifically calls umask. These default protections include correctly establishing protections based on ACLs, previous versions of files, and so on. In programs that do vfork/exec calls, the new process image inherits whether umask has ever been called or not from the calling process image. The umask setting and whether the umask function has ever been called are both inherited attributes. See also creat, read, write, close, dup, dup2, and lseek. 3 Return_Values x A nonnegative file descriptor number. -1 Indicates that the file does not exist, that it is protected against reading or writing, or that it cannot be opened for another reason. 3 Example #include #include #include main() { int file, stat; int flags; flags = O_RDWR; /* Open for read and write, with user */ /* with default file protection, with */ /* max fixed record size of 2048, and */ /* a block size of 2048 bytes. */ file = open("file.dat", flags, 0, "rfm=fix", "mrs=2048", "bls=2048"); if (file == -1) perror("OPEN error"), exit(1); close(file); } 2 opendir Opens a specified directory. Format #include DIR *opendir (const char *dir_name); 3 Arguments dir_name The name of the directory to be opened. 3 Description This function opens the directory specifed by dir_name and associates a directory stream with it. The directory stream is positioned at the first entry. The type DIR, defined in the header file, represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. The opendir function also returns a pointer to identify the directory stream in subsequent operations. The NULL pointer is returned when the directory named by dir_name cannot be accessed, or when not enough memory is available to hold the entire stream. NOTE An open directory must always be closed with the closedir function to ensure that the next attempt to open that directory is successful. The opendir function should be used with readdir, closedir, and rewinddir to examine the contents of the directory. 3 Example See the program example in the description of closedir. 3 Return_Values x A pointer to an object of type DIR. NULL Indicates an error; errno is set to one of the following values: o EACCES - Search permission is denied for any component of dir_name or read permission is denied for dir_name. o ENAMETOOLONG - The length of the dir_name string exceeds PATH_MAX, or a pathname component is longer than NAME_MAX. o ENOENT - The dir_name argument points to the name of a file that does not exist, or is an empty string. 2 overlay Nondestructively superimposes win1 on win2. The function writes the contents of win1 that will fit onto win2 beginning at the starting coordinates of both windows. Blanks on win1 leave the contents of the corresponding space on win2 unaltered. The overlay function copies as much of a window's box as possible. Format #include int overlay (WINDOW *win1, WINDOW *win2); 3 Arguments win1 A pointer to the window. win2 A pointer to the window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 overwrite Destructively writes the contents of win1 on win2. Format #include int overwrite (WINDOW *win1, WINDOW *win2); 3 Arguments win1 A pointer to the window. win2 A pointer to the window. 3 Description This function writes the contents of win1 that will fit onto win2 beginning at the starting coordinates of both windows. Blanks on win1 are written on win2 as blanks. This function copies as much of a window's box as possible. 3 Return_Values OK Indicates success. ERR Indicates failure. 2 pathconf Retrieves file implementation characteristics. Format #include long int pathconf (const char *path, int name); 3 Arguments path The pathname of a file or directory. name The configuration attribute to query. If this attribute is not applicable to the file specified by the path argument, the pathconf function returns an error. 3 Description This function allows an application to determine the characteristics of operations supported by the file system underlying the file named by path. Read, write, or execute permission of the named file is not required, but you must be able to search all directories in the path leading to the file. Symbolic values for the name argument are defined in the header file, as follows: _PC_LINK_MAX The maximum number of links to the file. If the path argument refers to a directory, the value returned applies to the directory itself. _PC_MAX_ The maximum number of bytes in a canonical input CANON line. This is applicable only to terminal devices. _PC_MAX_ The number of types allowed in an input queue. INPUT This is applicable only to terminal devices. _PC_NAME_MAX Maximum number of bytes in a filename (not including a terminating null). The byte range value is between 13 and 255. This is applicable only to a directory file. The value returned applies to filenames within the directory. _PC_PATH_MAX Maximum number of bytes in a pathname (not including a terminating null). The value is never larger than 65,535. This is applicable only to a directory file. The value returned is the maximum length of a relative pathname when the specified directory is the working directory. _PC_PIPE_BUF Maximum number of bytes guaranteed to be written atomically. This is applicable only to a FIFO. The value returned applies to the referenced object. If the path argument refers to a directory, the value returned applies to any FIFO that exists or can be created within the directory. _PC_CHOWN_ This is applicable only to a directory file. The RESTRICTED value returned applies to any files (other than directories) that exist or can be created within the directory. _PC_NO_TRUNC Returns 1 if supplying a component name longer than allowed by NAME_MAX causes an error. Returns 0 (zero) if long component names are truncated. This is applicable only to a directory file. _PC_VDISABLE This is always 0 (zero); no disabling character is defined. This is applicable only to a terminal device. 3 Return_Values x Resultant value of the configuration attribute specified in name. -1 Indicates an error; errno is set to one of the following values: o EACCES - Search permission is denied for a component of the path prefix. o EINVAL - The name argument specifies an unknown or inapplicable characteristic. o EFAULT - The path argument is an invalid address. o ENAMETOOLONG - The length of the path string exceeds PATH_MAX or a pathname component is longer than NAME_MAX. o ENOENT - The named file does not exist or the path argument points to an empty string. o ENOTDI - A component of the path prefix is not a directory. 2 pause Suspends the calling process until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. Format #include int pause (void); 3 Description This function suspends the calling process until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. If the action is to terminate the process, pause does not return. If the action is to execute a signal-catching function, pause returns after the signal-catching function returns. 3 Return_Value Since the pause function suspends process execution indefinitely unless interrupted by a signal, there is no successful completion return value. -1 In cases where pause returns, the return value is -1, and errno is set to EINTR. 2 pclose Closes a pipe to a process. Format #include int pclose (FILE *stream); 3 Arguments stream A pointer to a FILE structure for an open pipe returned by a previous call to the popen function. 3 Description This function closes a pipe between the calling program and a shell command to be executed. Use pclose to close any stream you have opened with popen. The pclose function waits for the associated process to end, and then returns the exit status of the command. See the description of waitpid for information on interpreting the exit status. Beginning with OpenVMS Version 7.3-1, when compiled with the _VMS_WAIT macro defined, the pclose function returns the OpenVMS completion code of the child process. See also popen. 3 Return_Values x Exit status of child. -1 Indicates an error. The stream argument is not associated with a popen function. errno is set to one of the following: o ECHILD - cannot obtain the status of the child process. 2 perror Writes a short error message to stderr describing the current value of errno. Format #include void perror (const char *str); 3 Argument str Usually the name of the program that caused the error. 3 Description This function uses the error number in the external variable errno to retrieve the appropriate locale-dependent error message. The function writes out the message as follows: str (a user- supplied prefix to the error message), followed by a colon and a space, followed by the message itself, followed by a new-line character. See also strerror. 3 Example #include #include main(argc, argv) int argc; char *argv[]; { FILE *fp; fp = fopen(argv[1], "r"); /* Open an input file. */ if (fp == NULL) { /* If the fopen call failed, perror prints out a */ /* diagnostic: */ /* */ /* "open: " */ /* This error message provides a diagnostic explaining */ /* the cause of the failure. */ perror("open"); exit(EXIT_FAILURE); } else fclose(fd) ; } 2 pipe Creates a temporary mailbox that can be used to read and write data between a parent and child process. The channels through which the processes communicate are called a pipe. Format #include int pipe (int array_fdscptr[2]); (ISO POSIX-1) int pipe (int array_fdscptr[2], . . . ); (DEC C Extension) 3 Arguments array_fdscptr An array of file descriptors. A pipe is implemented as an array of file descriptors associated with a mailbox. These mailbox descriptors are special in that these are the only file descriptors which, when passed to the isapipe function, will return 1. The file descriptors are allocated in the following way: o The first available file descriptor is assigned to writing, and the next available file descriptor is assigned to reading. o The file descriptors are then placed in the array in reverse order; element 0 contains the file descriptor for reading, and element 1 contains the file descriptor for writing. . . . Represents two optional, positional arguments, flag and bufsize, which follow: flag An optional argument used as a bitmask. If either the O_NDELAY or O_NONBLOCK bit is set, the I/O operations to the mailbox through array_fdscptr file descriptors terminate immediately, rather than waiting for another process. If, for example, the O_NDELAY bit is set and the child issues a read request to the mailbox before the parent has put any data into it, the read terminates immediately with zero status. If neither the O_NDELAY nor O_NONBLOCK bit is set, the child will be waiting on the read until the parent writes any data into the mailbox. This is the default behavior if no flag argument is specified. The values of O_NDELAY and O_NONBLOCK are defined in the header file. Any other bits in the flag argument are ignored. You must specify this argument if the second optional, positional argument bufsize is specified. If the flag argument is needed only to allow specification of the bufsize argument, specify flag as zero. bufsize Optional argument of type int that specifies the size of the mailbox, in bytes. If you do not specify this argument, Compaq C for OpenVMS Systems creates a mailbox with a default size of 512 bytes. If you do specify this argument, be sure to precede it with a flag argument of 0. 3 Description The mailbox used for the pipe is a temporary mailbox. The mailbox is not deleted until all processes that have open channels to that mailbox close those channels. The last process that closes a pipe writes a message to the mailbox, indicating the end-of-file. The mailbox is created by using the $CREMBX system service, specifying the following characteristics: o A maximum message length of 512 characters o A buffer quota of 512 characters o A protection mask granting all privileges to USER and GROUP and no privileges to SYSTEM or WORLD The buffer quota of 512 characters implies that you cannot write more than 512 characters to the mailbox before all or part of the mailbox is read. Since a mailbox record is slightly larger than the data part of the message that it contains, not all of the 512 characters can be used for message data. You can increase the size of the buffer by specifying an alternative size using the optional, third argument to the pipe function. A pipe under the OpenVMS system is a stream-oriented file with no carriage-control attributes. It is fully buffered by default in the Compaq C RTL. A mailbox used as a pipe is different than a mailbox created by the application. A mailbox created by the application defaults to a record-oriented file with carriage return, carriage control. Additionally, writing a zero-length record to a mailbox writes an EOF, as does each close of the mailbox. For a pipe, only the last close of a pipe writes an EOF. The pipe is created by the parent process before vfork and an exec function are called. By calling pipe first, the child inherits the open file descriptors for the pipe. You can then use the getname function to return the name of the mailbox associated with the pipe, if this information is desired. The mailbox name returned by getname has the format _MBAnnnn:, where nnnn is a unique number. Both the parent and the child need to know in advance which file descriptors will be allocated for the pipe. This information cannot be retrieved at run time. Therefore, it is important to understand how file descriptors are used in any Compaq C for OpenVMS program. File descriptors 0, 1, and 2 are open in a Compaq C for OpenVMS program for stdin (SYS$INPUT), stdout (SYS$OUTPUT), and stderr (SYS$ERROR), respectively. Therefore, if no other files are open when pipe is called, pipe assigns file descriptor 3 for writing and file descriptor 4 for reading. In the array returned by pipe, 4 is placed in element 0 and 3 is placed in element 1. If other files have been opened, pipe assigns the first available file descriptor for writing and the next available file descriptor for reading. In this case, the pipe does not necessarily use adjacent file descriptors. For example, assume that two files have been opened and assigned to file descriptors 3 and 4 and the first file is then closed. If pipe is called at this point, file descriptor 3 is assigned for writing and file descriptor 5 is assigned for reading. Element 0 of the array will contain 5 and element 1 will contain 3. In large applications that do large amounts of I/O, it gets more difficult to predict which file descriptors are going to be assigned to a pipe; and, unless the child knows which file descriptors are being used, it will not be able to read and write successfully from and to the pipe. One way to be sure that the correct file descriptors are being used is to use the following procedure: 1. Choose two descriptor numbers that will be known to both the parent and the child. The numbers should be high enough to account for any I/O that might be done before the pipe is created. 2. Call pipe in the parent at some point before calling an exec function. 3. In the parent, use dup2 to assign the file descriptors returned by pipe to the file descriptors you chose. This now reserves those file descriptors for the pipe; any subsequent I/O will not interfere with the pipe. You can read and write through the pipe using the UNIX I/O functions read and write, specifying the appropriate file descriptors. As an alternative, you can issue fdopen calls to associate file pointers with these file descriptors so that you can use the Standard I/O functions (fread and fwrite). Two separate file descriptors are used for reading from and writing to the pipe, but only one mailbox is used so some I/O synchronization is required. For example, assume that the parent writes a message to the pipe. If the parent is the first process to read from the pipe, then it will read its own message back as shown in Reading and Writing to a Pipe. Figure REF-1 Reading and Writing to a Pipe 3 Return_Values 0 Indicates success. -1 Indicates an error. 2 popen Initiates a pipe to a process. Format #include FILE *popen (const char *command, const char *type); 3 Arguments command A pointer to a null-terminated string containing a shell command line. type A pointer to a null-terminated string containing an I/O mode. Because open files are shared, you can use a type r command as an input filter and a type w command as an output filter. Specify one of the following values for the type argument: o r - the calling program can read from the standard output of the command by reading from the returned file stream. o w - the calling program can write to the standard input of the command by writing to the returned file stream. 3 Description This function creates a pipe between the calling program and a shell command awaiting execution. It returns a pointer to a FILE structure for the stream. NOTE When you use the popen function to invoke an output filter, beware of possible deadlock caused by output data remaining in the program buffer. You can avoid this by either using the setvbuf function to ensure that the output stream is unbuffered, or the fflush function to ensure that all buffered data is flushed before calling the pclose function. See also fflush, pclose, and setvbuf. 3 Return_Values x A pointer to the FILE structure for the opened stream. NULL Indicates an error. Unable to create files or processes. 2 pow Returns the first argument raised to the power of the second argument. Format #include double pow (double x, double y); float powf (float x, float y); (Alpha only) long double powl (long double x, long double y); (Alpha only) 3 Arguments x A floating-point base to be raised to an exponent y. y The exponent to which the base x is to be raised. 3 Description The pow functions raise a floating-point base x to a floating- point exponent y. The value of pow(x,y) is computed as e**(y ln(x)) for positive x. If x is 0 and y is negative, -HUGE_VAL is returned, and errno is set to EDOM. 3 Return_Values x The result of the first argument raised to the power of the second. 1.0 The base is zero and the exponent is zero. HUGE_VAL The result overflowed; errno is set to ERANGE. -HUGE_VAL The base is zero and the exponent is negative; errno is set to EDOM. 3 Example #include #include #include main() { double x; errno = 0; x = pow(-3.0, 2.0); printf("%d, %f\n", errno, x); } This example program outputs the following: 0, 9.000000 2 printf Performs formatted output from the standard output (stdout). Format #include int printf (const char *format_spec, . . . ); 3 Arguments format_spec Characters to be written literally to the output or converted as specified in the . . . arguments. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you may omit the output sources. Otherwise, the function call must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Excess output pointers, if any, are ignored. 3 Return_Values x The number of bytes written. Negative value Indicates that an output error occurred. The function sets errno. For a list of errno values set by this function, see fprintf. 2 [w]printw Perform a printf in the specified window, starting at the current position of the cursor. The printw function acts on the stdscr window. Format #include printw (char *format_spec, . . . ); int wprintw (WINDOW *win, char *format_spec, . . . ); 3 Arguments win A pointer to the window. format_spec A pointer to the format specification string. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you may omit the output sources. Otherwise, the function call must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Excess output pointers, if any, are ignored. 3 Description The formatting specification (format_spec) and the other arguments are identical to those used with the printf function. The printw and wprintw functions format and then print the resultant string to the window using the addstr function. For more information, see the printf and scrollok functions. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the window scroll illegally. 2 putc The putc macro writes a single character to a specified file. Format #include int putc (int character, FILE *file_ptr); 3 Arguments character An object of type int. file_ptr A file pointer. 3 Description Since putc is a macro, a file pointer argument with side effects (for example, putc (ch, *f++)) might be evaluated incorrectly. In such a case, use the fputc function instead. See also fputc. 3 Return_Values x The character written to the file. Indicates success. EOF Indicates output errors. 2 putchar Writes a single character to the standard output (stdout) and returns the character. Format #include int putchar (int character); 3 Argument character An object of type int. 3 Description This function is identical to fputc (character, stdout). 3 Return_Values character Indicates success. EOF Indicates output errors. 2 putenv Sets an environmental variable. Format #include int putenv (const char *string); 3 Arguments string A pointer to a name=value string. 3 Description This function sets the value of an environment variable by altering an existing variable or by creating a new one. The string argument points to a string of the form name=value, where name is the environment variable and value is the new value for it. The string pointed to by string becomes part of the environment, so altering the string changes the environment. When a new string-defining name is passed to putenv, the space used by string is no longer used. NOTE The putenv function manipulates the environment pointed to by the environ external variable, and can be used with getenv. However, the third argument to the main function (the environment pointer), is not changed. The putenv function uses the malloc function to enlarge the environment. A potential error is to call putenv with an automatic variable as the argument, then exit the calling function while string is still part of the environment. 3 Return_Values 0 Indicates success. -1 Indicates an error. errno is set to ENOMEM- Not enough memory available to expand the environment list. 3 Restriction This function cannot take a 64-bit address. 2 puts Writes a character string to the standard output (stdout) followed by a new-line character. Format #include int puts (const char *str); 3 Argument str A pointer to a character string. 3 Description This function does not copy the terminating null character to the output stream. 3 Return_Values Nonnegative value Indicates success. EOF Indicates output errors. 2 putw Writes characters to a specified file. Format #include int putw (int integer, FILE *file_ptr); 3 Arguments integer An object of type int or long. file_ptr A file pointer. 3 Description This function writes four characters to the output file as an int. No conversion is performed. 3 Return_Values integer Indicates success. EOF Indicates output errors. 2 putwc Converts a wide character to its corresponding multibyte value, and writes the result to a specified file. Format #include wint_t putwc (wint_t wc, FILE *file_ptr); 3 Arguments wc An object of type wint_t. file_ptr A file pointer. 3 Description Since putwc might be implemented as a macro, a file pointer argument with side effects (for example putwc (wc, *f++)) might be evaluated incorrectly. In such a case, use the fputwc function instead. See also fputwc. 3 Return_Values x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno. For a list of the errno values set by this function, see fputwc. 2 putwchar Writes a wide character to the standard output (stdout) and returns the character. Format #include wint_t putwchar (wint_t wc); 3 Arguments wc An object of type wint_t. 3 Description This function is identical to fputwc(wc, stdout). 3 Return_Values x The character written to the file. Indicates success. WEOF Indicates an output error. The function sets errno. For a list of the errno values set by this function, see fputwc. 2 qabs,_llabs Returns the absolute value of an integer as an __int64. llabs is a synonym for qabs. This function is OpenVMS Alpha only. Format #include __int64 qabs (__int64 j); __int64 llabs (__int64 j); 3 Argument j A value of type __int64. 2 qdiv,_lldiv Returns the quotient and the remainder after the division of its arguments. lldiv is a synonym for qdiv. This function is OpenVMS Alpha only. Format #include qdiv_t qdiv (__int64 numer, __int64 denom); lldiv_t lldiv (__int64 numer, __int64 denom); 3 Arguments numer A numerator of type __int64. denom A denominator of type __int64. 3 Description The types qdiv_t and lldiv_t are defined in the header file as follows: typedef struct { __int64 quot, rem; } qdiv_t, lldiv_t; 2 qsort Sorts an array of objects in place. It implements the quick-sort algorithm. Format #include void qsort (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *)); 3 Function_Variants This function also has variants named _qsort32 and _qsort64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments base A pointer to the first member of the array. The pointer should be of type pointer-to-element and cast to type pointer-to-character. nmemb The number of objects in the array. size The size of an object, in bytes. compar A pointer to the comparison function. 3 Description Two arguments are passed to the comparison function pointed to by compar. The two arguments point to the objects being compared. Depending on whether the first argument is less than, equal to, or greater than the second argument, the comparison function returns an integer less then, equal to, or greater than 0. The comparison function compar need not compare every byte, so arbitrary data might be contained in the objects in addition to the values being compared. The order in the output of two objects that compare as equal is unpredictable. 2 raise Generates a specified software signal. Generating a signal causes the action routine established by the signal, ssignal, or sigvec function to be invoked. Format #include int raise (int sig); (ANSI C) int raise (int sig[, int sigcode]); (DEC C Extension) 3 Arguments sig The signal to be generated. sigcode An optional signal code, available only when not compiling in strict ANSI C mode. For example, signal SIGFPE-the arithmetic trap signal-has 10 different codes, each representing a different type of arithmetic trap. The signal codes can be represented by mnemonics or numbers. The arithmetic trap codes are represented by the numbers 1 to 10; the SIGILL codes are represented by the numbers 0 to 2. The code values are defined in the header file. 3 Description Calling this function has one of the following results: o If raise specifies a sig argument that is outside the range defined in the header file, then the raise function returns 0, and the errno variable is set to EINVAL. o If signal, ssignal, or sigvec establishes SIG_DFL (default action) for the signal, then the functions do not return. The image is exited with the OpenVMS error code corresponding to the signal. o If signal, ssignal, or sigvec establishes SIG_IGN (ignore signal) as the action for the signal, then raise returns its argument, sig. o signal, ssignal, or sigvec must establish an action function for the signal. That function is called and its return value is returned by raise. See also gsignal, signal, ssignal, and sigvec. 3 Return_Values 0 If successful. nonzero If unsuccessful. 2 rand Returns pseudorandom numbers in the range 0 to 2[31] - 1. Format #include int rand (void); 3 Description This function uses the following ANSI Standard algorithm to return a random number: static unsigned int next = 1; int rand(void) { next = next * 1103515245 + 12345; return (next & RAND_MAX); } See also srand. For other random number algorithms, see random and all the *48 functions. 2 random Generates pseudorandom numbers in a more random sequence. Format #include long int random (void); 3 Description This function is a random number generator that has virtually the same calling sequence and initialization properties as the rand function, but produces sequences that are more random. The low 12 bits generated by rand go through a cyclic pattern. All bits generated by random are usable. For example, random() &1 produces a random binary value. The random function uses a nonlinear additive feedback random number generator employing a default state array size of 31 integers to return successive pseudorandom numbers in the range from 0 to ( 231)-1. The period of this random number generator is approximately 16*(( 231)-1). The size of the state array determines the period of the random number generator. Increasing the state array size increases the period. With a full 256 bytes of state information, the period of the random number generator is greater than 269, and is sufficient for most purposes. Like the rand function, the random function produces by default a sequence of numbers that you can duplicate by calling the srandom function with a value of 1 as the seed. The srandom function, unlike the srand function, does not return the old seed because the amount of state information used is more than a single word. See also rand, srand, srandom, setstate, and initstate. 3 Return_Values n A random number. 2 [no]raw Raw mode only works with the Curses input routines [w]getch and [w]getstr. Raw mode is not supported with the Compaq C RTL emulation of UNIX I/O, Terminal I/O, or Standard I/O. Format #include raw() noraw() 3 Description Raw mode reads are satisfied on one of two conditions: after a minimum number (5) of characters are input at the terminal or after waiting a fixed time (10 seconds) from receipt of any characters from the terminal. 3 Example /* Example of standard and raw input in Curses package. */ #include main() { WINDOW *win1; char vert = '.', hor = '.', str[80]; /* Initialize standard screen, turn echo off. */ initscr(); noecho(); /* Define a user window. */ win1 = newwin(22, 78, 1, 1); leaveok(win1, TRUE); leaveok(stdscr, TRUE); box(stdscr, vert, hor); /* Reset the video, refresh(redraw) both windows. */ mvwaddstr(win1, 2, 2, "Test line terminated input"); wrefresh(win1); /* Do some input and output it. */ nocrmode(); wgetstr(win1, str); mvwaddstr(win1, 5, 5, str); mvwaddstr(win1, 7, 7, "Type something to clear screen"); wrefresh(win1); /* Get another character then delete the window. */ wgetch(win1); wclear(win1); mvwaddstr(win1, 2, 2, "Test raw input"); wrefresh(win1); /* Do some raw input 5 chars or timeout - and output it. */ raw(); getstr(str); noraw(); mvwaddstr(win1, 5, 5, str); mvwaddstr(win1, 7, 7, "Raw input completed"); wrefresh(win1); endwin(); } 2 read Reads bytes from a file and places them in a buffer. Format #include ssize_t read (int file_desc, void *buffer, size_t nbytes); (ISO POSIX-1) int read (int file_desc, void *buffer, int nbytes); (Compatability) 3 Arguments file_desc A file descriptor. The specified file descriptor must refer to a file currently opened for reading. buffer The address of contiguous storage in which the input data is placed. nbytes The maximum number of bytes involved in the read operation. 3 Description This function returns the number of bytes read. The return value does not necessarily equal nbytes. For example, if the input is from a terminal, at most one line of characters is read. NOTE The read function does not span record boundaries in a record file and, therefore, reads at most one record. A separate read must be done for each record. 3 Return_Values n The number of bytes read. -1 Indicates a read error, including physical input errors, illegal buffer addresses, protection violations, undefined file descriptors, and so forth. 3 Example #include #include #include #include #include main() { int fd, i; char buf[10]; FILE *fp ; /* Temporary STDIO file */ /* Create a dummy data file */ if ((fp = fopen("test.txt", "w+")) == NULL) { perror("open"); exit(1); } fputs("XYZ\n",fp) ; fclose(fp) ; /* And now practice "read" */ if ((fd = open("test.txt", O_RDWR, 0, "shr=upd")) <= 0) { perror("open"); exit(0); } /* Read 2 characters into buf. */ if ((i = read(fd, buf, 2)) < 0) { perror("read"); exit(0); } /* Print out what was read. */ if (i > 0) printf("buf='%c%c'\n", buf[0], buf[1]); close(fd); } 2 readdir,_readdir_r Finds entries in a directory. Format #include struct dirent *readdir (DIR *dir_pointer); int readdir_r (DIR *dir_pointer, struct dirent *entry, struct dirent **result); 3 Arguments dir_pointer A pointer to the dir structure of an open directory. entry A pointer to a dirent structure that will be initialized with the directory entry at the current position of the specified stream. result Upon successful completion, the location where a pointer to entry is stored. 3 Description The readdir function returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by dir_pointer, and positions the directory stream at the next entry. It returns a NULL pointer upon reaching the end of the directory stream. The dirent structure defined in the header file describes a directory entry. The type DIR defined in the header file represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove files from or add files to a directory asynchronously to the operation of the readdir function. The pointer returned by the readdir function points to data that you can overwrite by another call to readdir on the same directory stream. This data is not overwritten by another call to readdir on a different directory stream. If a file is removed from or added to the directory after the most recent call to the opendir or rewinddir function, a subsequent call to the readdir function might not return an entry for that file. When it reaches the end of the directory, or when it detects an invalid seekdir operation, the readdir function returns the null value. An attempt to seek to an invalid location causes the readdir function to return the null value the next time it is called. A previous telldir function call returns the position. The readdir_r function is a reentrant version of readdir. In addition to dir_pointer, you must specify a pointer to a dirent structure in which the current directory entry of the specified stream is returned. If the operation is successful, readdir_r returns 0 and stores one of the two following pointers in result: o Pointer to entry if the entry was found o NULL pointer if the end of the directory stream was reached If an error occurred, an error value is returned that indicates the cause of the error. The storage pointed to by entry must be large enough for a dirent with an array of char d_name member containing at least NAME_MAX + 1 elements. 3 Example See the description of closedir for an example. 3 Return_Values x On successful completion of readdir, a pointer to an object of type struct dirent. 0 Successful completion of readdir_r. x On error, an error value (readdir_r only). NULL An error occurred or end of the directory stream (readdir_r only). If an error occurred, errno is set to a value indicating the cause. 2 realloc Changes the size of the area pointed to by the first argument to the number of bytes given by the second argument. These functions are AST-reentrant. Format #include void *realloc (void *ptr, size_t size); 3 Function_Variants This function also has variants named _realloc32 and _realloc64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments ptr Points to an allocated area, or can be NULL. size The new size of the allocated area. 3 Description If ptr is the NULL pointer, the behavior of the realloc function is identical to the malloc function. The contents of the area are unchanged up to the lesser of the old and new sizes. The ANSI C Standard states that "If the new size is larger than the old size, the value of the newly allocated portion of memory is indeterminate." For compatibility with old implementations, Compaq C initializes the newly allocated memory to 0. For efficiency, the previous actual allocation could have been larger than the requested size. If it was allocated with malloc, the value of the portion of memory between the previous requested allocation and the actual allocation is indeterminate. If it was allocated with calloc, that same memory was initialized to 0. If your application relies on realloc initializing memory to 0, then use calloc instead of malloc to perform the initial allocation. See also free, cfree, calloc, and malloc. 3 Return_Values x The address of the area, quadword-aligned. The address is returned because the area may have to be moved to a new address to reallocate enough space. If the area was moved, the space previously occupied is freed. NULL Indicates that space cannot be reallocated (for example, if there is not enough room). 2 [w]refresh Repaint the specified window on the terminal screen. The refresh function acts on the stdscr window. Format #include int refresh(); int wrefresh (WINDOW *win); 3 Argument win A pointer to the window. 3 Description The result of this process is that the portion of the window not occluded by subwindows or other windows appears on the terminal screen. To see the entire occluded window on the terminal screen, call the touchwin function instead of the refresh or wrefresh function. See also touchwin. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 remove Deletes a file. Format #include int remove (const char *file_spec); 3 Argument file_spec A pointer to the string that is an OpenVMS or a UNIX style file specification. The file specification can include a wildcard in its version number. So, for example, files of the form filename.txt;* can be deleted. 3 Description If you specify a directory in the file name and it is a search list that contains an error, Compaq C for OpenVMS Systems interprets it as a file error. The remove and delete functions are functionally equivalent in the Compaq C RTL. See also delete. 3 Return_Values 0 Indicates success. nonzero value Indicates failure. 2 rename Gives a new name to an existing file. Format #include int rename (const char *old_file_spec, const char *new_file_spec); 3 Arguments old_file_spec A pointer to a string that is the existing name of the file to be renamed. new_file_spec A pointer to a string that is to be the new name of the file. 3 Description If you try to rename a file that is currently open, the behavior is undefined. You cannot rename a file from one physical device to another. Both the old and new file specifications must reside on the same device. If the new_file_spec does not contain a file extension, the file extension of old_file_spec is used. To rename a file to have no file extension, new_file_spec must contain a period (.) For example, the following renames SYS$DISK:[]FILE.DAT to SYS$DISK:[]FILE1.DAT: rename("file.dat", "file1"); Whereas the following renames SYS$DISK:[]FILE.DAT to SYS$DISK:[]FILE1: rename(file.dat", "file1."); NOTE Because the rename function does special processing of the file extension, the caller must be careful when specifying the name of the renamed file in a call to a C Run-Time Library function that accepts a filename argument. For example, after the following call to the rename function, the new file should be opened as fopen("bar.dat",...): rename("foo.dat", "bar"); 3 Return_Values 0 Indicates success. nonzero value Indicates failure. 2 rewind Sets the file to its beginning. Format #include void rewind (FILE *file_ptr); (ISO POSIX-1) int rewind (FILE *file_ptr); (DEC C Extension) 3 Argument file_ptr A file pointer. 3 Description The rewind function is equivalent to fseek (file_ptr, 0, SEEK_ SET). You can use the rewind function with either record or stream files. A successful call to rewind clears the error indicator for the file. The ANSI C standard defines rewind as not returning a value; therefore, the function prototype for rewind is declared with a return type of void. However, since a rewind can fail, and since previous versions of the Compaq C RTL have declared rewind to return an int, the code for rewind does return 0 on success and -1 on failure. See also fseek. 2 rewinddir Resets the position of the specified directory stream to the beginning of a directory. Format #include void rewinddir (DIR *dir_pointer); 3 Arguments dir_pointer A pointer to the dir structure of an open directory. 3 Description This function resets the position of the specified directory stream to the beginning of the directory. It also causes the directory stream to refer to the current state of the corresonding directory, the same as using the opendir function. If the dir_pointer argument does not refer to a directory stream, the effect is undefined. The type DIR, defined in the header file, represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. See also opendir. 2 rindex Searches for character in string. Format #include char *rindex (const char *s, int c); 3 Function_Variants This function also has variants named _rindex32 and _rindex64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s The string to search. c The character to search for. 3 Description This function is identical to the strchr function, and is provided for compatibility with some UNIX implementations. 2 rint Rounds its argument to an integral value according to the current IEEE rounding direction specified by the user. This function is OpenVMS Alpha only. Format #include double rint (double x); float rintf (float x,); long double rintl (long double x); 3 Argument x A real number. 3 Description The rint functions return the nearest integral value to x in the direction of the current IEEE rounding mode specified on the /ROUNDING_MODE command-line qualifier. If the current rounding mode rounds toward negative Infinity, then rint is identical to floor. If the current rounding mode rounds toward positive Infinity, then rint is identical to ceil. If |x| = Infinity, rint returns x. 3 Return_Values n The nearest integral value to x in the direction of the current IEEE rounding mode. NaN x is NaN; errno is set to EDOM. 2 rmdir Removes a directory file. Format #include int rmdir (const char *path); 3 Arguments path A directory path name. 3 Description This function removes a directory file whose name is specified in the path argument. The directory is removed only if it is empty. 3 Restriction When using OpenVMS format names, the path argument must be in the form directory.dir. 3 Return_Values 0 Indicates success. -1 An error occurred; errno is set to indicate the error. 2 sbrk Determines the lowest virtual address that is not used with the program. Format #include void *sbrk (long int incr); 3 Argument incr The number of bytes to add to the current break address. 3 Description This function adds the number of bytes specified by its argument to the current break address and returns the old break address. When a program is executed, the break address is set to the highest location defined by the program and data storage areas. Consequently, sbrk is needed only by programs that have growing data areas. sbrk(0) returns the current break address. 3 Return_Values x The old break address. (void *)(-1) Indicates that the program is requesting too much memory. 3 Restriction Unlike other C library implementations, the Compaq C RTL memory allocation functions (such as malloc) do not rely on brk or sbrk to manage the program heap space. Consequently, on OpenVMS systems, calling brk or sbrk can interfere with memory allocation routines. The brk and sbrk functions are provided only for compatibility purposes. 2 scalb Returns the exponent of a floating-point number. This function is OpenVMS Alpha only. Format #include double scalb (double x, double n); float scalbf (float x, float n); long double scalbl (long double x, long double n); 3 Argument x A nonzero floating-point number. n An integer. 3 Description The scalb functions return x*(2**n) for integer n. 3 Return_Values x On successful completion, x*(2**n) is returned. (according to the sign of x) and sets errno to ERANGE. 0 Underflow occurred; errno is set to ERANGE. x x is NaN x or n is NaN; errno is set to EDOM. 2 scanf Performs formatted input from the standard input (stdin), interpreting it according to the format specification. Format #include int scanf (const char *format_spec, . . . ); 3 Arguments format_spec Pointer to a string containing the format specification. The format spcification consists of characters to be taken literally from the input or converted and placed in memory at the specified input sources. . . . Optional expressions that are pointers to objects whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit these input pointers. Otherwise, the function call must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Return_Values x The number of successfully matched and assigned input items. EOF Indicates that a read error occurred prior to any successful conversions.The function sets errno. For a list of errno values set by this function, see fscanf. 2 [w]scanw Perform a scanf on the window. The scanw function acts on the stdscr window. Format #include int scanw (char *format_spec, . . . ); int wscanw (WINDOW *win, char *format_spec, . . . ); 3 Arguments win A pointer to the window. format_spec A pointer to the format specification string. . . . Optional expressions that are pointers to objects whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you may omit these input pointers. Otherwise, the function call must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description The formatting specification (format_spec) and the other arguments are identical to those used with the scanf function. The scanw and wscanw functions accept, format, and return a line of text from the terminal screen. For more information, see the scrollok and scanf functions. 3 Return_Values OK Indicates success. ERR Indicates that the function makes the screen scroll illegally or that the scan was unsuccessful. 2 scroll Moves all the lines on the window up one line. The top line scrolls off the window and the bottom line becomes blank. Format #include int scroll (WINDOW *win); 3 Argument win A pointer to the window. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 scrollok Sets the scroll flag for the specified window. Format #include scrollok (WINDOW *win, bool boolf); 3 Arguments win A pointer to the window. boolf A Boolean TRUE or FALSE value. If boolf is FALSE, scrolling is not allowed. This is the default setting. The bool type is defined in the header file as follows: #define bool int 2 seed48 Initializes a 48-bit random number generator. Format #include unsigned short *seed48 (unsigned short seed_16v[3]); 3 Arguments seed_16v An array of three unsigned short int that form a 48-bit seed value. 3 Description The seed48 function initializes the random number generator. You can use this function in your program before calling the drand48, lrand48, or mrand48 functions. (Although it is not recommended practice, constant default initializer values are supplied automatically if you call drand48, lrand48, or mrand48 without calling an initialization function). The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n > 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The initializer function seed48: o Sets the value of Xi to the 48-bit value specified in the array pointed to by seed_16v. o Returns a pointer to a 48-bit internal buffer that contains the previous value of Xi, used only by seed48. The returned pointer allows you to restart the pseudorandom sequence at a given point. Use the pointer to copy the previous Xi value into a temporary array. To resume where the original sequence left off, you can call seed48 with a pointer to this array. See also drand48, lrand48, and mrand48. 3 Return_Values x A pointer to a 48-bit internal buffer. 2 seekdir Sets the position of a directory stream. Format #include void seekdir (DIR *dir_pointer, long int location); 3 Arguments dir_pointer A pointer to the dir structure of an open directory. location The number of an entry relative to the start of the directory. 3 Description This function sets the position of the next readdir operation on the directory stream specified by dir_pointer to the position specified by location. The value of location should be returned from an earlier call to telldir. If the value of location was not returned by a call to the telldir function, or if there was an intervening call to the rewinddir function on this directory stream, the effect is unspecified. The type DIR, defined in the header file, represents a directory stream. A directory stream is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files. You can remove files from or add files to a directory asynchronously to the operation of the readdir function. See readdir, rewinddir, and telldir. 2 [w]setattr Activate the video display attribute attr within the window. The setattr function acts on the stdscr window. Format #include int setattr (int attr); int wsetattr (WINDOW *win, int attr); 3 Arguments win A pointer to the window. attr One of a set of video display attributes, which are blinking, boldface, reverse video, and underlining, and are represented by the defined constants _BLINK, _BOLD, _REVERSE, and _UNDERLINE, respectively. You can set multiple attributes by separating them with a bitwise OR operator (|) as follows: setattr(_BLINK | _UNDERLINE); 3 Description The setattr and wsetattr functions are specific to Compaq C for OpenVMS Systems and are not portable. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 setbuf Associates a new buffer with an input or output file and potentially modifies the buffering behavior. Format #include void setbuf (FILE *file_ptr, char *buffer); 3 Arguments file_ptr A file pointer. buffer A pointer to a character array, or a NULL pointer. 3 Description You can use this function after the specified file is opened but before any I/O operations are performed. If buffer is a NULL pointer, then the call is equivalent to a call to setvbuf with the same file_ptr, a NULL buffer pointer, a buffering type of _IONBF (no buffering), and a buffer size of 0. If buffer is not a NULL pointer, then the call is equivalent to a call to setvbuf with the same file_ptr, the same buffer pointer, a buffering type of _IOFBF, and a buffer size given by the value BUFSIZ (defined in ). You should, therefore, use BUFSIZ to allocate the buffer argument used in the call to setbuf. For example: #include . . . char my_buf[BUFSIZ]; . . . setbuf(stdout, my_buf); . . . User programs must not depend on the contents of buffer once I/O has been performed on the stream. The Compaq C RTL might or might not use buffer for any given I/O operation. The setbuf function originally allowed programmers to substitute larger buffers in place of the system default buffers in obsolete versions of UNIX. The large default buffer sizes in modern implementations of C make the use of this function unnecessary most of the time. The setbuf function is retained in the ANSI C standard for compatibility with old programs. New programs should use setvbuf instead, because it allows the programmer to bind the buffer size at run time instead of compile time, and it returns a testable result value. 2 setenv Inserts or resets the environment variable name in the current environment list. Format #include int setenv (const char *name, const char *value, int overwrite); 3 Arguments name A variable name in the environment variable list. value The value for the environment variable. overwrite A value of 0 or 1 indicating whether to reset the environment variable, if it exists. 3 Description This function inserts or resets the environment variable name in the current environment list. If the variable name does not exist in the list, it is inserted with the value argument. If the variable does exist, the overwrite argument is tested. When the overwrite argument value is: o 0 (zero) - then the variable is not reset. o 1 - then the variable is reset to value. 3 Return_Values 0 Indicates success. -1 Indicates an error. errno is set to ENOMEM- Not enough memory available to expand the environment list. 2 setgid With POSIX IDs disabled, implemented for program portability and serves no function. It returns 0 (to indicate success). With POSIX IDs enabled, sets the group IDs. Format #include #include int setgid (__gid_t gid); (_DECC_V4_SOURCE) gid_t setgid (gid_t gid); (not _DECC_V4_SOURCE) 3 Arguments gid The value to which you want the group IDs set. 3 Description This function can be used with POSIX-style identifiers enabled or disabled. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX IDs disabled (the default), the setgid function is implemented for program portability and serves no function. It returns 0 (to indicate success). With POSIX-style IDs enabled: o If the process has the IMPERSONATE privilege, the setgid function sets the real group ID, effective group ID, and the saved set-group-ID to gid. o If the process does not have appropriate privileges but gid is equal to the real group ID or to the saved set-group-ID, then the setgid function sets the effective group ID to gid. The real group ID and saved set-group-ID remain unchanged. o Any supplementary group IDs of the calling process remain unchanged. 3 Return_Values 0 Successful completion. -1 Indicates an error. The function sets errno to one of the following values: o EINVAL - The value of the gid argument is invalid and not supported by the implementation. o EPERM - The process does not have appropriate privileges and gid does not match the real group ID or the saved set- group-ID. 2 setitimer Sets the value of interval timers. Format #include int setitimer (int which, struct itimerval *value, struct itimerval *ovalue); 3 Arguments which The type of interval timer. The Compaq C RTL only supports ITIMER_REAL. value A pointer to an itimerval structure whose members specify a timer interval and the time left to the end of the interval. ovalue A pointer to an itimerval structure whose members specify a current timer interval and the time left to the end of the interval. 3 Description This function sets the timer specified by which to the value specified by value, returning the previous value of the timer if ovalue is nonzero. A timer value is defined by the itimerval structure: struct itimerval { struct timeval it_interval; struct timeval it_value; }; The value of the itimerval structure members are: as follows itimerval Member Value Meaning it_interval = 0 Disables a timer after its next expiration (Assumes it_value is nonzero). it_interval = Specifies a value used in reloading it_value nonzero when the timer expires. it_value = 0 Disables a timer. it_value = Indicates the time to the next timer nonzero expiration. Time values smaller than the resolution of the system clock are rounded up to this resolution. The getitimer function provides one interval timer, defined in the header file as ITIMER_REAL. This timer decrements in real time. When the timer expires, it delivers a SIGALARM signal. NOTE The interaction between setitimer and any of alarm, sleep, or usleep is unspecified. 3 Return_Values 0 Indicates success. -1 An error occurred; errno is set to indicate the error. 2 setjmp Provides a way to transfer control from a nested series of function invocations back to a predefined point without returning normally. It does not use a series of return statements. The setjmp function saves the context of the calling function in an environment buffer. Format #include int setjmp (jmp_buf env); 3 Argument env The environment buffer, which must be an array of integers long enough to hold the register context of the calling function. The type jmp_buf is defined in the header file. The contents of the general-purpose registers, including the program counter (PC), are stored in the buffer. 3 Description When setjmp is first called, it returns the value 0. If longjmp is then called, naming the same environment as the call to setjmp, control is returned to the setjmp call as if it had returned normally a second time. The return value of setjmp in this second return is the value supplied by you in the longjmp call. To preserve the true value of setjmp, the function calling setjmp must not be called again until the associated longjmp is called. The setjmp function preserves the hardware general purpose registers, and the longjmp function restores them. After a longjmp, all variables have their values as of the time of the longjmp except for local automatic variables not marked volatile. These variables have indeterminate values. The setjmp and longjmp functions rely on the OpenVMS condition-handling facility to effect a nonlocal goto with a signal handler. The longjmp function is implemented by generating a Compaq C RTL specified signal that allows the OpenVMS condition-handling facility to unwind back to the desired destination. The Compaq C RTL must be in control of signal handling for any Compaq C image. For Compaq C to be in control of signal handling, you must establish all exception handlers through a call to the VAXC$ESTABLISH function. NOTE There are Alpha specific, non-standard decc$setjmp and decc$fast_longjmp functions. To use these non-standard functions instead of the standard ones, a program must be compiled with __FAST_SETJMP or __UNIX_SETJMP macros defined. Unlike the standard longjmp function, the decc$fast_longjmp function does not convert its second argument from 0 to 1. After a call to decc$fast_longjmp, a corresponding setjmp function returns with the exact value of the second argument specified in the decc$fast_longjmp call. 3 Restrictions You cannot invoke the longjmp function from an OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the Compaq C RTL, subject to the following nesting restrictions: o The longjmp function will not work if you invoke it from nested signal handlers. The result of the longjmp function, when invoked from a signal handler that has been entered as a result of an exception generated in another signal handler, is undefined. o Do not invoke the setjmp function from a signal handler unless the associated longjmp is to be issued before the handling of that signal is completed. o Do not invoke the longjmp function from within an exit handler (established with atexit or SYS$DCLEXH). Exit handlers are invoked after image tear-down, so the destination address of the longjmp no longer exists. o Invoking longjmp from within a signal handler to return to the main thread of execution might leave your program in an inconsistent state. Possible side effects include the inability to perform I/O or to receive any more UNIX signals. Use siglongjmp instead. 3 Return_Values See the Description section. 2 setlocale Selects the appropriate portion of the program's locale as specified by the category and locale arguments. You can use this function to change or query one category or the program's entire current locale. Format #include char *setlocale (int category, const char *locale); 3 Arguments category The name of the category. Specify LC_ALL to change or query the entire locale. Other valid category names are: o LC_COLLATE o LC_CTYPE o LC_MESSAGES o LC_MONETARY o LC_NUMERIC o LC_TIME locale Pointer to a string that specifies the locale. 3 Description This function sets or queries the appropriate portion of the program's locale as specified by the category and locale arguments. Specifying LC_ALL for the category argument names the entire locale; specifying the other values name only a portion of the program's locale. The locale argument points to a character string that identifies the locale to be used. This argument can be one of the following: o Name of the public locale Specifies the public locale in the following format: language_country.codeset[@modifier] The function searches for the public locale binary file in the location defined by the logical name SYS$I18N_LOCALE. The file type defaults to .LOCALE. The period (.) and at-sign (@) characters in the name are replaced by an underscore (_). For example: If the specified name is "zh_CN.dechanzi@radical", the function searches for the SYS$I18N_LOCALE:ZH_CN_DECHANZI_RADICAL.LOCALE binary locale file. o A file specification Specifies the binary locale file. It can be any valid file specification. If either the device or directory is omitted, the function first applies the current caller's device and directory as defaults for any missing component. If the file not found, the function applies the device and directory defined by the SYS$I18N_LOCALE logical name as defaults. The file type defaults to .LOCALE. No wildcards are allowed. The binary locale file cannot reside on a remote node. o "C" Specifies the C locale. If a program does not call setlocale, the C locale is the default. o "POSIX" This is the same as the C locale. o "" Specifies that the locale is initialized from the setting of the international environment logical names. The function checks the following logical names in the order shown until it finds a logical that is defined: 1. LC_ALL 2. Logical names corresponding to the category. For example, if LC_NUMERIC is specified as the category, then the first logical name that setlocale checks is LC_NUMERIC. 3. LANG 4. SYS$LC_ALL 5. The system default for the category, which is defined by the SYS$LC_* logical names. For example, the default for the LC_NUMERIC category is defined by the SYS$LC_NUMERIC logical name. 6. SYS$LANG If none of the logical names is defined, the C locale is used as the default. The SYS$LC_* logical names are set up at the system startup time. Like the locale argument, the equivalence name of the international environment logical name can be either the name of the public locale or the file specification. The setlocale function treats this equivalence name as if it were specified as the locale argument. o NULL Causes setlocale to query the current locale. The function returns a pointer to a string describing the portion of the program's locale associated with category. Specifying the LC_ ALL category returns the string describing the entire locale. The locale is not changed. o The string returned from the previous call to setlocale Causes the function to restore the portion of the program's locale associated with category. If the string contains the description of the entire locale, the part of the string corresponding to category is used. If the string describes the portion of the program's locale for a single category, this locale is used. For example, this means that you can use the string returned from the call setlocale with the LC_COLLATE category to set the same locale for the LC_MESSAGES category. If the specified locale is available, then setlocale returns a pointer to the string that describes the portion of the program's locale associated with category. For the LC_ALL category, the returned string describes the entire program's locale. If an error occurs, a NULL pointer is returned and the program's locale is not changed. Subsequent calls to setlocale overwrite the returned string. If that part of the locale needs to be restored, the program should save the string. The calling program should make no assumptions about the format or length of the returned string. 3 Return_Values x Pointer to a string describing the locale. NULL Indicates an error occurred; errno is set. 3 Example #include #include #include /* This program calls setlocale() three times. The second call */ /* is for a nonexistent locale. The third call is for an */ /* existing file that is not a locale file. */ main() { char *ret_str; errno = 0; printf("setlocale (LC_ALL, \"POSIX\")"); ret_str = (char *) setlocale(LC_ALL, "POSIX"); if (ret_str == NULL) perror("setlocale error"); else printf(" call was succesfull\n"); errno = 0; printf("\n\nsetlocale (LC_ALL, \"junk.junk_codeset\")"); ret_str = (char *) setlocale(LC_ALL, "junk.junk_ codeset"); if (ret_str == NULL) perror(" returned error"); else printf(" call was succesfull\n"); errno = 0; printf("\n\nsetlocale (LC_ ALL, \"sys$login:login.com\")"); ret_str = (char *) setlocale(LC_ ALL, "sys$login:login.com"); if (ret_str == NULL) perror(" returned error"); else printf(" call was succesfull\n"); } Running the example program produces the following result: setlocale (LC_ALL, "POSIX") call was succesfull setlocale (LC_ALL, "junk.junk_codeset") returned error: no such file or directory setlocale (LC_ALL, "sys$login:login.com") returned error: non-translatable vms error code: 0x35C07C %c-f-localebad, not a locale file 2 setpwent Accesses the first entry of user attribute information in the user database. Format #include #include int *setpwent (void); 3 Description Use this function to access basic user attributes about a specified user. The setpwent function ensures that the next call to the getpwent function returns the first entry. See also getpwent. 2 setstate Restarts, and changes random number generators. Format char *setstate (char *state;) 3 Arguments state Points to the array of state information. 3 Description This function handles restarting and changing random number generators. Once you initialize a state, the setstate function allows rapid switching between state arrays. The array defined by state is used for further random number generation until the initstate function is called or the setstate function is called again. The setstate function returns a pointer to the previous state array. After initialization, you can restart a state array at a different point in one of two ways: o Use the initstate function, with the desired seed, state array, and size of the array. o Use the setstate function, with the desired state, followed by the srandom function with the desired seed. The advantage of using both functions is that you do not have to save the state array size once you initialize it. See also initstate, srandom, and random. 3 Return_Values x A pointer to the previous state array information. 0 Indicates an error. The state information is damaged. Further specified in the following errno value: o EINVAL-The state argument is invalid. 2 setuid With POSIX IDs disabled, implemented for program portability and serves no function. It returns 0 (to indicate success). With POSIX IDs enabled, sets the user IDs. Format #include #include int setuid (__uid_t uid); (_DECC_V4_SOURCE) uid_t setuid (uid_t uid); (not _DECC_V4_SOURCE) 3 Arguments uid The value to which you want the user IDs set. 3 Description This function can be used with POSIX-style identifiers enabled or disabled. NOTE OpenVMS Version 7.3-1 does not support POSIX-style IDs, but it does support 32-bit identifiers. With POSIX IDs disabled (the default), the setuid function is implemented for program portability and serves no function. It returns 0 (to indicate success). With POSIX-style IDs enabled: o If the process has the IMPERSONATE privilege, the setuid function sets the real user ID, effective user ID, and the saved set-user-ID to uid. o If the process does not have appropriate privileges but uid is equal to the real user ID or to the saved set-user-ID, then the setuid function sets the effective user ID to uid. The real user ID and saved set-user-ID remain unchanged. 3 Return_Values 0 Successful completion. -1 Indicates an error. The function sets errno to one of the following values: o EINVAL - The value of the uid argument is invalid and not supported by the implementation. o EPERM - The process does not have appropriate privileges and uid does not match the real user ID or the saved set- user-ID. 2 setvbuf Associates a buffer with an input or output file and potentially modifies the buffering behavior. Format #include int setvbuf (FILE *file_ptr, char *buffer, int type, size_t size); 3 Arguments file_ptr A pointer to a file. buffer A pointer to a character array, or a NULL pointer. type The buffering type. Use one of the following values defined in : _IONBF, _IOFBF, _IOLBF. size The number of bytes to be used in buffer by the Compaq C RTL for buffering this file. The buffer size must be a minimum of 8192 bytes and a maximum of 32767 bytes. 3 Description You can use this function after the file is opened but before any I/O operations are performed. The ANSI C standard defines the following types of file buffering. In unbuffered I/O, each I/O operation is performed immediately. Output characters or lines are written to the output device before control is returned to the program. Input characters or lines are sent directly to the program without read-ahead by the Compaq C RTL. In line-buffered I/O, characters are buffered in an area of memory until a new-line character is seen, at which point the appropriate RMS routine is called to transmit the entire buffer. Line buffering is more efficient than unbuffered I/O since it reduces the system overhead, but it delays the availability of the data to the user or disk on output. In fully buffered I/O, characters are buffered in an area of memory until the buffer is full, regardless of the presence of break characters. Full buffering is more efficient than line buffering or unbuffered I/O, but it delays the availability of output data even longer than line buffering. Use the values _IONBF, _IOLBF, and _IOFBF defined in for the type argument to specify unbuffered, line-buffered, and fully buffered I/O, respectively. If _IONBF is specified for type, I/O will be unbuffered and the buffer and size arguments are ignored. If _IOLBF or _IOFBF is specified for type, the Compaq C RTL will use line-buffered I/O if file_ptr specifies a terminal device; otherwise, it will use fully buffered I/O. The Compaq C RTL automatically allocates a buffer to use for each I/O stream. So there are several buffer allocation possibilities: o If buffer is not a NULL pointer and size is not smaller than the automatically allocated buffer, then setvbuf uses buffer as the file buffer. o If buffer is a NULL pointer or size is smaller than the automatically allocated buffer, the automatically allocated buffer is used as the buffer area. o If buffer is a NULL pointer and size is larger than the automatically allocated buffer, then setvbuf allocates a new buffer equal to the specified size and uses that as the file buffer. User programs must not depend on the contents of buffer once I/O has been performed on the stream. The Compaq C RTL might or might not use buffer for any given I/O operation. Generally, it is unnecessary to use setvbuf or setbuf to control the buffer size used by the Compaq C RTL. The automatically allocated buffer sizes are chosen for efficiency based on the kind of I/O operations performed and the device characteristics (such as terminal, disk, or socket). The setvbuf and setbuf functions are useful to introduce buffering for improved performance when writing a large amount of text to the stdout stream. This stream is unbuffered by default when bound to a terminal device (the normal case), and therefore incurs a large number of OpenVMS buffered I/O operations unless Compaq C RTL buffering is introduced by a call to setvbuf or setbuf. The setvbuf function is used only to control the buffering used by the Compaq C RTL, not the buffering used by the underlying RMS I/O operations. You can modify RMS default buffering behavior by specifying various values for the ctx, fop, rat, gbc, mbc, mbf, rfm, and rop RMS keywords when the file is opened by the creat, freopen or open functions. 3 Return_Values 0 Indicates success. nonzero value Indicates that an invalid input value was specifed for type or file_ptr, or because file_ptr is being used by another thread. 2 sigaction Specifies the action to take upon delivery of a signal. Format #include int sigaction (int sig, const struct sigaction *action, struct sigaction *o_action); 3 Arguments sig The signal for which the action is to be taken. action A pointer to a sigaction structure that describes the action to take when you receive the signal specified by the sig argument. o_action A pointer to a sigaction structure. When the sigaction function returns from a call, the action previously attached to the specified signal is stored in this structure. 3 Description When a process requests the sigaction function, the process can both examine and specify what action to perform when the specified signal is delivered. The arguments determine the behavior of the sigaction function as follows: o Specifying the sig argument identifies the affected signal. Use any one of the signal values defined in the header file, except SIGKILL. If sig is SIGCHLD and the SA_NOCLDSTOP flag is not set in sa_flags, then a SIGCHLD signal is generated for the calling process whenever any of its child processes stop. If sig is SIGCHLD and the SA_NOCLDSTOP flag is set in sa_flags, then SIGCHLD signal is not generated in this way. o Specifying the action argument, if not null, points to a sigaction structure that defines what action to perform when the signal is received. If the action argument is null, signal handling remains unchanged, so you can use the call to inquire about the current handling of the signal. o Specifying the o_action argument, if not null, points to a sigaction structure that contains the action previously attached to the specified signal. The sigaction structure consists of the following members: void (*sa_handler)(int); sigset_t sa_mask; int sa_flags; The sigaction structure members are defined as follows: sa_ This member can contain the following values: handler o SIG_DFL - Specifies the default action taken when the signal is delivered. o SIG_IGN - Specifies that the signal has no effect on the receiving process. o Function pointer - Requests to catch the signal. The signal causes the function call. sa_mask This member can request that individual signals, in addition to those in the process signal mask, are blocked from delivery while the signal handler function specified by the sa_handler member is executing. sa_flags This member can set the flags to enable further control over the actions taken when a signal is delivered. The sa_flags member of the sigaction structure has the following values: SA_ONSTACK Setting this bit causes the system to run the signal catching function on the signal stack specified by the sigstack function. If this bit is not set, the function runs on the stack of the process where the signal is delivered. SA_RESETHAND Setting this bit resets the signal to SIG_DFL. Be aware that you cannot automatically reset SIGILL and SIGTRAP. SA_NODEFER Setting this bit does not automatically block the signal as it is caught. SA_NOCLDSTOP If this bit is set and the sig argument is equal to SIGCHLD and a child process of the calling process stops, then a SIGCHLD signal is sent to the calling process only if SA_NOCLDSTOP is not set for SIGCHLD. When a signal is caught by a signal-catching function installed by sigaction, a new signal mask is calculated and installed for the duration of the signal-catching function (or until a call to either sigprocmask or sigsuspend is made. This mask is formed by taking the union of the current signal mask and the value of the sa_mask for the signal being delivered unless SA_NODEFER or SA_ RESETHAND is set, and then including the signal being delivered. If and when the user's signal handler returns normally, the original signal mask is restored. Once an action is installed for a specific signal, it remains installed until another action is explicitly requested (by another call to sigaction), until the SA_RESETHAND flag causes resetting of the handler, or until one of the exec functions is called. If the previous action for a specified signal had been established by signal, the values of the fields returned in the structure pointed to by the o_action argument of sigaction are unspecified, and in particular o_action->sa_handler is not necessarily the same value passed to signal. However, if a pointer to the same structure or a copy thereof is passed to a subsequent call to sigaction by means of the action argument of sigaction), the signal is handled as if the original call to signal were repeated. If sigaction fails, no new signal handler is installed. It is unspecified whether an attempt to set the action for a signal that cannot be caught or ignored to SIG_DFL is ignored or causes an error to be returned with errno set to EINVAL. See the "Error and Signal Handling" chapter of the Compaq C RTL Reference Manual for more information on signal handling. NOTE The sigvec and signal functions are provided for compatibility to old UNIX systems; their function is a subset of that available with the sigaction function. See also sigstack, sigvec, signal, wait, read, and write. 3 Return_Values 0 Indicates success. -1 Indicates an error; A new signal handler is not installed. errno is set to one of the following values: o EFAULT - The action or o_action argument points to a location outside of the allocated address space of the process. o EINVAL - The sig argument is not a valid signal number. Or an attempt was made to ignore or supply a handler for the SIGKILL, SIGSTOP, and SIGCONT signals. 2 sigaddset Adds the specified individual signal. Format #include int sigaddset (sigset_t *set, int sig_number); 3 Arguments set The signal set. sig_number The individual signal. 3 Description This function manipulates sets of signals. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process. The sigaddset function adds the individual signal specified by sig_number from the signal set specified by set. 3 Example The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery. #include int return_value; sigset_t newset; . . . sigemptyset(&newset); sigaddset(&newset, SIGINT); return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EINVAL - The value of sig_number is not a valid signal number. 2 sigblock Adds the signals in mask to the current set of signals being blocked from delivery. Format #include int sigblock (int mask); 3 Argument mask The signals to be blocked. 3 Description Signal i is blocked if the i - 1 bit in mask is a 1. For example, to add the protection-violation signal to the set of blocked signals, use the following line: sigblock(1 << (SIGBUS - 1)); You can express signals in mnemonics (such as SIGBUS for a protection violation) or numbers as defined in the header file, and you can express combinations of signals by using the bitwise OR operator (|). 3 Return_Value x Indicates the previous set of masked signals. 2 sigdelset Deletes a specified individual signal. Format #include int sigdelset (sigset_t *set, int sig_number;) 3 Arguments set The signal set. sig_number The individual signal. 3 Description The sigdelset function deletes the individual signal specified by sig_number from the signal set specified by set. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EINVAL - The value of sig_number is not a valid signal number. 2 sigemptyset Initializes the signal set to exclude all signals. Format #include int sigemptyset (sigset_t *set); 3 Arguments set The signal set. 3 Description The sigemptyset function initializes the signal set pointed to by set such that you exclude all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process. See also sigfillset. 3 Example The following example shows how to generate and use a signal mask that blocks only the SIGINT signal from delivery. #include int return_value; sigset_t newset; . . . sigemptyset(&newset); sigaddset(&newset, SIGINT); return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 3 Return_Values 0 Indicates success. -1 Indicates an error; the global errno is set to indicate the error. 2 sigfillset Initializes the signal set to include all signals. Format #include int sigfillset (sigset_t *set); 3 Arguments set The signal set. 3 Description The sigfillset function initializes the signal set pointed to by set such that you include all signals. A call to sigemptyset or sigfillset must be made at least once for each object of type sigset_t prior to any other use of that object. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process. See also sigemptyset. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to one of the following values: o EINVAL - The value of the sig_number argument is not a valid signal number. 2 sigismember Tests whether a specified signal is a member of the signal set. Format #include int sigismember (const sigset_t *set, int sig_number); 3 Arguments set The signal set. sig_number The individual signal. 3 Description The sigismember function tests whether sig_number is a member of the signal set pointed to by set. This function operates on data objects that you can address by the application, not on any set of signals known to the system. For example, this function does not operate on the set blocked from delivery to a process or the set pending for a process. 3 Return_Values 1 Indicates success. The specified signal is a member of the specified set. 0 Indicates an error. The specified signal is not a member of the specified set. 2 siglongjmp Nonlocal goto with signal handling. Format #include void siglongjmp (sigjmp_buf env, int value); 3 Arguments env An address for a sigjmp_buf structure. value A nonzero value. 3 Description This function restores the environment saved by the most recent call to sigsetjmp in the same process with the corresponding sigjmp_buf argument. All accessible objects have values when siglongjmp is called, with one exception: values of objects of automatic storage duration that changed between the sigsetjmp call and siglongjmp call are indeterminate. Because it bypasses the usual function call and return mechanisms, siglongjmp executes correctly during interrupts, signals, and any of their associated functions. However, if you invoke siglongjmp from a nested signal handler (for example, from a function invoked as a result of a signal raised during the handling of another signal), the behavior is undefined. The siglongjmp function restores the saved signal mask only if you initialize the env argument by a call to sigsetjmp with a nonzero savemask argument. After siglongjmp is completed, program execution continues as if the corresponding call of sigsetjmp just returned the value specified by value. The siglongjmp function cannot cause sigsetjmp to return 0 (zero); if value is 0, sigsetjmp returns 1 See also sigsetjmp. 2 sigmask Constructs the mask for a given signal number. Format #include int sigmask (signum); 3 Argument signum The signal number for which the mask is to be constructed. 3 Description This function is used to contruct the mask for a given signum. This mask can be used with the sigblock function. 3 Return_Value x The mask constructed for signum 2 signal Allows you to specify the way in which the signal sig is to be handled: use the default handling for the signal, ignore the signal, or call the signal handler at the address specified. Format #include void (*signal (int sig, void (*func) (int))) (int); 3 Arguments sig The number or mnemonic associated with a signal. This argument is usually one of the mnemonics defined in the header file. func Either the action to take when the signal is raised, or the address of a function needed to handle the signal. 3 Description If func is the constant SIG_DFL, the action for the given signal is reset to the default action, which is to terminate the receiving process. If the argument is SIG_IGN, the signal is ignored. Not all signals can be ignored. If func is neither SIG_DFL nor SIG_IGN, it specifies the address of a signal-handling function. When the signal is raised, the addressed function is called with sig as its argument. When the addressed function returns, the interrupted process continues at the point of interruption. (This is called catching a signal. Signals are reset to SIG_DFL after they are caught, except as shown in the Error and Signal Handling chapter of the Compaq C RTL Reference Manual. You must call the signal function each time you want to catch a signal. See the "Error and Signal Handling" chapter of the Compaq C RTL Reference Manual for more information on signal handling. To cause a OpenVMS exception or a signal to generate a UNIX style signal, user OpenVMS condition handlers must return SS$_RESIGNAL upon receiving any exception that they do not want to handle. Returning SS$_CONTINUE prevents the correct generation of a UNIX style signal. 3 Return_Values x The address of the function previously established to handle the signal. SIG_ERR Indicates that the sig argument is out of range. 2 sigpause Assigns mask to the current set of masked signals and then waits for a signal. Format #include int sigpause (int mask); 3 Argument mask The signals to be blocked. 3 Description See the sigblock function for information about the mask argument. When control returns to sigpause, the function restores the previous set of masked signals, sets errno to EINTR, and returns -1 to indicate an interrupt. The value EINTR is defined in the header file. 3 Return_Value -1 Indicates an interrupt. errno is set to EINTR. 2 sigpending Examines pending signals. Format #include int sigpending (sigset_t *set); 3 Arguments set A pointer to a sigset_t structure. 3 Description This function stores the set of signals that are blocked from delivery and pending to the calling process in the location pointed to by the set argument. Call either the sigemptyset or the sigfillset function at least once for each object of type sigset_t prior to any other use of that object. If you do not initialize an object in this way and supply an argument to the sigpending function, the result is undefined. See sigemptyset, and sigfillset. 3 Return_Values 0 Indicates success. -1 Indicates an error; errno is set to the following value: o SIGSEGV - Bad mask argument. 2 sigprocmask Sets the current signal mask. Format #include int sigprocmask (int how, const sigset_t *set, sigset_t *o_set); 3 Arguments how An integer value that indicates how to change the set of masked signals. Use one of the following values: SIG_BLOCK The resulting set is the union of the current set and the signal set pointed to by the set argument. SIG_ The resulting set is the intersection of the current UNBLOCK set and the complement of the signal set pointed to by the set argument. SIG_ The resulting set is the signal set pointed to by the SETMASK set argument. set The signal set. If the value of the set argument is: o Not NULL - It points to a set of signals used to change the currently blocked set. o NULL - The value of the how argument is not significant, and the process signal mask is unchanged, so you can use the call to inquire about currently blocked signals. o_set A non-NULL pointer to the location where the signal mask in effect at the time of the call is stored. 3 Description This function is used to examine or change the signal mask of the calling process. Typically, use the sigprocmask SIG_BLOCK value to block signals during a critical section of code, then use the sigprocmask SIG_ SETMASK value to restore the mask to the previous value returned by the sigprocmask SIG_BLOCK value. If there are any unblocked signals pending after the call to the sigprocmask function, at least one of those signals is delivered before the sigprocmask function returns. You cannot block SIGKILL or SIGSTOP signals with the sigprocmask function. If a program attempts to block one of these signals, the sigprocmask function gives no indication of the error. 3 Example The following example shows how to set the signal mask to block only the SIGINT signal from delivery: #include int return_value; sigset_t newset; . . . sigemptyset(&newset); sigaddset(&newset, SIGINT); return_value = sigprocmask (SIG_SETMASK, &newset, NULL); 3 Return_Values 0 Indicates success. -1 Indicates an error. The signal mask of the process is unchanged. errno is set to one of the following values: o EINVAL - The value of the how argument is not equal to one of the defined values. o EFAULT - The set or o_set argument points to a location outside the allocated address space of the process. 2 sigsetjmp Sets jump point for a nonlocal goto. Format #include init sigsetjmp (sigjmp_buf env, int savemask); 3 Arguments env An address for a sigjmp_buf structure. savemask An integer value that specifies whether you need to save the current signal mask. 3 Description This function saves its calling environment in its env argument for later use by the siglongjmp function. If the value of savemask is not 0 (zero), sigsetjmp also saves the process' current signal mask as part of the calling environment. See also siglongjmp. 3 Restrictions You cannot invoke the longjmp function from an OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the Compaq C RTL, subject to the following nesting restrictions: o The longjmp function will not work if you invoke it from nested signal handlers. The result of the longjmp function, when invoked from a signal handler that has been entered as a result of an exception generated in another signal handler, is undefined. o Do not invoke the sigsetjmp function from a signal handler unless the associated longjmp is to be issued before the handling of that signal is completed. o Do not invoke the longjmp function from within an exit handler (established with atexit or SYS$DCLEXH). Exit handlers are invoked after image tear-down, so the destination address of the longjmp no longer exists. o Invoking longjmp from within a signal handler to return to the main thread of execution might leave your program in an inconsistent state. Possible side effects include the inability to perform I/O or to receive any more UNIX signals. Use siglongjmp instead. 3 Return_Values 0 Indicates success. nonzero The return is a call to the siglongjmp function. 2 sigsetmask Establishes those signals that are blocked from delivery. Format #include int sigsetmask (int mask); 3 Argument mask The signals to be blocked. 3 Description See the sigblock function for information about the mask argument. 3 Return_Value x The previous set of masked signals. 2 sigstack (VAX_only) Defines an alternate stack on which to process signals. This allows the processing of signals in a separate environment from that of the current process. This function is nonreentrant. Format #include int sigstack (struct sigstack *ss, struct sigstack *oss); 3 Arguments ss If ss is not NULL, it specifies the address of a structure that holds a pointer to a designated section of memory to be used as a signal stack on which to deliver signals. oss If oss is not NULL, it specifies the address of a structure in which the old value of the stack address is returned. 3 Description The sigstack structure is defined in the standard header file as follows: struct sigstack { char *ss_sp; int ss_onstack; }; If the sigvec function specifies that the signal handler is to execute on the signal stack, the system checks to see if the process is currently executing on that stack. If the process is not executing on the signal stack, the system arranges a switch to the signal stack for the duration of the signal handler's execution. If the oss argument is not NULL, the current state of the signal stack is returned. Signal stacks must be allocated an adequate amount of storage; they do not expand like the run-time stack. For example, if your signal handler calls printf or any similarly complex Compaq C RTL routine, at least 12,000 bytes of storage should be allocated for the signal stack. If the stack overflows, an error occurs. ss_sp must point to at least four bytes before the end of the allocated memory area (see the example). This is architecture-dependent and possibly not portable to other machine architectures or operating systems. The sigstack structure is defined in the header file. 3 Return_Values 0 Indicates success. -1 Indicates failure. 3 Example #define ss_size 15000 static char mystack[ss_size]; struct sigstack ss = {&mystack + sizeof(mystack) - sizeof(void *), 1}; 2 sigsuspend Atomically changes the set of blocked signals and waits for a signal. Format #include int sigsuspend (const sigset_t *signal_mask); 3 Arguments signal_mask A pointer to a set of signals. 3 Description This function replaces the signal mask of the process with the set of signals pointed to by the signal_mask argument. Then it suspends execution of the process until delivery of a signal whose action is either to execute a signal catching function or to terminate the process. You cannot block the SIGKILL or SIGSTOP signals with the sigsuspend function. If a program attempts to block either of these signals, sigsuspend gives no indication of the error. If delivery of a signal causes the process to terminate, sigsuspend does not return. If delivery of a signal causes a signal catching function to execute, sigsuspend returns after the signal catching function returns, with the signal mask restored to the set that existed prior to the call to sigsuspend. The sigsuspend function sets the signal mask and waits for an unblocked signal as one atomic operation. This means that signals cannot occur between the operations of setting the mask and waiting for a signal. If a program invokes sigprocmask SIG_ SETMASK and sigsuspend separately, a signal that occurs between these functions is often not noticed by sigsuspend. In normal usage, a signal is blocked by using the sigprocmask function at the beginning of a critical section. The process then determines whether there is work for it to do. If there is no work, the process waits for work by calling sigsuspend with the mask previously returned by sigprocmask. If a signal is caught by the calling process and control is returned from the signal handler, the calling process resumes execution after sigsuspend, which always returns a value of -1 and sets errno to EINTR. See also sigpause, and sigprocmask. 2 sigvec Permanently assigns a handler for a specific signal. Format #include int sigvec (int sigint, struct sigvec *sv, struct sigvec *osv); 3 Arguments sigint The signal identifier. sv Pointer to a sigvec structure (see the Description section). osv If osv is not NULL, the previous handling information for the signal is returned. 3 Description If sv is not NULL, it specifies the address of a structure containing a pointer to a handler routine and mask to be used when delivering the specified signal, and a flag indicating whether the signal is to be processed on an alternative stack. If sv->onstack has a value of 1, the system delivers the signal to the process on a signal stack specified with sigstack. The sigvec function establishes a handler that remains established until explicitly removed or until the image terminates. The sigvec structure is defined in the header file as follows: struct sigvec { int (*handler)(); int mask; int onstack; }; See the "Error and Signal Handling" chapter of the Compaq C RTL Reference Manual for more information on signal handling. 3 Return_Values 0 Indicates that the call succeeded. -1 Indicates that an error occurred. 2 sin Returns the sine of its radian argument. Format #include double sin (double x); float sinf (float x); (Alpha only) long double sinl (long double x); (Alpha only) double sind (double x); (Alpha only) float sindf (float x); (Alpha only) long double sindl (long double x); (Alpha only) 3 Argument x A radian expressed as a floating-point number. 3 Description The sin functions compute the sine of x measured in radians. The sind functions compute the sine of x measured in degrees. 3 Return_Values x The sine of the argument. NaN x = 0 Undeflow occurred; errno is set to ERANGE. 2 sinh Returns the hyperbolic sine of its argument. Format #include double sinh (double x); float sinhf (float x); (Alpha only) long double sinhl (long double x); (Alpha only) 3 Argument x A real number. 3 Return_Values n The hyperbolic sine of the argument. HUGE_VAL Overflow occurred; errno is set to ERANGE. 0 Underflow occurred; errno is set to ERANGE. NaN x is NaN; errno is set to EDOM. 2 sleep Suspends the execution of the current process for at least the number of seconds indicated by its argument. Format #include unsigned int sleep (unsigned seconds); (_DECC_V4_SOURCE) int sleep (unsigned seconds); (not _DECC_V4_SOURCE) 3 Argument seconds The number of seconds. 3 Description This function sleeps for the specified number of seconds, or until a signal is received, or until the process executes a call to SYS$WAKE. If a SIGALRM signal is generated, but blocked or ignored, the sleep function returns. For all other signals, a blocked or ignored signal does not cause sleep to return. 3 Return_Values x The number of seconds that the process awoke early. 0 If the process slept the full number of seconds specified by seconds 2 sprintf Performs formatted output to a string in memory. Format #include int sprintf (char *str, const char *format_spec, . . . ); 3 Arguments str The address of the string that will receive the formatted output. It is assumed that this string is large enough to hold the output. format_spec A pointer to a character string that contains the format specification. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you may omit the output sources. Otherwise, the function calls must have at least as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Excess output pointers, if any, are ignored. 3 Description A null character is automatically appended to the end of the output string. Consider the following example of a conversion specification: #include main() { int temp = 4, temp2 = 17; char s[80]; sprintf(s, "The answers are %d, and %d.", temp, temp2); } In this example, character string s has the following contents: The answers are 4, and 17. 3 Return_Value x The number of characters placed in the output string, not including the final null character. Negative value Indicates an output error occurred. The function sets errno. For a list of errno values set by this function, see fprintf. 2 sqrt Returns the square root of its argument. Format #include double sqrt (double x); float sqrtf (float x); (Alpha only) long double sqrtl (long double x); (Alpha only) 3 Argument x A real number. 3 Return_Values val The square root of x, if x is nonnegative. 0 x is negative; errno is set to EDOM. NaN x is NaN; errno is set to EDOM. 2 srand Initializes the pseudorandom number generator rand. Format #include void srand (unsigned int seed); 3 Argument seed An unsigned integer. 3 Description This function uses the argument as a seed for a new sequence of pseudorandom numbers to be returned by subsequent calls to rand. If rand is called before any calls to srand, the sequence of pseudorandom numbers is generated as if the seed were set to 1. 2 srand48 Initializes a 48-bit random number generator. Format #include void srand48 (long int seed_val); 3 Arguments seed_val The initialization value to begin randomization. Changing this value changes the randomization pattern. 3 Description This function initializes the random number generator. You can use this function in your program before calling the drand48, lrand48, or mrand48 functions. (Although it is not recommended practice, constant default initializer values are supplied automatically if you call drand48, lrand48, or mrand48 without calling an initialization function). The function works by generating a sequence of 48-bit integer values, Xi, according to the linear congruential formula: Xn+1 = (aXn+c)mod m n >= 0 The argument m equals 248, so 48-bit integer arithmetic is performed. Unless you invoke the lcong48 function, the multiplier value a and the addend value c are: a = 5DEECE66D16 = 2736731631558 c = B16 = 138 The initializer function srand48 sets the high-order 32 bits of Xi to the low-order 32 bits contained in its argument. The low-order 16 bits of Xi are set to the arbitrary value 330E16. See also drand48, lrand48, and mrand48. 2 srandom Initializes the pseudorandom number generator random. Format int srandom (unsigned seed); 3 Arguments seed An initial seed value. 3 Description This function uses the argument as a seed for a new sequence of pseudorandom numbers to be returned by subsequent calls to random. This function has virtually the same calling sequence and initialization properties as the srand function, but produce sequences that are more random. The srandom function initializes the current state with the initial seed value. The srandom function, unlike the srand function, does not return the old seed because the amount of state information used is more than a single word. See also rand, srand, random, setstate, and initstate. 3 Return_Values 0 Indicates success. Initializes the state seed. -1 Indicates an error, further specified in the global errno. 2 sscanf Reads input from a character string in memory, interpreting it according to the format specification. Format #include int sscanf (const char *str, const char *format_spec, . . . ); 3 Arguments str The address of the character string that provides the input text to sscanf. format_spec A pointer to a character string that contains the format specification. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have at least as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description The following is an example of a conversion specification: main () { char str[] = "4 17"; int temp, temp2; sscanf(str, "%d %d", &temp, &temp2); printf("The answers are %d and %d.", temp, temp2); } This example produces the following output: $ RUN EXAMPLE The answers are 4 and 17. 3 Return_Values x The number of successfully matched and assigned input items. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see fscanf. 2 ssignal Allows you to specify the action to take when a particular signal is raised. Format #include void (*ssignal (int sig, void (*func) (int, . . . ))) (int, . . . ); 3 Arguments sig A number or mnemonic associated with a signal. The symbolic constants for signal values are defined in the header file. See the Error and Signal Handling chapter of the Compaq C RTL Reference Manual. func The action to take when the signal is raised, or the address of a function that is executed when the signal is raised. 3 Description This function is equivalent to the signal function except for the return value on error conditions. Since the signal function is defined by the ANSI C standard and the ssignal function is not, use signal for greater portability. See the "Error and Signal Handling" chapter of the Compaq C RTL Reference Manual for more information on signal handling. 3 Return_Values x The address of the function previously established as the action for the signal. The address may be the value SIG_DFL (0) or SIG_IGN (1). 0 Indicates errors. For this reason, there is no way to know whether a return status of 0 indicates failure, or whether it indicates that a previous action was SIG_DFL (0). 2 [w]standend Deactivate the boldface attribute for the specified window. The standend function operates on the stdscr window. Format #include int standend (void); int wstandend (WINDOW *win); 3 Argument win A pointer to the window. 3 Description The standend and wstandend functions are equivalent to clrattr and wclrattr called with the attribute _BOLD. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 [w]standout Activate the boldface attribute of the specified window. The standout function acts on the stdscr window. Format #include int standout (void); int wstandout (WINDOW *win); 3 Argument win A pointer to the window. 3 Description The standout and wstandout functions are equivalent to setattr and wsetattr called with the attribute _BOLD. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 stat Accesses information about the specified file. Format #include int stat (const char *file_spec, struct stat *buffer); (ISO POSIX-1) int stat (const char *file_spec, struct stat *buffer, . . . ); (DEC C Extension) 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Arguments file_spec A valid OpenVMS or UNIX style file specification (no wildcards). Read, write, or execute permission of the named file is not required, but you must be able to reach all directories listed in the file specification leading to the file. buffer A pointer to a structure of type stat_t that is defined in the header file. The argument receives information about the particular file. The members of the structure pointed to by buffer are described as follows: Member Type Definition st_dev dev_t Pointer to the physical device name st_ ino_t Three words to receive the file ID ino[3] st_mode mode_t File "mode" (prot, dir, . . . ) st_nlink nlink_t For UNIX system compatibility only st_uid uid_t Owner user ID st_gid gid_t Group member: from st_uid st_rdev dev_t UNIX system compatibility - always 0 st_size off_t File size, in bytes st_atime time_t File access time; always the same as st_ mtime st_mtime time_t Last modification time st_ctime time_t File creation time st_fab_ char Record format rfm st_fab_ char Record attributes rat st_fab_ char Fixed header size fsz st_fab_ unsigned Record size mrs The types dev_t, ino_t, off_t, mode_t, nlink_t, uid_t, gid_t, and time_t, are defined in the header file. However, when compiling for compatibility (/DEFINE=_DECC_V4_SOURCE), only dev_ t, ino_t, and off_t are defined. The off_t data type is either a 32-bit integer or 64-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE As of OpenVMS Version 7.0, times are given in seconds since the Epoch (00:00:00 GMT, January 1, 1970). The st_mode structure member is the status information mode defined in the header file. The st_mode bits are described as follows: Bits Constant Definition 0170000 S_IFMT Type of file 0040000 S_ Directory IFDIR 0020000 S_ Character special IFCHR 0060000 S_ Block special IFBLK 0100000 S_ Regular IFREG 0030000 S_ Multiplexed char special IFMPC 0070000 S_ Multiplexed block special IFMPB 0004000 S_ Set user ID on execution ISUID 0002000 S_ Set group ID on execution ISGID 0001000 S_ Save swapped text even after use ISVTX 0000400 S_ Read permission, owner IREAD 0000200 S_ Write permission, owner IWRITE 0000100 S_ Execute/search permission, owner IEXEC . . . An optional default file-name string. This is the only optional RMS keyword that can be specified for the stat function. See the description of the creat function for the full list of optional RMS keywords and their values. 3 Description This function does not work on remote network files. If the file is a record file, the st_size field includes carriage-control information. Consequently, the st_size value will not correspond to the number of characters that can be read from the file. The physical device name string referred to by the st_dev member of the stat structure is overwritten by the next stat call. NOTE (Alpha only) On OpenVMS Alpha systems, the stat, fstat, utime, and utimes functions have been enhanced to take advantage of the new file-system support for POSIX-compliant file timestamps. This support is available only on ODS-5 devices on OpenVMS Alpha systems beginning with a version of OpenVMS Alpha after Version 7.3. Before this change, the stat and fstat functions were setting the values of the st_ctime, st_mtime, and st_atime fields based on the following file attributes: st_ctime - ATR$C_CREDATE (file creation time) st_mtime - ATR$C_REVDATE (file revision time) st_atime - was always set to st_mtime because no support for file access time was available Also, for the file-modification time, utime and utimes were modifying the ATR$C_REVDATE file attribute, and ignoring the file-access-time argument. After the change, for a file on an ODS-5 device, the stat and fstat functions set the values of the st_ctime, st_ mtime, and st_atime fields based on the following new file attributes: st_ctime - ATR$C_ATTDATE (last attribute modification time) st_mtime - ATR$C_MODDATE (last data modification time) st_atime - ATR$C_ACCDATE (last access time) If ATR$C_ACCDATE is zero, as on an ODS-2 device, the stat and fstat functions set st_atime to st_mtime. For the file-modification time, the utime and utimes functions modify both the ATR$C_REVDATE and ATR$C_MODDATE file attributes. For the file-access time, these functions modify the ATR$C_ACCDATE file attribute. Setting the ATR$C_ MODDATE and ATR$C_ACCDATE file attributes on an ODS-2 device has no effect. For compatibility, the old behavior of stat, fstat, utime and utimes remains the default, regardless of the kind of device. The new behavior must be explicitly enabled by defining the DECC$EFS_FILE_TIMESTAMPS logical name to "ENABLE" before invoking the application. Setting this logical does not affect the behavior of stat, fstat, utime and utimes for files on an ODS-2 device. 3 Return_Values 0 Indicates success. -1 Indicates an error other than a privilege violation; errno is set to indicate the error. -2 Indicates a privilege violation. 2 strcasecmp Does a case-insensitive comparison of two 7-bit ASCII strings. Format #include int strcasecmp (const char *s1, const char *s2); 3 Arguments s1 The first of two strings to compare. s2 The second of two strings to compare. 3 Description This function is case-insensitive. The returned lexicographic difference reflects a conversion to lowercase. The strcasecmp function works for 7-bit ASCII compares only. Do not use this function for internationalized applications. 3 Return_Values n An integer value greater than, equal to, or less than 0 (zero), depending on whether the s1 string is greater than, equal to, or less than the s2 string. 2 strcat Concatenates str_2, including the terminating null character, to the end of str_1. Format #include char *strcat (char *str_1, const char *str_2); 3 Function_Variants This function also has variants named _strcat32 and _strcat64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str_1, str_2 Pointers to null-terminated character strings. 3 Description See also strncat. 3 Return_Value x The address of the first argument, str_1, which is assumed to be large enough to hold the concatenated result. 3 Example #include #include /* This program concatenates two strings using the strcat */ /* function, and then manually compares the result of strcat */ /* to the expected result. */ #define S1LENGTH 10 #define S2LENGTH 8 main() { static char s1buf[S1LENGTH + S2LENGTH] = "abcmnexyz"; static char s2buf[] = " orthis"; static char test1[] = "abcmnexyz orthis"; int i; char *status; /* Take static buffer s1buf, concatenate static buffer */ /* s2buf to it, and compare the answer in s1buf with the */ /* static answer in test1. */ status = strcat(s1buf, s2buf); for (i = 0; i <= S1LENGTH + S2LENGTH - 2; i++) { /* Check for correct returned string. */ if (test1[i] != s1buf[i]) printf("error in strcat"); } } 2 strchr Returns the address of the first occurrence of a given character in a null-terminated string. The terminating null character is considered to be part of the string. Format #include char *strchr (const char *str, int character); 3 Function_Variants This function also has variants named _strchr32 and _strchr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str A pointer to a null-terminated character string. character An object of type int. 3 Description See also strrchr. 3 Return_Values x The address of the first occurrence of the specified character. NULL Indicates that the character does not occur in the string. 3 Example #include #include main() { static char s1buf[] = "abcdefghijkl lkjihgfedcba"; int i; char *status; /* This program checks the strchr function by incrementally */ /* going through a string that ascends to the middle and then */ /* descends towards the end. */ for (i = 0; s1buf[i] != '\0' && s1buf[i] != ' '; i++) { status = strchr(s1buf, s1buf[i]); /* Check for pointer to leftmost character - test 1. */ if (status != &s1buf[i]) printf("error in strchr"); } } 2 strcmp Compares two ASCII character strings and returns a negative, 0, or positive integer, indicating that the ASCII values of the individual characters in the first string are less than, equal to, or greater than the values in the second string. Format #include int strcmp (const char *str_1, const char *str_2); 3 Arguments str_1, str_2 Pointers to character strings. 3 Description The strings are compared until a null character is encountered or until the strings differ. 3 Return_Values < 0 Indicates that str_1 is less than str_2. = 0 Indicates that str_1 equals str_2. > 0 Indicates that str_1 is greater than str_2. 2 strcoll Compares two strings and returns an integer that indicates if the strings differ and how they differ. The function uses the collating information in the LC_COLLATE category of the current locale to determine how the comparison is performed. Format #include int strcoll (const char *s1, const char *s2); 3 Arguments s1, s2 Pointers to character strings. 3 Description This function, unlike strcmp, compares two strings in a locale- dependent manner. Because no value is reserved for error indication, the application must check for one by setting errno to 0 before the function call and testing it after the call. See also the strxfrm function. 3 Return_Values < 0 Indicates that s1 is less than s2. = 0 Indicates that the strings are equal. > 0 Indicates that s1 is greater than s2. 2 strcpy Copies all of source, including the terminating null character, into dest. Format #include char *strcpy (char *dest, const char *source); 3 Function_Variants This function also has variants named _strcpy32 and _strcpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest Pointer to the destination character string. source Pointer to the source character string. 3 Description This function copies source into dest, and stops after copying source's null character. The behavior of this function is undefined if the area pointed to by dest overlaps the area pointed to by source. 3 Return_Value x The address of dest. 2 strcspn Returns the length of the prefix of a string that consists entirely of characters not in a specified set of characters. Format #include size_t strcspn (const char *str, const char *charset); 3 Arguments str A pointer to a character string. If this character string is a null string, 0 is returned. charset A pointer to a character string containing the set of characters. 3 Description This function scans the characters in the string, stops when it encounters a character found in charset, and returns the length of the string's initial segment formed by characters not found in charset. If none of the characters match in the character strings pointed to by str and charset, strcspn returns the length of string. 3 Return_Value x The length of the segment. 2 strdup Finds and points to a duplicate string. Format #include char *strdup (const char *s1); 3 Function_Variants This function also has variants named _strdup32 and _strdup64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s1 The first of two strings to compare. 3 Description This function returns a pointer to a string that is an exact duplicate of the string pointed to by s1. The malloc function is used to allocate space for the new string. The strdup function is provided for compatibility with existing systems. 3 Return_Values x A pointer to the resulting string. NULL Indicates an error. 2 strerror Maps the error number in error_code to a locale-dependent error message string. Format #include char *strerror (int error_code); (ANSI C) char *strerror (int error_code[, int vms_error_code]); (DEC C Extension) 3 Arguments error_code An error code. vms_error_code An OpenVMS error code. 3 Description This function uses the error number in error_code to retrieve the appropriate locale-dependent error message. The contents of the error message strings are determined by the LC_MESSAGES category of the program's current locale. When a program is not compiled with any standards-related feature-test macros, strerror has a second argument (vms_error_ code), which is used in the following way: o If error_code is EVMSERR and there is a second argument, then that second argument is used as the vaxc$errno value. o If error_code is EVMSERR and there is no second argument, look at vaxc$errno to get the OpenVMS error condition. See the strerror example. Use of the second argument is not included in the ANSI C definition of strerror and is, therefore, not portable. Because no return value is reserved to indicate an error, applications should set the value of errno to 0, call strerror, and then test the value of errno; a nonzero value indicates an error condition. 3 Return_Values x A pointer to a buffer containing the appropriate error message. Do not modify this buffer in your programs. Moreover, calls to the strerror function may overwrite this buffer with a new message. 3 Example #include #include #include #include #include main() { puts(strerror(EVMSERR)); errno = EVMSERR; vaxc$errno = SS$_LINKEXIT; puts(strerror(errno)); puts(strerror(EVMSERR, SS$_ABORT)); exit(1); } Running this example produces the following output: non-translatable vms error code: network partner exited abort 2 strfmon Converts a number of monetary values into a string. The conversion is controlled by a format string. Format #include ssize_t strfmon (char *s, size_t maxsize, const char *format, . . . ); 3 Arguments s A pointer to the resultant string. maxsize The maximum number of bytes to be stored in the resultant string. format A pointer to a string that controls the format of the output string. . . . The monetary values of type double that are to be formatted for the output string. There should be as many values as there are conversion specifications in the format string pointed to by format. The function fails if there are insufficient values. Excess arguments are ignored. 3 Description This function creates a string pointed to by s, using the monetary values supplied. A maximum of maxsize bytes is copied to s. The format string pointed to by format consists of ordinary characters and conversion specifications. All ordinary characters are copied unchanged to the output string. A conversion specification defines how one of the monetary values supplied is formatted in the output string. A conversion specification consists of a percent character (%), followed by a number of optional characters (see Optional Characters in strfmon Conversion Specifications), and concluding with a conversion specifier (see strfmon Conversion Specifiers). If any of the optional characters listed in Optional Characters in strfmon Conversion Specifications is included in a conversion specification, they must appear in the order shown. Table REF-5 Optional Characters in strfmon Conversion Specifications Character Meaning =character Use character as the numeric fill character if a left precision is specified. The default numeric fill character is the space character. The fill character must be representable as a single byte in order to work with precision and width count. This conversion specifier is ignored unless a left precision is specified, and it does not affect width filling, which always uses the space character. ^ Do not use separator characters to format the number. By default, the digits are grouped according to the mon_grouping field in the LC_ MONETARY category of the current locale. + Add the string specified by the positive_sign or negative_sign fields in the current locale. If p_sign_posn or n_sign_posn is set to zero, then parentheses are used by default to indicate negative values. Otherwise, sign strings are used to indicate the sign of the value. You cannot use a + and a ( in the same conversion specification. ( Enclose negative values within parentheses. The default is taken from the p_sign_posn and n_sign_ posn fields in the current locale. If p_sign_posn or n_sign_posn is set to zero, then parentheses are used by default to indicate negative values. Otherwise, sign strings are used to indicate the sign of the value. You cannot use a + and ( in the same conversion specification. ! Suppress the currency symbol. By default, the currency symbol is included. - Left-justify the value within the field. By default, values are right-justified. field width A decimal integer that specifies the minimum field width in which to align the result of the conversion. The default field width is the smallest field that can contain the result. #left_ A # followed by a decimal integer specifies precision the number of digits to the left of the radix character. Extra positions are filled by the fill character. By default the precision is the smallest required for the argument. If grouping is not suppressed with the ^ conversion specifier, and if grouping is defined for the current locale, grouping separators are inserted before any fill characters are added. Grouping separators are not applied to fill characters even if the fill character is defined as a digit. .right_ A period (.) followed by a decimal integer precision specifies the number of digits to the right of the radix character. Extra positions are filled with zeros. The amount is rounded to this number of decimal places. If the right precision is zero, the radix character is not included in the output. By default the right precision is defined by the frac_digits or int_frac_digits field of the current locale. Table REF-6 strfmon Conversion Specifiers SpecifierMeaning i Use the international currency symbol defined by the int_currency_symbol field in the current locale, unless the currency symbol has been suppressed. n Use the local currency symbol defined by the currency_ symbol field in the current locale, unless the currency symbol has been suppressed. % Output a % character. The conversion specification must be %%; none of the optional characters is valid with this specifier. 3 Return_Values x The number of bytes written to the string pointed to by s, not including the null terminating character. -1 Indicates an error.The function sets errno to one of the following values: o EINVAL - A conversion specification is syntactically incorrect. o E2BIG - Processing the complete format string would produce more than maxsize bytes. 3 Example #include #include #include #include #include #define MAX_BUF_SIZE 124 main() { size_t ret; char buffer[MAX_BUF_SIZE]; double amount = 102593421; /* Display a monetary amount using the en_US.ISO8859-1 */ /* locale and a range of different display formats. */ if (setlocale(LC_ALL, "en_US.ISO8859- 1") == (char *) NULL) { perror("setlocale"); exit(EXIT_FAILURE); } ret = strfmon(buffer, MAX_BUF_ SIZE, "International: %i\n", amount); printf(buffer); ret = strfmon(buffer, MAX_BUF_ SIZE, "National: %n\n", amount); printf(buffer); ret = strfmon(buffer, MAX_BUF_ SIZE, "National: %=*#10n\n", amount); printf(buffer); ret = strfmon(buffer, MAX_BUF_ SIZE, "National: %(n\n", -1 * amount); printf(buffer); ret = strfmon(buffer, MAX_BUF_ SIZE, "National: %^!n\n", amount); printf(buffer); } Running the example program produces the following result: International: USD 102,593,421.00 National: $102,593,421.00 National: $**102,593,421.00 National: ($102,593,421.00) National: 102593421.00 2 strftime Uses date and time information stored in a tm structure, to create an output string. The format of the output string is controlled by a format string. Format #include size_t strftime (char *s, size_t maxsize, const char *format, const struct tm *timeptr); 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Arguments s A pointer to the resultant string. maxsize The maximum number of bytes to be stored in the resultant string, including the null terminator. format A pointer to a string that controls the format of the output string. timeptr A pointer to the local time (tm) structure. The tm structure is defined in the header file. 3 Description This function uses data in the structure pointed to by timeptr to create the string pointed to by s. A maximum of maxsize bytes is copied to s. The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters (including the terminating null character) are copied unchanged into the output string. A conversion specification defines how data in the tm structure is formatted in the output string. A conversion specification consists of a percent (%) character followed by one or more optional characters (see Optional Elements of strftime Conversion Specifications), and concluding with a conversion specifier (see strftime Conversion Specifiers). If any of the optional characters listed in Optional Elements of strftime Conversion Specifications are specified, they must appear in the order shown in the table. The strftime function behaves as if it called tzset. Table REF-7 Optional Elements of strftime Conversion Specifications Element Meaning - Optional with the field width to specify that the field is left-justified and padded with spaces. This cannot be used with the 0 element. 0 Optional with the field width to specify that the field is right-justified and padded with zeros. This cannot be used with the - element. field A decimal integer that specifies the maximum field width width .precisioA decimal integer that specifies the precision of data in a field. For the d, H, I, j, m, M, o, S, U, w, W, y and Y conversion specifiers, the precision specifier is the minimum number of digits to appear in the field. If the conversion specification has fewer digits than that specified by the precision, leading zeros are added. For the a, A, b, B, c, D, E, h, n, N, p, r, t, T, x, X, Z, and % conversion specifiers, the precision specifier is the maximum number of characters to appear in the field. If the conversion specification has more characters than that specified by the the precision, characters are truncated on the right. The default precision for the d, H, I, m, M, o, S, U, w, W, y and Y conversion specifiers is 2; the default precision for the j conversion specifier is 3. Note that the list of conversion specifications in Optional Elements of strftime Conversion Specifications are extensions to the XPG4 specification. strftime Conversion Specifiers lists the conversion specifiers. The strftime function uses fields in the LC_TIME category of the program's current locale to provide a value. For example, if %B is specified, the function accesses the mon field in LC_TIME to find the full month name for the month specified in the tm structure. The result of using invalid conversion specifiers is undefined. Table REF-8 strftime Conversion Specifiers Specifier Replaced by a The locale's abbreviated weekday name A The locale's full weekday name b The locale's abbreviated month name B The locale's full month name c The locale's appropriate date and time representation C The century number (the year divided by 100 and truncated to an integer) as a decimal number (00 - 99) d The day of the month as a decimal number (01 - 31) D Same as %m/%d/%y e The day of the month as a decimal number (1 - 31) in a 2 digit field with the leading space character fill Ec The locale's alternative date and time representation EC The name of the base year (period) in the locale's alternative representation Ex The locale's alternative date representation EX The locale's alternative time representation Ey The offset from the base year (%EC) in the locale's alternative representation EY The locale's full alternative year representation h Same as %b H The hour (24-hour clock) as a decimal number (00 - 23) I The hour (12-hour clock) as a decimal number (01 - 12) j The day of the year as a decimal number (001 - 366) m The month as a decimal number (01 - 12) M The minute as a decimal number (00 - 59) n The newline character Od The day of the month using the locale's alternative numeric symbols Oe The date of the month using the locale's alternative numeric symbols OH The hour (24-hour clock) using the locale's alternative numeric symbols OI The hour (12-hour clock) using the locale's alternative numeric symbols Om The month using the locale's alternative numeric symbols OM The minutes using the locale's alternative numeric symbols OS The seconds using the locale's alternative numeric symbols Ou The weekday as a number in the locale's alternative representation (Monday=1) OU The week number of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols OV The week number of the year (Monday as the first day of the week) as a decimal number (01 -53) using the locale's alterntative numeric symbols. If the week containing January 1 has four or more days in the new year, it is considered as week 1. Otherwise, it is considered as week 53 of the previous year, and the next week is week 1. Ow The weekday as a number (Sunday=0) using the locale's alternative numeric symbols OW The week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols Oy The year without the century using the locale's alternative numeric symbols p The locale's equivalent of the AM/PM designations associated with a 12-hour clock r The time in AM/PM notation R The time in 24-hour notation (%H:%M) S The second as a decimal number (00 - 61) t The tab character T The time (%H:%M:%S) u The weekday as a decimal number between 1 and 7 (Monday=1) U The week number of the year (the first Sunday as the first day of week 1) as a decimal number (00 - 53) V The week number of the year (Monday as the first day of the week) as a decimal number (00 - 53). If the week containing January 1 has four or more days in the new year, it is considered as week 1. Otherwise, it is considered as week 53 of the previous year, and the next week is week 1. w The weekday as a decimal number (0 [Sunday] - 6) W The week number of the year (the first Monday as the first day of week 1) as a decimal number (00 - 53) x The locale's appropriate date representation X The locale's appropriate time representation y The year without century as a decimal number (00 - 99) Y The year with century as a decimal number Z Time-zone name or abbreviation. If time-zone information is not available, no character is output. % % 3 Return_Values x The number of characters placed into the array pointed to by s, not including the terminating null character. 0 Indicates an error occurred. The contents of the array are indeterminate. 3 Example #include #include #include #include #include #define NUM_OF_DATES 7 #define BUF_SIZE 256 /* This program formats a number of different dates, once */ /* using the C locale and then using the fr_FR.ISO8859-1 */ /* locale. Date and time formatting is done using strftime().*/ main() { int count, i; char buffer[BUF_SIZE]; struct tm *tm_ptr; time_t time_list[NUM_OF_DATES] = {500, 68200000, 694223999, 694224000, 704900000, 705000000, 705900000}; /* Display dates using the C locale */ printf("\nUsing the C locale:\n\n"); setlocale(LC_ALL, "C"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = strftime(buffer, BUF_SIZE, "Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("strftime"); exit(EXIT_FAILURE); } /* Print the result */ printf(buffer); } /* Display dates using the fr_FR.ISO8859-1 locale */ printf("\nUsing the fr_FR.ISO8859-1 locale:\n\n"); setlocale(LC_ALL, "fr_FR.ISO8859-1"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = strftime(buffer, BUF_SIZE, "Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("strftime"); exit(EXIT_FAILURE); } /* Print the result */ printf(buffer); } } Running the example program produces the following result: Using the C locale: Date: Thursday 01 January 1970 Time: 00:08:20 Date: Tuesday 29 February 1972 Time: 08:26:40 Date: Tuesday 31 December 1991 Time: 23:59:59 Date: Wednesday 01 January 1992 Time: 00:00:00 Date: Sunday 03 May 1992 Time: 13:33:20 Date: Monday 04 May 1992 Time: 17:20:00 Date: Friday 15 May 1992 Time: 03:20:00 Using the fr_FR.ISO8859-1 locale: Date: jeudi 01 janvier 1970 Time: 00:08:20 Date: mardi 29 février 1972 Time: 08:26:40 Date: mardi 31 décembre 1991 Time: 23:59:59 Date: mercredi 01 janvier 1992 Time: 00:00:00 Date: dimanche 03 mai 1992 Time: 13:33:20 Date: lundi 04 mai 1992 Time: 17:20:00 Date: vendredi 15 mai 1992 Time: 03:20:00 2 strlen Returns the length of a string of ASCII characters. The returned length does not include the terminating null character (\0). Format #include size_t strlen (const char *str); 3 Argument str A pointer to the character string. 3 Return_Value x The length of the string. 2 strncasecmp Does a case-insensitive comparison between two 7-bit ASCII strings. Format #include int strncasecmp (const char *s1, const char *s2, size_t n); 3 Arguments s1 The first of two strings to compare. s2 The second of two strings to compare. n The maximum number of bytes in a string to compare. 3 Description This function is case-insensitive. The returned lexicographic difference reflects a conversion to lowercase. The strncasecmp function is similar to the strcasecmp function, but also compares size. If the size specified by n is read before a NULL, the comparison stops. The strcasecmp function works for 7-bit ASCII compares only. Do not use this function for internationalized applications. 3 Return_Values n An integer value greater than, equal to, or less than 0 (zero), depending on whether s1 is greater than, equal to, or less than s2. 2 strncat Appends not more than maxchar characters from str_2 to the end of str_1. Format #include char *strncat (char *str_1, const char *str_2, size_t maxchar); 3 Function_Variants This function also has variants named _strncat32 and _strncat64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str_1, str_2 Pointers to null-terminated character strings. maxchar The number of characters to concatenate from str_2, unless strncat first encounters a null terminator in str_2. If maxchar is 0, no characters are copied from str_2. 3 Description A null character is always appended to the result of the strncat function. If strncat reaches the specified maximum, it sets the next byte in str_1 to the null character. 3 Return_Value x The address of the first argument, str_1, which is assumed to be large enough to hold the concatenated result. 2 strncmp Compares not more than maxchar characters of two ASCII character strings and returns a negative, 0, or positive integer, indicating that the ASCII values of the individual characters in the first string are less than, equal to, or greater than the values in the second string. Format #include int strncmp (const char *str_1, const char *str_2, size_t maxchar); 3 Arguments str_1, str_2 Pointers to character strings. maxchar The maximum number of characters (beginning with the first) to search in both str_1 and str_2. If maxchar is 0, no comparison is performed and 0 is returned (the strings are considered equal). 3 Description This function compares no more than maxchar characters from the string pointed to by str_1 to the string pointed to by str_2. The strings are compared until a null character is encountered, the strings differ, or maxchar is reached. Characters that follow a difference or a null character are not compared. 3 Return_Values < 0 Indicates that str_1 is less than str_2. = 0 Indicates that str_1 equals str_2. > 0 Indicates that str_1 is greater than str_2. 3 Examples 1.#include #include main() { printf( "%d\n", strncmp("abcde", "abc", 3)); } When linked and executed, this example returns 0, because the first 3 characters of the 2 strings are equal: $ run tmp 0 2.#include #include main() { printf( "%d\n", strncmp("abcde", "abc", 4)); } When linked and executed, this example returns a value greater than 0 because the first 4 characters of the 2 strings are not equal (The "d" in the first string is not equal to the null character in the second): $ run tmp 100 2 strncpy Copies not more than maxchar characters from source into dest. Format #include char *strncpy (char *dest, const char *source, size_t maxchar); 3 Function_Variants This function also has variants named _strncpy32 and _strncpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest Pointer to the destination character string. source Pointer to the source character string. maxchar The maximum number of characters to copy from source to dest up to but not including the null terminator of source. 3 Description This function copies no more than maxchar characters from source to dest, up to but not including the null terminator of source. If source contains less than maxchar characters, dest is padded with null characters. If source contains greater than or equal to maxchar characters, as many characters as possible are copied to dest. Be aware that the dest argument might not be terminated by a null character after a call to strncpy. 3 Return_Value x The address of dest. 2 strnlen Returns the number of bytes in a string. Format #include size_t strnlen (const char *s, size_t n); 3 Arguments s Pointer to the string. n The maximum number of characters to examine. 3 Description This function returns the number of bytes in the string pointed to by s. The string length value does not include the terminating null character. The strnlen function counts bytes until the first null byte or until n bytes have been examined. 3 Return_Values n The length of the string. 2 strpbrk Searches a string for the occurrence of one of a specified set of characters. Format #include char *strpbrk (const char *str, const char *charset); 3 Function_Variants This function also has variants named _strpbrk32 and _strpbrk64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str A pointer to a character string. If this character string is a null string, 0 is returned. charset A pointer to a character string containing the set of characters for which the function will search. 3 Description This function scans the characters in the string, stops when it encounters a character found in charset, and returns the address of the first character in the string that appears in the character set. 3 Return_Values x The address of the first character in the string that is in the set. NULL Indicates that no character is in the set. 2 strptime Converts a character string into date and time values that are stored in a tm structure. Conversion is controlled by a format string. Format #include char *strptime (const char *buf, const char *format, struct tm *timeptr); 3 Function_Variants This function also has variants named _strptime32 and _strptime64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments buf A pointer to the character string to convert. format A pointer to the string that defines how the input string is converted. timeptr A pointer to the local time structure. The tm structure is defined in the header file. 3 Description This function converts the string pointed to by buf into values that are stored in the structure pointed to by timeptr. The string pointed to by format defines how the conversion is performed. The strptime function modifies only those fields in the tm structure that have corresponding conversion specifications in the format. In particular, strptime never sets the tm_isdst member of the tm structure. The format string consists of zero or more directives. A directive is composed of one of the following: o One or more white-space characters (as defined by the isspace function). This directive causes the function to read input up to the first character that is not a white-space character. o Any character other than the percent character (%) or a white- space character. This directive causes the function to read the next character. The character read must be the same as the character that comprises the directive. If the character is different, the function fails. o A conversion specification. A conversion specification defines how characters in the input string are interpreted as values that are then stored in the tm structure. A conversion specification consists of a percent (%) character followed by a conversion specifier. strptime Conversion Specifications lists the valid conversion specifications. The strptime function uses fields in the LC_TIME category of the program's current locale to provide a value. NOTE To be compliant with X/Open CAE Specification System Interfaces and Headers Issue 5 (commonly known as XPG5), the strptime function processes the "%y" directive differently than in previous versions of the Compaq C RTL. With Compaq C Version 6.4 and higher, for a two-digit year within the century if no century is specified, "%y" directive values ranging from: o 69 to 99 refer to years in the twentieth century (1969 to 1999 inclusive) o 00 to 68 refer to years in the twenty-first century (2000 to 2068 inclusive) In previous (XPG4-compliant) versions of the Compaq C RTL, strptime interpreted a two-digit year with no century specified as a year within the twentieth century. The XPG5-compliant strptime is now the default version in the Compaq C RTL. To obtain the old, XPG4-compliant strptime function behavior, specify one of the following: o Define the DECC$XPG4_STRPTIME logical name: $ DEFINE DECC$XPG4_STRPTIME ENABLE Or o Call the XPG4 strptime directly as the function decc$strptime_xpg4. To return to using the XPG5 strptime version, DEASSIGN the DECC$XPG4_STRPTIME logical name: $ DEASSIGN DECC$XPG4_STRPTIME Table REF-9 strptime Conversion Specifications SpecificaReplaced by %a The weekday name. This is either the abbreviated or the full name. %A Same as %a %b The month name. This is either the abbreviated or the full name. %B Same as %b. %c The date and time using the locale's date format %Ec The locale's alternative date and time representation %C The century number (the year divided by 100 and truncated to an integer) as a decimal number (00 - 99). Leading zeros are permitted. %EC The name of the base year (period) in the locale's alternative representation %d The day of the month as a decimal number (01 - 31). Leading zeros are permitted. %Od The day of the month using the locale's alternative numeric symbols %D Same as %m/%d/%y %e Same as %d %Oe The date of the month using the locale's alternative numeric symbols %h Same as %b %H The hour (24-hour clock) as a decimal number (00 - 23). Leading zeros are permitted. %OH The hour (24-hour clock) using the locale's alternative numeric symbols %I The hour (12-hour clock) as a decimal number (01 - 12). Leading zeros are permitted. %OI The hour (12-hour clock) using the locale's alternative numeric symbols %j The day of the year as a decimal number (001 - 366) %m The month as a decimal number (01 - 12). Leading zeros are permitted. %Om The month using the locale's alternative numeric symbols %M The minute as a decimal number (00 - 59). Leading zeros are permitted. %OM The minutes using the locale's alternative numeric symbols %n Any whitespace character %p The locale's equivalent of the AM/PM designations associated with a 12-hour clock %r The time in AM/PM notation (%I:%M:%S %p) %R The time in 24-hour notation (%H:%M) %S The second as a decimal number (00 - 61). Leading zeros are permitted. %OS The seconds using the locale's alternative numeric symbols %t Any whitespace character %T The time (%H:%M:%S) %U The week number of the year (the first Sunday as the first day of week 1) as a decimal number (00 - 53). Leading zeros are permitted. %OU The week number of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols %w The weekday as a decimal number (0 [Sunday] - 6). Leading zeros are permitted. %Ow The weekday as a number (Sunday=0) using the locale's alternative numeric symbols %W The week number of the year (the first Monday as the first day of week 1) as a decimal number (00 - 53). Leading zeros are permitted. %OW The week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols %x The locale's appropriate date representation %Ex The locale's alternative date representation %EX The locale's alternative time representation %X The locale's appropriate time representation %y The year without century as a decimal number (00 - 99) %Ey The offset from the base year (%EC) in the locale's alternative representation %Oy The year without the century using the locale's alternative numeric symbols %Y The year with century as a decimal number %EY The locale's full alternative year representation %% % 3 Return_Values x A pointer to the character following the last character parsed. NULL Indicates that an error occurred. The contents of the tm structure are undefined. 3 Example #include #include #include #include #include #include #define NUM_OF_DATES 7 #define BUF_SIZE 256 /* This program takes a number of date and time strings and */ /* converts them into tm structs using strptime(). These tm */ /* structs are then passed to strftime() which will reverse the */ /* process. The resulting strings are then compared with the */ /* originals and if a difference is found then an error is */ /* displayed. */ main() { int count, i; char buffer[BUF_SIZE]; char *ret_val; struct tm time_struct; char dates[NUM_OF_DATES][BUF_SIZE] = { "Thursday 01 January 1970 00:08:20", "Tuesday 29 February 1972 08:26:40", "Tuesday 31 December 1991 23:59:59", "Wednesday 01 January 1992 00:00:00", "Sunday 03 May 1992 13:33:20", "Monday 04 May 1992 17:20:00", "Friday 15 May 1992 03:20:00"}; for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ ret_val = strptime(dates[i], "%A %d %B %Y %T", &time_struct); /* Check the return value */ if (ret_val == (char *) NULL) { perror("strptime"); exit(EXIT_FAILURE); } /* Convert the time structure back to a formatted string */ count = strftime(buffer, BUF_SIZE, "%A %d %B %Y %T", &time_struct); /* Check the return value */ if (count == 0) { perror("strftime"); exit(EXIT_FAILURE); } /* Check the result */ if (strcmp(buffer, dates[i]) != 0) { printf("Error: Converted string differs from the original\n"); } else { printf("Successfully converted <%s>\n", dates[i]); } } } Running the example program produces the following result: Successfully converted Successfully converted Successfully converted Successfully converted Successfully converted Successfully converted Successfully converted 2 strrchr Returns the address of the last occurrence of a given character in a null-terminated string. The terminating null character is considered to be part of the string. Format #include char *strrchr (const char *str, int character); 3 Function_Variants This function also has variants named _strrchr32 and _strrchr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments str A pointer to a null-terminated character string. character An object of type int. 3 Description See also strchr. 3 Return_Values x The address of the last occurrence of the specified character. NULL Indicates that the character does not occur in the string. 2 strsep Separates strings. Format #include char *strsep (char **stringp, char *delim); 3 Function_Variants This function also has variants named _strsep32 and _strsep64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments stringp A pointer to a pointer to a character string. delim A pointer to a string containing characters to be used as delimeters. 3 Description This function locates in stringp, the first occurrence of any character in delim (or the terminating '\0' character) and replaces it with a '\0'. The location of the next character after the delimiter character (or NULL, if the end of the string is reached) is stored in the stringp argument. The original value of the stringp argument is returned. You can detect an "empty" field; one caused by two adjacent delimiter characters, by comparing the location referenced by the pointer returned in the stringp argument to '\0'. The stringp argument is initially NULL, strsep returns NULL. 3 Return_Values x The address of the string pointed to by stringp. NULL Indicates that stringp is NULL. 3 Example The following example uses strsep to parse a string, containing token delimited by white space, into an argument vector: char **ap, **argv[10], *inputstring; for (ap = argv; (*ap = strsep(&inputstring, " \t")) != NULL;) if (**ap != '\0') ++ap; 2 strspn Returns the length of the prefix of a string that consists entirely of characters from a set of characters. Format #include size_t strspn (const char *str, const char *charset); 3 Arguments str A pointer to a character string. If this string is a null string, 0 is returned. charset A pointer to a character string containing the characters for which the function will search. 3 Description This function scans the characters in the string, stops when it encounters a character not found in charset, and returns the length of the string's initial segment formed by characters found in charset. 3 Return_Value x The length of the segment. 2 strstr Locates the first occurrence in the string pointed to by s1 of the sequence of characters in the string pointed to by s2. Format #include char *strstr (const char *s1, const char *s2); 3 Function_Variants This function also has variants named _strstr32 and _strstr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s1, s2 Pointers to character strings. 3 Return_Values Pointer A pointer to the located string. NULL Indicates that the string was not found. 3 Example #include #include #include main() { static char lookin[]="that this is a test was at the end"; putchar('\n'); printf("String: %s\n", &lookin[0] ); putchar('\n'); printf("Addr: %s\n", &lookin[0] ); printf("this: %s\n", strstr( &lookin[0] ,"this") ); printf("that: %s\n", strstr( &lookin[0] , "that" ) ); printf("NULL: %s\n", strstr( &lookin[0], "" ) ); printf("was: %s\n", strstr( &lookin[0], "was" ) ); printf("at: %s\n", strstr( &lookin[0], "at" ) ); printf("the end: %s\n", strstr( &lookin[0], "the end") ); putchar('\n'); exit(0); } This example produces the following results: $ RUN STRSTR_EXAMPLE String: that this is a test was at the end Addr: that this is a test was at the end this: this is a test was at the end that: that this is a test was at the end NULL: that this is a test was at the end was: was at the end at: at this is a test was at the end the end: the end $ 2 strtod Converts a given string to a double-precision number. Format #include double strtod (const char *nptr, char **endptr); 3 Function_Variants This function also has variants named _strtod32 and _strtod64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the character string to be converted to a double- precision number. endptr The address of an object where the function can store the address of the first unrecognized character that terminates the scan. If endptr is a NULL pointer, the address of the first unrecognized character is not retained. 3 Description This function recognizes an optional sequence of white-space characters (as defined by isspace), then an optional plus or minus sign, then a sequence of digits optionally containing a radix character, then an optional letter (e or E) followed by an optionally signed integer. The first unrecognized character ends the conversion. The string is interpreted by the same rules used to interpret floating constants. The radix character is defined the program's current locale (category LC_NUMERIC). This function returns the converted value. For strtod, overflows are accounted for in the following manner: o If the correct value causes an overflow, HUGE_VAL (with a plus or minus sign according to the sign of the value) is returned and errno is set to ERANGE. o If the correct value causes an underflow, 0 is returned and errno is set to ERANGE. If the string starts with an unrecognized character, then the conversion is not performed, *endptr is set to nptr, a 0 value is returned, and errno is set to EINVAL.) 3 Return_Values x The converted string. 0 Indicates the conversion could not be performed. errno is set to one of the following: o EINVAL - No conversion could be performed. o ERANGE - The value would cause an underflow. o ENOMEM - Not enough memory available for internal conversion buffer. (+/-)HUGE_VAL Indicates overflow. errno is set to ERANGE. 2 strtok Locates text tokens in a given string. The text tokens are delimited by one or more characters from a separator string that you specify. This function keeps track of its position in the string between calls and, as successive calls are made, the function works through the string, identifying the text token following the one identified by the previous call. Format #include char *strtok (char *s1, const char *s2); 3 Function_Variants This function also has variants named _strtok32 and _strtok64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s1 On the first call, a pointer to a string containing 0 or more text tokens. On all subsequent calls for that string, a NULL pointer. s2 A pointer to a separator string consisting of one or more characters. The separator string may differ from call to call. 3 Description A token in s1 starts at the first character that is not a character in the separator string s2 and ends either at the end of the string or at (but not including) a separator character. The first call to the strtok function returns a pointer to the first character in the first token and writes a null character into s1 immediately following the returned token. Each subsequent call (with the value of the first argument remaining NULL) returns a pointer to a subsequent token in the string originally pointed to by s1. When no tokens remain in the string, the strtok function returns a NULL pointer. (This can occur on the first call to strtok if the string is empty or contains only separator characters.) Since strtok inserts null characters into s1 to delimit tokens, s1 cannot be a const object. 3 Return_Values x A pointer to the first character of a token. NULL Indicates that there are no tokens remaining in s1. 3 Examples 1.#include #include main() { static char str[] = "...ab..cd,,ef.hi"; printf("|%s|\n", strtok(str, ".")); printf("|%s|\n", strtok(NULL, ",")); printf("|%s|\n", strtok(NULL, ",.")); printf("|%s|\n", strtok(NULL, ",.")); } Running this example program produces the following results: $ RUN STRTOK_EXAMPLE1 |ab| |.cd| |ef| |hi| $ 2.#include #include main() { char *ptr, string[30]; /* The first character not in the string "-" is "A". The */ /* token ends at "C. */ strcpy(string, "ABC"); ptr = strtok(string, "-"); printf("|%s|\n", ptr); /* Returns NULL because no characters not in separator */ /* string "-" were found (i.e. only separator characters */ /* were found) */ strcpy(string, "-"); ptr = strtok(string, "-"); if (ptr == NULL) printf("ptr is NULL\n"); } Running this example program produces the following results: $ RUN STRTOK_EXAMPLE2 |abc| ptr is NULL $ 2 strtol Converts strings of ASCII characters to the appropriate numeric values. Format #include long int strtol (const char *nptr, char **endptr, int base); 3 Function_Variants This function also has variants named _strtol32 and _strtol64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the character string to be converted to a long. endptr The address of an object where the function can store a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. 3 Description This function recognizes strings in various formats, depending on the value of the base. This function ignores any leading white-space characters (as defined by isspace in ) in the given string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that may represent an integer constant according to the value of the base. The first unrecognized character ends the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16. If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion. Truncation from long to int can take place after assignment or by an explicit cast (arithmetic exceptions not withstanding). The function call atol (str) is equivalent to strtol (str, (char**)NULL, 10). 3 Return_Values x The converted value. LONG_MAX or LONG_ Indicates that the converted value would cause MIN an overflow. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, *endptr is set to nptr. 2 strtoq,_strtoll Converts strings of ASCII characters to the appropriate numeric values. strtoll is a synonym for strtoq. This function is OpenVMS Alpha only. Format #include __int64 strtoq (const char *nptr, char **endptr, int base); __int64 strtoll (const char *nptr, char **endptr, int base); 3 Function_Variants This function also has variants named _strtoq32/_strtoll32 and _ strtoq64/_strtoll64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the character string to be converted to an __int64. endptr The address of an object where the function can store a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. 3 Description This function recognizes strings in various formats, depending on the value of the base. This function ignores any leading white-space characters (as defined by isspace in ) in the given string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that may represent an integer constant according to the value of the base. The first unrecognized character ends the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16. If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion. The function call atoq (str) is equivalent to strtoq (str, (char**)NULL, 10). 3 Return_Values x The converted value. __INT64_MAX or Indicates that the converted value would cause __INT64_MIN an overflow. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, *endptr is set to nptr. 2 strtoul Converts the initial portion of the string pointed to by nptr to an unsigned long integer. Format #include unsigned long int strtoul (const char *nptr, char **endptr, int base); 3 Function_Variants This function also has variants named _strtoul32 and _strtoul64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the character string to be converted to an unsigned long. endptr The address of an object where the function can store a pointer to a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16. If the base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion. 3 Return_Values x The converted value. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, *endptr is set to nptr. ULONG_MAX Indicates that the converted value would cause an overflow. 2 strtouq,_strtoull Converts the initial portion of the string pointed to by nptr to an unsigned __int64 integer. strtoull is a synonym for strtouq. This function is OpenVMS Alpha only. Format #include unsigned __int64 strtouq (const char *nptr, char **endptr, int base); unsigned __int64 strtoull (const char *nptr, char **endptr, int base); 3 Function_Variants This function also has variants named _strtouq32/_strtoull32 and _strtouq64/_strtoull64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the character string to be converted to an unsigned __int64. endptr The address of an object where the function can store a pointer to a pointer to the first unrecognized character encountered in the conversion process (that is, the character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. Leading zeros after the optional sign are ignored, and 0x or 0X is ignored if the base is 16. If the base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion. 3 Return_Values x The converted value. 0 Indicates that the string starts with an unrecognized character or that the value for base is invalid. If the string starts with an unrecognized character, *endptr is set to nptr. __UINT64_MAX Indicates that the converted value would cause an overflow. 2 strxfrm Changes a string such that the changed string can be passed to the strcmp function and produce the same result as passing the unchanged string to the strcoll function. Format #include size_t strxfrm (char *s1, const char *s2, size_t maxchar); 3 Arguments s1, s2 Pointers to character strings. maxchar The maximum number of bytes (including the null terminator) to be stored in s1. 3 Description This function transforms the string pointed to by s2, and stores the resulting string in the array pointed to by s1. No more than maxchar bytes, including the null terminator, are placed into the array pointed to by s1. If the value of maxchar is less than the required size to store the transformed string (including the terminating null), the contents of the array pointed to by s1 is indeterminate. In such a case, the function returns the size of the transformed string. If maxchar is 0, then s1 is allowed to be a NULL pointer, and the function returns the required size of the s1 array before making the transformation. The string comparison functions, strcoll and strcmp, can produce different results given the same two string to compare. The reason for this is that strcmp does a straightforward comparison of the code point values of the characters in the strings, whereas strcoll uses the locale information to do the comparison. Depending on the locale, the strcoll comparison can be a multipass operation, which is slower than strcmp. The purpose of the strxfrm function is to transform strings in such a way that if you pass two transformed strings to the strcmp function, the result is the same as passing the two original strings to the strcoll function. The strxfrm function is useful in applications that need to do a large number of comparisons on the same strings using strcoll. In this case, it might be more efficient (depending on the locale) to transform the strings once using strxfrm, and then do comparisons using strcmp. 3 Return_Value x Length of the resulting string pointed to by s1, not including the terminating null character. No return value is reserved for error indication. However, the function can set errno to EINVAL - The string pointed to by ws2 contains characters outside the domain of the collating sequence. 3 Example /* This program verifies that two transformed strings when */ /* passed through strxfrm and then compared, provide the same */ /* result as if passed through strcoll without any */ /* transformation. #include #include #include #include #define BUFF_SIZE 256 main() { char string1[BUFF_SIZE]; char string2[BUFF_SIZE]; int errno; int coll_result; int strcmp_result; size_t strxfrm_result1; size_t strxfrm_result2; /* setlocale to French locale */ if (setlocale(LC_ALL, "fr_FR.ISO8859-1") == NULL) { perror("setlocale"); exit(EXIT_FAILURE); } /* collate string 1 and string 2 and store the result */ errno = 0; coll_result = strcoll("bcd", "abcz"); if (errno) { perror("strcoll"); exit(EXIT_FAILURE); } else { /* Transform the strings (using strxfrm) into */ /* string1 and string2 */ strxfrm_result1 = strxfrm(string1, "bcd", BUFF_SIZE); if (strxfrm_result1 == ((size_t) - 1)) { perror("strxfrm"); exit(EXIT_FAILURE); } else if (strxfrm_result1 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } else { strxfrm_result2 = strxfrm(string2, "abcz", BUFF_SIZE); if (strxfrm_result2 == ((size_t) - 1)) { perror("strxfrm"); exit(EXIT_FAILURE); } else if (strxfrm_result2 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } /* Compare the two transformed strings and verify */ /* that the result is the same as the result from */ /* strcoll on the original strings */ else { strcmp_result = strcmp(string1, string2); if (strcmp_result == 0 && (coll_result == 0)) { printf("\nReturn value from strcoll() and " "return value from strcmp() are both zero."); printf("\nThe program was successful\n\n"); } else if ((strcmp_result < 0) && (coll_result < 0)) { printf("\nReturn value from strcoll() and " "return value from strcmp() are less than zero."); printf("\nThe program successful\n\n"); } else if ((strcmp_result > 0) && (coll_result > 0)) { printf("\nReturn value from strcoll() and return " " value from strcmp() are greater than zero."); printf("\nThe program was successful\n\n"); } else { printf("** Error **\n"); printf("\nReturn values are not of the same type"); } } } } } Running the example program produces the following result: Return value from strcoll() and return value from strcmp() are less than zero. The program was successful 2 subwin Creates a new subwindow with numlines lines and numcols columns starting at the coordinates (begin_y,begin_x) on the terminal screen. Format #include WINDOW *subwin (WINDOW *win, int numlines, int numcols, int begin_y, int begin_x); 3 Arguments win A pointer to the parent window. numlines The number of lines in the subwindow. If numlines is 0, then the function sets that dimension to LINES - begin_y. To get a subwindow of dimensions LINES by COLS, use the following format: subwin (win, 0, 0, 0, 0) numcols The number of columns in the subwindow. If numcols is 0, then the function sets that dimension to COLS - begin_x. To get a subwindow of dimensions LINES by COLS, use the following format: subwin (win, 0, 0, 0, 0) begin_y A window coordinate at which the subwindow is to be created. begin_x A window coordinate at which the subwindow is to be created. 3 Description When creating the subwindow, begin_y and begin_x are relative to the entire terminal screen. If either numlines or numcols is 0, then the subwin function sets that dimension to (LINES - begin_y) or (COLS - begin_x), respectively. The window pointed to by win must be large enough to contain the entire area of the subwindow. Any changes made to either window within the coordinates of the subwindow appear on both windows. 3 Return_Values window pointer A pointer to an instance of the structure window corresponding to the newly created subwindow. ERR Indicates an error. 2 swab Swaps bytes. Format #include void swab (const void *src, void *dest, ssize_t nbytes); 3 Arguments src A pointer to the location of the string to copy. dest A pointer to where you want the results copied. nbytes The number of bytes to copy. Make this argument an even value. When it is an odd value, the swab function uses nbytes -1 instead. 3 Description This function copies the number of bytes specified by nbytes from the location pointed to by src to the array pointed to by dest. The function then exchanges adjacent bytes. If a copy takes place between objects that overlap, the result is undefined. 2 swprintf Writes output to an array of wide characters under control of the wide-character format string. Format #include int swprintf (wchar_t *s, size_t n, const wchar_t *format, . . . ); 3 Arguments s A pointer to the resulting wide-character sequence. n The maximum number of wide characters that can be written to an array pointed to by s, including a terminating null wide character. format A pointer to a wide-character string containing the format specifications. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, the output sources can be omitted. Otherwise, the function calls must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Excess output pointers, if any, are ignored. 3 Description The swprintf function is equivalent to the fwprintf function, except that the first argument specifies an array of wide characters instead of a stream. No more than n wide characters are written, including a terminating null wide character, which is always added (unless n is 0). See also fwprintf. 3 Return_Values x The number of wide characters written, not counting the terminating null wide character. Negative value Indicates an error. Either n or more wide characters were requested to be written, or a conversion error occurred, in which case errno is set to EILSEQ. 2 swscanf Reads input from a wide-character string under control of the wide-character format string. Format #include int swscanf (const wchar_t *s, const wchar_t *format, . . . ); 3 Arguments s A pointer to a wide-character string from which the input is to be obtained. format A pointer to a wide-character string containing the format specifications. . . . Optional expressions whose results correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description The swscanf function is equivalent to the fwscanf function, except that the first argument specifies a wide-character string rather than a stream. Reaching the end of the wide-character string is the same as encountering EOF for the fwscanf function. See also fwscanf. 3 Return_Values x The number of input items assigned, sometimes fewer than provided for, or even 0 in the event of an early matching failure. EOF Indicates and error. An input failure occurred before any conversion. 2 sysconf Gets configurable system variables. Format #include long int sysconf (int name); 3 Arguments name Specifies the system variable to be queried. 3 Description This function provides a method for determining the current value of a configurable system limit or whether optional features are supported. You supply a symbolic constant in the name argument, and sysconf returns a value for the corresponding system variable: o The symbolic constants defined in the header file. o The system variables are defined in the and header files. SYSCONF Argument and Return Values lists the system variables returned by the sysconf function, and the symbolic constants that you can supply as the name value. Table REF-10 SYSCONF Argument and Return Values Symbolic System Variable Constant for Returned name Meaning ISO POSIX-1 ARG_MAX _SC_ARG_MAX The maximum length, in bytes, of the arguments for one of the exec functions, including environment data. CHILD_MAX _SC_CHILD_ The maximum number of MAX simultaneous processes for each real user ID. CLK_TCK _SC_CLK_TCK The number of clock ticks per second. The value of CLK_TCK can be variable. Do not assume that CLK_TCK is a compile time constant. NGROUPS_MAX _SC_NGROUPS_ The maximum number of MAX simultaneous supplementary group IDs for each process. OPEN_MAX _SC_OPEN_MAX The maximum number of files that one process can have open at one time. STREAM_MAX _SC_STREAM_ The number of streams that one MAX process can have open at one time. TZNAME_MAX _SC_TZNAME_ The maximum number of bytes MAX supported for the name of a time zone (not the length of the TZ environmental variable). _POSIX_JOB_ _SC_JOB_ This variable has a value of CONTROL CONTROL 1 if the system supports job control; otherwise, -1 is returned. _POSIX_SAVED_IDS _SC_SAVED_ This variable has a value of 1 IDS if each process has a saved set user ID and a saved set group ID; otherwise, -1 is returned. _POSIX_VERSION _SC_VERSION The date of approval of the most current version of the POSIX-1 standard that the system supports. The date is a 6-digit number, with the first 4 digits signifying the year and the last 2 digits the month. If_POSIX_VERSION is not defined, -1 is returned. Different versions of the POSIX- 1 standard are periodically approved by the IEEE Standards Board, and the date of approval is used to distinguish between different versions. ISO POSIX-2 BC_BASE_MAX _SC_BC_BASE_ The maximum value allowed for MAX the obase variable with the bc command. BC_DIM_MAX _SC_BC_DIM_ The maximum number of elements MAX permitted in an array by the bc command. BC_SCALE_MAX _SC_BC_ The maximum value allowed for SCALE_MAX the scale variable with the bc command. BC_STRING_MAX _SC_BC_ The maximum length of string STRING_MAX constants accepted by the bc command. COLL_WEIGHTS_MAX _SC_COLL_ The maximum number of weights WEIGHTS_MAX that can be assigned to an entry in the LC_COLLATE locale- dependent information in a locale definition file. EXPR_NEST_MAX _SC_EXPR_ The maximum number of NEST_MAX expressions that you can nest within parentheses by the expr command. LINE_MAX _SC_LINE_MAX The maximum length, in bytes, of a command input line (either standard input or another file) when the utility is described as processing text files. The length includes room for the trailing newline character. RE_DUP_MAX _SC_RE_DUP_ The maximum number of repeated MAX occurrences of a regular expression permitted when using the interval notation arguments, such as the m and n arguments with the ed command. _POSIX2_CHAR_ _SC_2_CHAR_ This variable has a value of 1 TERM TERM if the system supports at least one terminal type; otherwise, -1 is returned. _POSIX2_C_BIND _SC_2_C_BIND This variable has a value of 1 if the system supports the C language binding option; otherwise, -1 is returned. _POSIX2_C_DEV _SC_2_C_DEV This variable has a value of 1 if the system supports the optional C Language Development Utilities from the ISO POSIX- 2 standard; otherwise, -1 is returned. _POSIX2_C_ _SC_2_C_ Integer value indicating the VERSION VERSION version of the ISO POSIX-2 standard (C language binding). It changes with each new version of the ISO POSIX-2 standard. _POSIX2_VERSION _SC_2_ Integer value indicating the VERSION version of the ISO POSIX-2 standard (Commands). It changes with each new version of the ISO POSIX-2 standard. _POSIX2_FORT_DEV _SC_2_FORT_ The variable has a value of 1 if DEV the system supports the FORTRAN Development Utilities Option from the ISO POSIX-2 standard; otherwise, -1 is returned. _POSIX2_FORT_RUN _SC_2_FORT_ The variable has a value of RUN 1 if the system supports the FORTRAN Runtime Utilities Option from the ISO POSIX-2 standard; otherwise, -1 is returned. _POSIX2_ _SC_2_ The variable has a value of LOCALEDEF LOCALEDEF 1 if the system supports the creation of new locales with the localedef command; otherwise, -1 is returned. _POSIX2_SW_DEV _SC_2_SW_DEV The variable has a value of 1 if the system supports the Software Development Utilities Option from the ISO POSIX-2 standard; otherwise, -1 is returned. _POSIX2_UPE _SC_2_UPE The variable has a value of 1 if the system supports the User Portability Utilities Option; otherwise, -1 is returned. POSIX 1003.1c-1995 _POSIX_THREADS _SC_THREADS This variable has a value of 1 if the system supports POSIX threads; otherwise, -1 is returned. _POSIX_THREAD_ _SC_THREAD_ This variable has a value of 1 ATTR_STACKSIZE ATTR_ if the system supports the POSIX STACKSIZE threads stack size attribute; otherwise, -1 is returned. _POSIX_THREAD_ _SC_THREAD_ The 1003.1c implementation PRIORITY_ PRIORITY_ supports the realtime scheduling SCHEDULING SCHEDULING functions. _POSIX_THREAD_ _SC_THREAD_ TRUE if the implementation SAFE_FUNCTIONS SAFE_ supports the thread-safe ANSI FUNCTIONS C functions in POSIX 1003.1c. PTHREAD_ _SC_THREAD_ When a thread terminates, DESTRUCTOR_ DESTRUCTOR_ DECthreads iterates through ITERATIONS ITERATIONS all non-NULL thread-specific data values in the thread, and calls a registered destructor routine (if any) for each. It is possible for a destructor routine to create new values for one or more thread-specific data keys. In that case, DECthreads goes through the entire process again. _SC_THREAD_DESTRUCTOR_ITERATIONS is the maximum number of times the implementation loops before it terminates the thread even if there are still non-NULL values. PTHREAD_KEYS_MAX _SC_THREAD_ The maximum number of thread- KEYS_MAX specific data keys that an application can create. PTHREAD_STACK_ _SC_THREAD_ The minimum allowed size of a MIN STACK_MIN stack for a new thread. Any lower value specified for the "stacksize" thread attribute is rounded up. UINT_MAX _SC_THREAD_ The maximum number of threads THREADS_MAX an application is allowed to create. Since DECthreads does not enforce any fixed limit, this value is -1. X/Open _XOPEN_VERSION _SC_XOPEN_ An integer indicating the VERSION most current version of the X/OPEN standard that the system supports. PASS_MAX _SC_PASS_MAX Maximum number of significant bytes in a password (not including terminating null). XOPEN_CRYPT _SC_XOPEN_ This variable has a value of CRYPT 1 if the system supports the X/Open Encryption Feature Group; otherwise, -1 is returned. XOPEN_ENH_I18N _SC_XOPEN_ This variable has a value ENH_I18N of 1 if the system supports the X/Open enhanced Internationalization Feature Group; otherwise, -1 is returned. XOPEN_SHM _SC_XOPEN_ This variable has a value SHM of 1 if the system supports the X/Open Shared Memory Feature Group; otherwise, -1 is returned. X/Open Extended ATEXIT_MAX _SC_ATEXIT_ The maximum number of functions MAX that you can register with atexit per process. PAGESIZE _SC_PAGESIZE Size in bytes of a page. PAGE_SIZE _SC_PAGE_ Same as PAGESIZE. If either SIZE PAGESIZE or PAGE_SIZE is defined, the other is defined with the same value. IOV_MAX _SC_IOV_MAX Maximum number of iovec structures that one process has available for use with readv or writev. XOPEN_UNIX _SC_XOPEN_ This variable has a value of UNIX 1 if the system supports the X/Open CAE Specification, August 1994, System Interfaces and Headers, Issue 4, Version 2, (ISBN: 1-85912-037-7, C435); otherwise, -1 is returned. 3 Return_Values x The current variable value on the system. The value does not change during the lifetime of the calling process. -1 Indicates an error. If the value of the name argument is invalid, errno is set to indicate the error. If the value of the name argument is undefined, errno is unchanged. 2 system Passes a given string to the host environment to be executed by a command processor. This function is nonreentrant. Format #include int system (const char *string); 3 Argument string A pointer to the string to be executed. If string is NULL, a nonzero value is returned. The string is a DCL command, not the name of an image. To execute an image, use one of the exec routines. 3 Description This function spawns a subprocess and executes the command specified by string in that subprocess. The system function waits for the subprocess to complete before returning the subprocess status as the return value of the function. The subprocess is spawned within the system call by a call to vfork. Because of this, a call to system should not be made after a call to vfork and before the corresponding call to an exec function. For OpenVMS Version 7.0 and higher systems, if you include and compile with the _POSIX_EXIT feature-test macro set, then the system function returns the status as if it called waitpid to wait for the child. Therefore, use the WIFEXITED and WEXITSTATUS macros to retrieve the exit status in the range of 0 to 255. You set the _POSIX_EXIT feature-test macro by using /DEFINE=_ POSIX_EXIT or #define _POSIX_EXIT at the top of your file, before any file inclusions. 3 Return_Values nonzero value If string is NULL, a value of 1 is returned, indicating that the system function is supported. If string is not NULL, the value is the subprocess OpenVMS return status. 3 Example #include #include #include /* write, close */ #include /* Creat */ main() { int status, fd; /* Creat a file we are sure is there */ fd = creat("system.test", 0); write(fd, "this is an example of using system", 34); close(fd); if (system(NULL)) { status = system("DIR/NOHEAD/NOTRAIL/SIZE SYSTEM.TEST"); printf("system status = %d\n", status); } else printf("system() not supported.\n"); } Running this example program produces the following result: DISK3$:[JONES.CRTL.2059.SRC]SYSTEM.TEST;1 1 system status = 1 2 tan Returns a double value that is the tangent of its radian argument. Format #include double tan (double x); float tanf (float x); (Alpha only) long double tanl (long double x); (Alpha only) double tand (double x); (Alpha only) float tandf (float x); (Alpha only) long double tandl (long double x); (Alpha only) 3 Argument x A radian expressed as a real number. 3 Description The tan functions compute the tangent of x, measured in radians. The tand functions compute the tangent of x, measured in degrees. 3 Return_Values x The tangent of the argument. HUGE_VAL x is a singular point ( . . . -3/2, -/2, /2 . . . ). NaN x is NaN; errno is set to EDOM. 0 x is 0 Underflow occurred; errno is set to ERANGE. 2 tanh Returns the hyperbolic tangent of its argument. Format #include double tanh (double x); float tanhf (float x); (Alpha only) long double tanhl (long double x); (Alpha only) 3 Argument x A real number. 3 Description The tanh functions return the hyperbolic tangent their argument, calculated as (e**x - e**(-x))/(e**x + e**(-x)). 3 Return_Values n The hyperbolic tangent of the argument. HUGE_VAL The argument is too large; errno is set to ERANGE. NaN x is NaN; errno is set to EDOM. 0 Underflow occurred; errno is set to ERANGE. 2 telldir Returns the current location associated with a specified directory stream. Performs operations on directories. Format #include long int telldir (DIR *dir_pointer); 3 Arguments dir_pointer A pointer to the DIR structure of an open directory. 3 Description This function returns the current location associated with the specified directory stream. 3 Return_Values x The current location. -1 Indicates an error and is further specified in the global errno. 2 tempnam Constructs the name for a temporary file. Format #include char *tempnam (const char *directory, const char *prefix); 3 Arguments directory A pointer to the pathname of the directory where you want to create a file. prefix A pointer to an initial character sequence of the filename. The prefix argument can be null, or it can point to a string of up to five characters used as the first characters of the temporary filename. 3 Description This function generates filenames for temporary files. It allows you to control the choice of a directory. If the directory argument is null or points to a string that is not a pathname for an appropriate directory, the pathname defined as P_tmpdir in the header file is used. You can bypass the selection of a pathname by providing the TMPDIR environment variable in the user environment. The value of the TMPDIR variable is a pathname for the desired temporary file directory. Use the prefix argument to specify a prefix of up to 5 characters for the temporary filename. The tempnam function returns a pointer to the generated pathname, suitable for use in a subsequent call to the free function. See also free. NOTE In contrast to tmpnam, tempnam does not have to generate a different file name on each call. tempnam generates a new file name only if the file with the specified name exists. If you need a unique filename on each call, use tmpnam instead of tempnam. 3 Return_Values x A pointer to the generated pathname, suitable for use in a subsequent call to the free function. NULL An error occurred; errno is set to indicate the error. 2 time Returns the time (expressed as Universal Coordinated Time) elapsed since 00:00:00, January 1, 1970, in seconds. Format #include time_t time (time_t *time_location); 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Argument time_location Either NULL or a pointer to the place where the returned time is also stored. The time_t type is defined in the header file as follows: typedef unsigned long int time_t; 3 Return_Values x The time elapsed past the epoch. (time_t)(-1) Indicates an error. If the value of SYS$TIMEZONE_DIFFERENTIAL logical is wrong, the function will fail with errno set to EINVAL. 2 times Passes back the accumulated times of the current process and its terminated child processes. Format #include clock_t times (struct tms *buffer); (OpenVMS V7.0 and higher) void times (tbuffer_t *buffer); (pre OpenVMS V7.0) 3 Argument buffer A pointer to the terminal buffer. 3 Description For both process and children times, the structure breaks down the time by user and system time. Since the OpenVMS system does not differentiate between system and user time, all system times are returned as 0. Accumulated CPU times are returned in 10- millisecond units. Only the accumulated times for child processes running a C main program or a program that calls VAXC$CRTL_INIT or DECC$CRTL_INIT are included. On OpenVMS Version 7.0 and higher systems, the times function returns the elapsed real time in clock ticks since an arbitrary reference time in the past (for example, system startup time). This reference time does not change from one times function call to another. The return value can overflow the possible range of type clock_t values. When times fails, it returns a value of -1. The Compaq C RTL uses system-boot time as its reference time. 3 Return_Values x The elapsed real time in clock ticks since system-boot time. (clock_t)(-1) Indicates an error. 2 tmpfile Creates a temporary file that is opened for update. Format #include FILE *tmpfile (void); 3 Description The file exists only for the duration of the process, or until the file is closed and is preserved across calls to vfork. 3 Return_Values x The address of a file pointer (defined in the header file). NULL Indicates an error. 2 tmpnam Generates file names that can be safely used for a temporary file. Format #include char *tmpnam (char *name); 3 Function_Variants This function also has variants named _tmpnam32 and _tmpnam64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Argument name A character string containing a name to use in place of file-name arguments in functions or macros. Successive calls to tmpnam with a null argument cause the function to overwrite the current name. 3 Return_Value x If the name argument is the null pointer value NULL, tmpnam returns the address of an internal storage area. If name is not NULL, then it is considered the address of an area of length L_tmpnam (defined in the header file). In this case, tmpnam returns the name argument as the result. 2 toascii Converts its argument, an 8-bit ASCII character, to a 7-bit ASCII character. Format #include int toascii (char character); 3 Argument character An object of type char. 3 Return_Value x A 7-bit ASCII character. 2 tolower Converts a character to lowercase. Format #include int tolower (int character); 3 Argument character An object of type int representable as an unsigned char or the value of EOF. For any other value, the behavior is undefined. 3 Description If the argument represents an uppercase letter, and there is a corresponding lowercase letter, as defined by character type information in the program locale category LC_TYPE, the corresponding lowercase letter is returned. If the argument is not an uppercase character, it is returned unchanged. 3 Return_Value x The lowercase letter corresponding to the argument. Or, the unchanged argument, if it is not an uppercase character. 2 _tolower Converts an uppercase character to lowercase. Format #include int _tolower (int character); 3 Argument character This argument must be an uppercase letter. 3 Description The _tolower macro is equivalent to the tolower function except that its argument must be an uppercase letter (not lowercase, not EOF). The _tolower macro should not be used with arguments that contain side-effect operations. For instance, the following example will not return the expected result: d = _tolower (c++); 3 Return_Value x The lowercase letter corresponding to the argument. 2 touchwin Places the most recently edited version of the specified window on the terminal screen. Format #include int touchwin (WINDOW *win); 3 Argument win A pointer to the window. 3 Description This function is normally used only to refresh overlapping windows. 3 Return_Values OK Indicates success. ERR Indicates an error. 2 toupper Converts a character to uppercase. Format #include int toupper (int character); 3 Argument character An object of type int representable as an unsigned char or the value of EOF. For any other value, the behavior is undefined. 3 Description If the argument represents a lowercase letter, and there is a corresponding uppercase letter, as defined by character type information in the program locale category LC_TYPE, the corresponding uppercase letter is returned. If the argument is not a lowercase character, it is returned unchanged. 3 Return_Value x The uppercase letter corresponding to the argument. Or, the unchanged argument, if the argument is not a lowercase character. 2 _toupper Converts a lowercase character to uppercase. Format #include int _toupper (int character); 3 Argument character This argument must be an uppercase letter. 3 Description The _toupper macro is equivalent to the toupper function except that its argument must be a lowercase letter (not uppercase, not EOF). The _toupper macro should not be used with arguments that contain side-effect operations. For instance, the following example will not return the expected result: d = _toupper (c++); 3 Return_Value x The uppercase letter corresponding to the argument. 2 towctrans Maps one wide character to another according to a specified mapping descriptor. Format #include wint_t towctrans (wint_t wc, wctrans_t desc); 3 Arguments wc The wide character that you want to map. desc Description of the mapping obtained through a call to the wctrans function. 3 Description This function maps the wide character specified in wc, using the mapping described by desc. The current setting of the LC_CTYPE category must be the same as during the call to the wctrans function that returned the value of desc. 3 Return_Values x The mapped value of the wc wide character, if this character exists in the mapping described by desc. Otherwise, the value of wc is returned. 2 towlower Converts the argument, a wide-character code, to lowercase. If the argument is not an uppercase character, it is returned unchanged. Format #include (ISO C) #include (XPG4) int towlower (wint_t wc); 3 Arguments wc An object of type wint_t representable as a valid wide character in the current locale, or the value of WEOF. For any other value, the behavior is undefined. 3 Description If the argument is an uppercase wide character, the corresponding lowercase wide character (as defined in the LC_CTYPE category of the locale) is returned, if it exists. If it does not exist, the function returns the input argument unchanged. 2 towupper Converts the argument, a wide character, to uppercase. If the argument is not a lowercase character, it is returned unchanged. Format #include (ISO C) #include (XPG4) int towupper (wint_t wc); 3 Arguments wc An object of type wint_t representable as a valid wide character in the current locale, or the value of WEOF. For any other value, the behavior is undefined. 3 Description If the argument is a lowercase wide character, the corresponing uppercase wide character (as defined in the LC_CTYPE category of the locale) is returned, if it exists. If it does not exist, the function returns the input argument unchanged. 2 trunc Truncates the argument to an integral value. This function is OpenVMS Alpha only. Format #include double trunc (double x); float truncf (float x,); long double truncl (long double x); 3 Argument x A floating-point number. 3 Return_Values n The truncated, integral value of the argument. 2 truncate Changes file length to a specified length in bytes. Format #include int truncate (const char *path, off_t length); 3 Arguments path The name of a file that is to be truncated. This argument must point to a pathname that names a regular file for which the calling process has write permission. length The new length of the file in bytes. The off_t type of length is either a 64-bit integer or a 32-bit integer. The 64-bit interface allows for file sizes greater than 2 gigabytes, and can be selected at compile time by defining the _LARGEFILE feature-test macro: CC/DEFINE=_LARGEFILE 3 Description This function changes the length of a file to the size in bytes specified by the length argument. If the new length is less than the previous length, the function removes all data beyond length bytes from the specified file. All file data between the new End-of-File and the previous End-of- File is discarded. For stream files, if the new length is greater than the previous length, new file data between the previous End-of-File and the new End-of-File is added, consisting of all zeros. (For record files, it is not possible to extend the file in this manner.) 3 Return_Values 0 Indicates success. -1 An error occurred; errno is set to indicate the error. 2 ttyname Returns a pointer to the null-terminated name of the terminal device associated with file descriptor 0, the default input device (stdin). Format #include char *ttyname (void); 3 Description This function is provided only for UNIX compatibility and has limited use in the OpenVMS environment. 3 Return_Values x A pointer to a null-terminated string. 0 Indicates that SYS$INPUT is not a TTY device. 2 tzset Sets and accesses time-zone conversion. Format #include void tzset (void); extern char *tzname[]; extern long int timezone; extern int daylight; 3 Description This function initializes time conversion information used by the ctime, localtime, mktime, strftime, and wcsftime functions. The tzset function sets the following external variables: o tzname is set as follows, where "std" is a 3-byte name for the standard time zone, and "dst" is a 3-byte name for the Daylight Savings Time zone: tzname[0] = "std" tzname[1] = "dst" o daylight is set to 0 if Daylight Savings Time should never be applied to the time zone. Otherwise, daylight is set to 1. o timezone is set to the difference between UTC and local standard time. The environment variable TZ specifies how tzset initializes time conversion information: o If TZ is absent from the environment, the implementation- dependent time-zone information is used, as follows: The best available approximation to local wall-clock time is used, as defined by the system logical SYS$LOCALTIME, which points to a tzfile format file that describes default time-zone rules. This system logical is set during the installation of OpenVMS Version 7.0 or higher to define a time-zone file based off the root directory SYS$COMMON:[SYS$ZONEINFO.SYSTEM]. o If TZ appears in the environment but its value is a null string, Coordinated Universal Time (UTC) is used (without leap-second correction). o If TZ appears in the environment and its value is not a null string, the value has one of three formats, as described in Time-Zone Initialization Rules. Table REF-11 Time-Zone Initialization Rules TZ Format Meaning : UTC is used. :pathname The characters following the colon specify the pathname of a tzfile format file from which to read the time-conversion information. A pathname beginning with a slash (/) represents an absolute pathname; otherwise, the pathname is relative to the system time-conversion information directory specified by SYS$TZDIR, which by default is SYS$COMMON:[SYS$ZONEINFO.SYSTEM]. stdoffset[dstThefset]e is first used as the pathname of a file (as described for the :pathname format) from which [,rule]] to read the time-conversion information. If that file cannot be read, the value is then interpreted as a direct specification of the time- conversion information, as follows: std and dst-Three or more characters that are the designation for the time zone: o std-Standard time zone. Required. o dst-Daylight Savings Time zone. Optional. If dst is omitted, Daylight Savings Time does not apply. Uppercase and lowercase letters are explicitly allowed. Any characters are allowed, except the following: o digits o leading colon (:) o comma (,) o minus (-) o plus (+) o ASCII null character offset-The value added to the local time to arrive at UTC. The offset has the following format: hh[:mm[:ss]] In this format: o hh (hours) is a one-or two-digit value of 0-24. o mm (minutes) is a value of 0-59. (optional) o ss (seconds) is a value of 0-59. (optional) The offset following std is required. If no offset follows dst, summer time is assumed, one hour ahead of standard time. You can use one or more digits; the value is always interpreted as a decimal number. If the time zone is preceded by a minus sign (-), the time zone is East of Greenwich; otherwise, it is West, which can also be indicated by a preceding plus sign (+). rule-Indicates when to change to and return from summer time. The rule has the form: start[/time], end[/time] Where: o start is the date when the change from standard time to summer time occurs. o end is the date for returning from summer time to standard time. If start and end are omitted, the default is the US Daylight Saving Time start and end dates. The format for start and end must be one of the following: o Jn-The Julian day n (1 < n < 365). Leap days are not counted. That is, in all years, including leap years, February 28 is day 59 and March 1 is day 60. You cannot explicitly refer to February 29. o n-The zero based Julian day (0 < n < 365). Leap days are counted, making it possible to refer to February 29. o Mm.n.d-The nth d day of month m where: 0 < n < 5 0 < d < 6 1 < m < 12 When n is 5, it refers to the last d day of month m. Sunday is day 0. time-The time when, in current time, the change to or return from summer time occurs. The time argument has the same format as offset, except that you cannot use a leading minus (-) or plus (+) sign. If time is not specified, the default is 02:00:00. If no rule is present in the TZ specification, the rules used are those specified by the tzfile format file defined by the system logical SYS$POSIXRULES in the system time-conversion information directory, with the standard and summer time offsets from UTC replaced by those specified by the offset values in TZ. If TZ does not specify a tzfile format file and cannot be interpreted as a direct specification, UTC is used. NOTE The UTC-based time functions, introduced in OpenVMS Version 7.0, had degraded performance compared with the non-UTC- based time functions. OpenVMS Version 7.1 added a cache for time-zone files to improve performance. The size of the cache is determined by the logical name DECC$TZ_CACHE_SIZE. To accommodate most countries changing the time twice per year, the default cache size is large enough to hold two time-zone files. See also ctime, localtime, mktime, strftime, and wcsftime. 3 Sample_TZ_Specification 1.EST5EDT4,M4.1.0,M10.5.0 This sample TZ specification describes the rule defined in 1987 for the Eastern time zone in the US: o EST (Eastern Standard Time) is the designation for standard time, which is 5 hours behind UTC. o EDT (Eastern Daylight Time) is the designation for summer time, which is 4 hours behind UTC. EDT starts on the first Sunday in April and ends on the last Sunday in October. Because time was not specified in either case, the changes occur at the default time, which is 2:00 a.m. The start and end dates did not need to be specified, because they are the defaults. 2 ualarm Sets or changes the timeout of interval timers. Format #include useconds_t ualarm (useconds_t mseconds, useconds_t interval); 3 Arguments mseconds Specifies a number of real time microseconds. interval Specifies the interval for repeating the timer. 3 Description This function causes the SIGALRM signal to be generated for the calling process after the number of real-time microseconds specified by useconds has elapsed. When the interval argument is nonzero, repeated timeout notification occurs with a period in microseconds specified by interval. If the notification signal SIGALRM is not caught or is ignored, the calling process is terminated. If you call a combination of ualarm and setitimer functions, and the AST status is disabled, the return value is invalid. If you call a combination of ualarm and setitimer functions, and the AST status is enabled, the return value is valid. This is because you cannot invoke an AST handler to clear the previous value of the timer when ASTs are disabled or invoked from a handler that was invoked at AST level. NOTE Interactions between ualarm and either alarm, or sleep are unspecified. See also setitimer. 3 Return_Values n The number of microseconds remaining from the previous ualarm or setitimer call. 0 No timeouts are pending or ualarm not previously called. -1 Indicates an error. 2 umask Creates a file protection mask that is used when a new file is created, and returns the previous mask value. Format #include mode_t umask (mode_t mode_complement); 3 Argument mode_complement Shows which bits to turn off when a new file is created. See the description of chmod to determine what the bits represent. 3 Description Initially, the file protection mask is set from the current process's default file protection. This is done when the C main program starts up or when DECC$CRTL_INIT (or VAXC$CRTL_INIT) is called. You can change this for all files created by your program by calling umask or you can use chmod to change the file protection on individual files. The file protection of a file created by open or creat is the bitwise AND of the open and creat mode argument with the complement of the value passed to umask on the previous call. NOTE The way to create files with OpenVMS RMS default protections using the UNIX system-call functions umask, mkdir, creat, and open is to call mkdir, creat, and open with a file- protection mode argument of 0777 in a program that never specifically calls umask. These default protections include correctly establishing protections based on ACLs, previous versions of files, and so on. In programs that do vfork/exec calls, the new process image inherits whether umask has ever been called or not from the calling process image. The umask setting and whether the umask function has ever been called are both inherited attributes. 3 Return_Value x The old mask value. 2 uname Gets system identification information. Format #include int uname (struct utsname *name); 3 Arguments name The current system identifier. 3 Description This function stores null-terminated strings of information identifying the current system into the structure referenced by the name argument. The utsname structure is defined in the header file and contains the following members: sysname Name of the operating system implementation nodename Network name of this machine release Release level of the operating system version Version level of the operating system machine Machine hardware platform 3 Return_Values 0 Indicates success. -1 Indicates an error; errno or vaxc$errno is set as appropriate. 2 ungetc Pushes a character back into the input stream and leaves the stream positioned before the character. Format #include int ungetc (int character, FILE *file_ptr); 3 Arguments character A value of type int. file_ptr A file pointer. 3 Description When using this function, the character is pushed back onto the file indicated by file_ptr. One pushback is guaranteed, even if there has been no previous activity on the file. The fseek function erases all memory of pushed-back characters. The pushed-back character is not written to the underlying file. If the character to be pushed back is EOF, the operation fails, the input stream is left unchanged, and EOF is returned. See also fseek and getc. 3 Return_Values x The push-back character. EOF Indicates it cannot push the character back. 2 ungetwc Pushes a wide character back into the input stream. Format #include wint_t ungetwc (wint_t wc, FILE *file_ptr); 3 Arguments wc A value of type wint_t. file_ptr A file pointer. 3 Description When using this function, the wide character is pushed back onto the file indicated by file_ptr. One push-back is guaranteed, even if there has been no previous activity on the file. If a file positioning function (such as fseek) is called before the pushed back character is read, the bytes representing the pushed back character are lost. If the character to be pushed back is WEOF, the operation fails, the input stream is left unchanged, and WEOF is returned. See also getwc. 3 Return_Values x The push-back character. WEOF Indicates that the function cannot push the character back. errno is set to one of the following: o EBADF - The file descriptor is not valid. o EALREADY - Operation is already in progress on the same file. o EILSEQ - Invalid wide-character code detected. 2 unordered Returns the value 1 (True) if either or both of the arguments is a NaN. Otherwise, it returns the value 0 (False). This function is OpenVMS Alpha only. Format #include double unordered (double x, double y); float unorderedf (float x, float y); long double unorderedl (long double x, long double y); 3 Argument x A real number. y A real number. 3 Return_Values 1 Either or both of the arguments is a NaN. 0 Neither argument is a NaN. 2 utime Sets file access and modification times. Format #include int utime (const char *path, const struct utimbuf *times); 3 Argument path A pointer to a file. times A null pointer or a pointer to a utimbuf structure. 3 Description The utime function sets the access and modification times of the file named by the path argument. If times is a null pointer, the access and modification times of the file are set to the current time. To use utime in this way, the effective user ID of the process must match the owner of the file, or the process must have write permission to the file or have appropriate privileges. If times is not a null pointer, it is interpreted as a pointer to a utimbuf structure, and the access and modification times are set to the values in the specified structure. Only a process with an effective user ID equal to the user ID of the file or a process with appropriate privileges can use utime this way. The utimbuf structure is defined by the header. The times in the utimbuf structure are measured in seconds since the Epoch. Upon successful completion, utime marks the time of the last file status change, st_ctime, to be updated. See the header file. NOTE (Alpha only) On OpenVMS Alpha systems, the stat, fstat, utime, and utimes functions have been enhanced to take advantage of the new file-system support for POSIX-compliant file timestamps. This support is available only on ODS-5 devices on OpenVMS Alpha systems beginning with a version of OpenVMS Alpha after Version 7.3. Before this change, the stat and fstat functions were setting the values of the st_ctime, st_mtime, and st_atime fields based on the following file attributes: st_ctime - ATR$C_CREDATE (file creation time) st_mtime - ATR$C_REVDATE (file revision time) st_atime - was always set to st_mtime because no support for file access time was available Also, for the file-modification time, utime and utimes were modifying the ATR$C_REVDATE file attribute, and ignoring the file-access-time argument. After the change, for a file on an ODS-5 device, the stat and fstat functions set the values of the st_ctime, st_ mtime, and st_atime fields based on the following new file attributes: st_ctime - ATR$C_ATTDATE (last attribute modification time) st_mtime - ATR$C_MODDATE (last data modification time) st_atime - ATR$C_ACCDATE (last access time) If ATR$C_ACCDATE is zero, as on an ODS-2 device, the stat and fstat functions set st_atime to st_mtime. For the file-modification time, the utime and utimes functions modify both the ATR$C_REVDATE and ATR$C_MODDATE file attributes. For the file-access time, these functions modify the ATR$C_ACCDATE file attribute. Setting the ATR$C_ MODDATE and ATR$C_ACCDATE file attributes on an ODS-2 device has no effect. For compatibility, the old behavior of stat, fstat, utime and utimes remains the default, regardless of the kind of device. The new behavior must be explicitly enabled by defining the DECC$EFS_FILE_TIMESTAMPS logical name to "ENABLE" before invoking the application. Setting this logical does not affect the behavior of stat, fstat, utime and utimes for files on an ODS-2 device. 3 Return_Values 0 Successful execution. -1 Indicates an error. The function sets errno to one of the following values: The utime function will fail if: o EACCES - Search permission is denied by a component of the path prefix; or the times argument is a null pointer and the effective user ID of the process does not match the owner of the file and write access is denied. o ELOOP - Too many symbolic links were encountered in resolving path. o ENAMETOOLONG - The length of the path argument exceeds {PATH_MAX}, a path name component is longer than {NAME_MAX}, or a path name resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. o ENOENT - A component of path does not name an existing file, or path is an empty string. o ENOTDIR - A component of the path prefix is not a directory. o EPERM -The times argument is not a null pointer and the calling process' effective user ID has write-access to the file but does not match the owner of the file and the calling process does not have the appropriate privileges. o EROFS - The file system containing the file is read-only. 2 utimes Sets file access and modification times. Format #include int utimes (const char *path, const struct timeval times[2]); 3 Argument path A pointer to a file. times an array of timeval structures. The first array member represents the date and time of last access, and the second member represents the date and time of last modification. The times in the timeval structure are measured in seconds and microseconds since the Epoch, although rounding toward the nearest second may occur. 3 Description The utimes function sets the access and modification times of the file pointed to by the path argument to the value of the times argument. The utimes function allows time specifications accurate to the microsecond. If the times argument is a null pointer, the access and modification times of the file are set to the current time. The effective user ID of the process must be the same as the owner of the file, or must have write access to the file or appropriate privileges to use this call in this manner. Upon completion, utimes marks the time of the last file status change, st_ctime, for update. NOTE (Alpha only) On OpenVMS Alpha systems, the stat, fstat, utime, and utimes functions have been enhanced to take advantage of the new file-system support for POSIX-compliant file timestamps. This support is available only on ODS-5 devices on OpenVMS Alpha systems beginning with a version of OpenVMS Alpha after Version 7.3. Before this change, the stat and fstat functions were setting the values of the st_ctime, st_mtime, and st_atime fields based on the following file attributes: st_ctime - ATR$C_CREDATE (file creation time) st_mtime - ATR$C_REVDATE (file revision time) st_atime - was always set to st_mtime because no support for file access time was available Also, for the file-modification time, utime and utimes were modifying the ATR$C_REVDATE file attribute, and ignoring the file-access-time argument. After the change, for a file on an ODS-5 device, the stat and fstat functions set the values of the st_ctime, st_ mtime, and st_atime fields based on the following new file attributes: st_ctime - ATR$C_ATTDATE (last attribute modification time) st_mtime - ATR$C_MODDATE (last data modification time) st_atime - ATR$C_ACCDATE (last access time) If ATR$C_ACCDATE is zero, as on an ODS-2 device, the stat and fstat functions set st_atime to st_mtime. For the file-modification time, the utime and utimes functions modify both the ATR$C_REVDATE and ATR$C_MODDATE file attributes. For the file-access time, these functions modify the ATR$C_ACCDATE file attribute. Setting the ATR$C_ MODDATE and ATR$C_ACCDATE file attributes on an ODS-2 device has no effect. For compatibility, the old behavior of stat, fstat, utime and utimes remains the default, regardless of the kind of device. The new behavior must be explicitly enabled by defining the DECC$EFS_FILE_TIMESTAMPS logical name to "ENABLE" before invoking the application. Setting this logical does not affect the behavior of stat, fstat, utime and utimes for files on an ODS-2 device. 3 Return_Values 0 Successful execution. -1 Indicates an error. The file times do not change and the function sets errno to one of the following values: The utimes function will fail if: o EACCES - Search permission is denied by a component of the path prefix; or the times argument is a null pointer and the effective user ID of the process does not match the owner of the file and write access is denied. o ELOOP - Too many symbolic links were encountered in resolving path. o ENAMETOOLONG - The length of the path argument exceeds {PATH_MAX}, a path name component is longer than {NAME_MAX}, or a path name resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. o ENOENT - A component of path does not name an existing file, or path is an empty string. o ENOTDIR - A component of the path prefix is not a directory. o EPERM -The times argument is not a null pointer and the calling process' effective user ID has write-access to the file but does not match the owner of the file and the calling process does not have the appropriate privileges. o EROFS - The file system containing the file is read-only. 2 unsetenv Deletes all instances of the environment variable name from the environment list. Format #include void unsetenv (const char *name); 3 Arguments name The environment variable to delete from the environment list. 3 Description This function deletes all instances of the variable name pointed to by the name argument from the environment list. 2 usleep Suspends execution for an interval. Format #include int usleep (unsigned int mseconds); 3 Arguments mseconds The number of microseconds to suspend execution for. 3 Description This function suspends the current process from execution for the number of microseconds specified by the mseconds argument. This argument must be less than 1,000,000. However, if its value is 0, then the call has no effect. There is one real-time interval timer for each process. The usleep function does not interfere with a previous setting of this timer. If the process set this timer before calling usleep and if the time specified by mseconds equals or exceeds the interval timer's prior setting, then the process is awakened shortly before the timer was set to expire. 3 Return_Values 0 Indicates success. -1 Indicates an error occurred; errno is set to EINVAL. 2 VAXC$CRTL_INIT Allows you to call the Compaq C RTL from other languages or to use the Compaq C RTL when your main function is not in C. It initializes the run-time environment and establishes both an exit and condition handler. VAXC$CRTL_INIT is a synonym for DECC$CRTL_ INIT. Either name invokes the same routine. Format #include void VAXC$CRTL_INIT(); 3 Description The following example shows a Pascal program that calls the Compaq C RTL using the VAXC$CRTL_INIT function: On OpenVMS VAX systems: $ PASCAL EXAMPLE $ LINK EXAMPLE,SYS$LIBRARY:DECCRTL/LIB $ TY EXAMPLE.PAS PROGRAM TESTC(input, output); PROCEDURE VAXC$CRTL_INIT; extern; BEGIN VAXC$CRTL_INIT; END $ On OpenVMS Alpha systems: $ PASCAL EXAMPLE $ LINK EXAMPLE,SYS$LIBRARY:VAXCRTL/LIB $ TY EXAMPLE.PAS PROGRAM TESTC(input, output); PROCEDURE VAXC$CRTL_INIT; extern; BEGIN VAXC$CRTL_INIT; END $ A shareable image need only call this function if it contains a Compaq C function for signal handling, environment variables, I/O, exit handling, a default file protection mask, or if it is a child process that should inherit context. Although many of the initialization activities are performed only once, DECC$CRTL_INIT can safely be called multiple times. On OpenVMS VAX systems, DECC$CRTL_INIT establishes the Compaq C RTL internal OpenVMS exception handler in the frame of the routine that calls DECC$CRTL_INIT each time DECC$CRTL_INIT is called. At least one frame in the current call stack must have that handler established for OpenVMS exceptions to get mapped to UNIX signals. 2 VAXC$ESTABLISH Used for establishing an OpenVMS exception handler for a particular routine. This function establishes a special Compaq C RTL exception handler in the routine that called it. This special handler catches all RTL-related exceptions that occur in later routines, and passes on all other exceptions to your handler. Format #include void VAXC$ESTABLISH (unsigned int (*exception_handler)(void *sigarr, void *mecharr)); 3 Arguments exception_handler The name of the function that you want to establish as an OpenVMS exception handler. You pass a pointer to this function as the parameter to VAXC$ESTABLISH. sigarr A pointer to the signal array. mecharr A pointer to the mechanism array. 3 Description VAXC$ESTABLISH must be used in place of LIB$ESTABLISH when programs use the Compaq C RTL routines setjmp or longjmp. See setjmp and longjmp, or sigsetjmp and siglongjmp. You can only invoke the VAXC$ESTABLISH function from a Compaq C for OpenVMS function, because it relies on the allocation of data space on the run-time stack by the Compaq C compiler. Calling the OpenVMS system library routine LIB$ESTABLISH directly from a Compaq C function results in undefined behavior from the setjmp and longjmp functions. To cause an OpenVMS exception to generate a UNIX style signal, user exception handlers must return SS$_RESIGNAL upon receiving any exception that they do not want to handle. Returning SS$_NORMAL prevents the generation of a UNIX style signal. UNIX signals are generated as if by an exception handler in the stack frame of the main C program. Not all OpenVMS exceptions correspond to UNIX signals. See the "Error and Signal Handling" chapter of the Compaq C RTL Reference Manual. for more information on the interaction of OpenVMS exceptions and UNIX style signals. Calling VAXC$ESTABLISH with an argument of NULL cancels an existing handler in that routine. NOTES o On OpenVMS Alpha systems, VAXC$ESTABLISH is implemented as a compiler built-in function, not as a Compaq C RTL function. (Alpha only) o On OpenVMS VAX systems, programs compiled with /NAMES=AS_ IS should link against SYS$LIBRARY:DECCRTL.OLB to resolve the name VAXC$ESTABLISH, whether or not the program is compiled with the /PREFIX_LIBRARY_ENTRIES switch. This is a restriction in the implementation. (VAX only) 2 va_arg Used for returning the next item in the argument list. Format #include (ANSI C) #include (DEC C Extension) type va_arg (va_list ap, type); 3 Arguments ap A variable list containing the next argument to be obtained. type A data type that is used to determine the size of the next item in the list. An argument list can contain items of varying sizes, but the calling routine must determine what type of argument is expected since it cannot be determined at run time. 3 Description This function interprets the object at the address specified by the list incrementor according to type. If there is no corresponding argument, the behavior is undefined. When using va_arg to write portable applications, include the header file (defined by the ANSI C standard), not the header file, and use va_arg only in conjunction with other functions and macros defined in . For an example of argument-list processing using the functions and definitions, see the "Character, String, and Argument-List Functions" chapter of the Compaq C RTL Reference Manual. 2 va_count Returns the number of longwords (VAX only) or quadwords (Alpha only) in the argument list. Format #include (ANSI C) #include (DEC C Extension) void va_count (int count); 3 Argument count An integer variable name in which the number of longwords (VAX only) or quadwords (Alpha only) is returned. 3 Description This function places the number of longwords (VAX only) or quadwords (Alpha only) in the argument list into count. The value returned in count is the number of longwords (VAX only) or quadwords (Alpha only) in the function argument block not counting the count field itself. If the argument list contains items whose storage requirements are a longword (VAX only) or quadword (Alpha only) of memory or less, the number in the count argument is also the number of arguments. However, if the argument list contains items that are longer than a longword (VAX only) or a quadword (Alpha only), count must be interpreted to obtain the number of arguments. Because a double is 8 bytes, it occupies two argument-list positions on OpenVMS VAX systems, and one argument-list position on OpenVMS Alpha systems. This function is specific to Compaq C for OpenVMS Systems and is not portable. 2 va_end Finishes the or session. Format #include (ANSI C) #include (DEC C Extension) void va_end (va_list ap); 3 Argument ap The object used to traverse the argument list length. You must declare and use the argument ap as shown in the format section. 3 Description You can execute multiple traversals of the argument list, each delimited by va_start . . . va_end. The va_end function sets ap equal to NULL. When using this function to write portable applications, include the header file (defined by the ANSI C standard), not the header file, and use va_end only in conjunction with other routines defined in . For an example of argument-list processing using the functions and definitions, see the "Character, String, and Argument-List Functions" chapter of the Compaq C RTL Reference Manual. 2 va_start_1,_va_start Used for initializing a variable to the beginning of the argument list. Format #include (DEC C Extension) void va_start (va_list ap); void va_start_1 (va_list ap, int offset); 3 Arguments ap An object pointer. You must declare and use the argument ap as shown in the format section. offset The number of bytes by which ap is to be incremented so that it points to a subsequent argument within the list (that is, not to the start of the argument list). Using a nonzero offset can initialize ap to the address of the first of the optional arguments that follow a number of fixed arguments. 3 Description The va_start macro initializes the variable ap to the beginning of the argument list. The va_start_1 macro initializes ap to the address of an argument that is preceded by a known number of defined arguments. The printf function is an example of a Compaq C RTL function that contains a variable-length argument list offset from the beginning of the entire argument list. The variable-length argument list is offset by the address of the formatting string. When determining value of the offset argument used in va_start_ 1 the implications of the OpenVMS calling standard must be considered. On OpenVMS VAX, most argument items are a longword. For example, OpenVMS VAX arguments of types char and short use a full longword of memory when they are present in argument lists. However, OpenVMS VAX arguments of type float use two longwords because they are converted to type double. On OpenVMS Alpha, each argument item is a quadword. NOTE When accessing argument lists, especially those passed to a subroutine (written in C) by a program written in another programming language, consider the implications of the OpenVMS calling standard. For more information about the OpenVMS calling standard, see the Compaq C User's Guide for OpenVMS Systems or the OpenVMS Calling Standard. The preceding version of va_start and va_start_1 is specific to the Compaq C RTL, and is not portable. The following syntax describes the va_start macro in the header file, as defined in the ANSI C standard: Format #include (ANSI C) void va_start (va_list ap, parmN); 3 Arguments ap An object pointer. You must declare and use the argument ap as shown in the format section. parmN The name of the last of the known fixed arguments. 3 Description The pointer ap is initialized to point to the first of the optional arguments that follow parmN in the argument list. Always use this version of va_start in conjunction with functions that are declared and defined with function prototypes. Also use this version of va_start to write portable programs. For an example of argument-list processing using the functions and definitions, see the "Character, String, and Argument-List Functions" chapter of the Compaq C RTL Reference Manual. 2 vfork Creates an independent child process. This function is nonreentrant. Format #include int vfork (void); (_DECC_V4_SOURCE) pid_t vfork (void); (not _DECC_V4_SOURCE) 3 Description This function provided by Compaq C for OpenVMS Systems differs from the fork function provided by other C implementations. The vfork and fork Functions shows the two major differences. Table REF-12 The vfork and fork Functions The vfork Function The fork Function Used with the exec Can be used without an exec function for functions. asynchronous processing. Creates an Creates an exact duplicate of the parent independent child process that branches at the point where process that shares vfork is called, as if the parent and the some of child are the same process at different the parent's stages of execution. characteristics. The vfork function provides the setup necessary for a subsequent call to an exec function. Although no process is created by vfork, it performs the following steps: o It saves the return address (the address of the vfork call) to be used later as the return address for the call to an exec function. o It saves the current context. o It returns the integer 0 the first time it is called (before the call to an exec function is made). After the corresponding exec function call is made, the exec function returns control to the parent process, at the point of the vfork call, and it returns the process ID of the child as the return value. Unless the exec function fails, control appears to return twice from vfork even though one call was made to vfork and one call was made to the exec function. The behavior of the vfork function is similar to the behavior of the setjmp function. Both vfork and setjmp establish a return address for later use, both return the integer 0 when they are first called to set up this address, and both pass back the second return value as though it were returned by them rather than by their corresponding exec or longjmp function calls. However, unlike setjmp, with vfork, all local automatic variables, even those with volatile-qualified type, can have indeterminate values if they are modified between the call to vfork and the corresponding call to an exec routine. 3 Return_Values 0 Indicates successful creation of the context. nonzero Indicates the process ID (PID) of the child process. -1 Indicates an error - failure to create the child process. 2 vfprintf Prints formatted output based on an argument list. Format #include int vfprintf (FILE *file_ptr, const char *format, va_list arg); 3 Arguments file_ptr A pointer to the file to which the output is directed. format A pointer to a string containing the format specification. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description See the vprintf and vsprintf functions. 3 Return_Values x The number of bytes written. Negative value Indicates an output error. The function sets errno. For a list of possible errno values set, see fprintf. 2 vfscanf Reads formatted input based on an argument list. Format #include int vfscanf (FILE *file_ptr, const char *format, va_list arg); 3 Arguments file_ptr A pointer to the file that provides input text. format A pointer to a string containing the format specification. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description This function is the same as the fscanf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by va_ start (and possibly subsequent va_arg calls). If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. For more information about format and conversion specifications and their corresponding arguments, see the "Understanding Input and Output" chapter of the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. This functon returns the number of successfully matched and assigned input items. Also see the vscanf and vsscanf functions. 3 Return_Values n The number of successfully matched and assigned input items. EOF Indicates that the end-of-file was encountered or a read error occurred. If a read error occurs, the function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This can indicate that conversion to a numeric value failed due to overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o EVMSERR - Non-translatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 vfwprintf Writes output to the stream under control of the wide-character format string. Format #include int vfwprintf (FILE *stream, const wchar_t *format, va_list arg); 3 Arguments stream A file pointer. format A pointer to a wide-character string containing the format specifications. arg A variable list of the items needed for output. 3 Description This function is equivalent to the fwprintf function, with the variable argument list replaced by the arg argument. Initialize arg with the va_start macro (and possibly with subsequent va_arg calls) from . If the stream pointed to by stream has no orientation, vfwprintf makes the stream wide-oriented. See also fwprintf. 3 Return_Values n The number of wide characters written. Negative value Indicates an error. The function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This might indicate that conversion to a numeric value failed because of overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 3 Examples The following example shows the use of the vfwprintf function in a general error reporting routine. #include #include #include void error(char *function_name, wchar_t *format, . . . ); { va_list args; va_start(args, format); /* print out name of function causing error */ fwprintf(stderr, L"ERROR in %s: ", function_name); /* print out remainder of message */ vfwprintf(stderr, format, args); va_end(args); } 2 vfwscanf Reads input from the stream under control of a wide-character format string. Format #include int vfwscanf (FILE *stream, const wchar_t *format, va_list arg); 3 Arguments stream A file pointer. format A pointer to a wide-character string containing the format specifications. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description This function is equivalent to the fwscanf function, except that instead of being called with a variable number of arguments, it is called with an argument list (arg) that has been initialized by va_start (and possibly with subsequent va_arg calls). If the stream pointed to by stream has no orientation, vfwscanf makes the stream wide-oriented. For more information about format and conversion specifications and their corresponding arguments, see the "Understanding Input and Output" chapter of the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. 3 Return_Values n The number of successfully matched and assigned wide-character input items. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see vfscanf. 2 vprintf Prints formatted output based on an argument list. This function is the same as the printf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by the va_start macro (and possibly with subsequent va_arg calls) from . Format #include int vprintf (const char *format, va_list arg); 3 Arguments format A pointer to the string containing the format specification. arg A variable list of the items needed for output. 3 Description See the vfprintf and vsprintf functions. 3 Return_Values x The number of bytes written. Negative value Indicates an output error. The function sets errno. For a list of possible errno values set, see fprintf. 2 vscanf Reads formatted input based on an argument list. Format #include int vscanf (const char *format, va_list arg); 3 Arguments format A pointer to the string containing the format specification. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description This function is the same as the scanf function except that instead of being called with a variable number of arguments, it is called with an argument list (arg) that has been initialized by the va_start macro (and possibly with subsequent va_arg calls). For more information about format and conversion specifications and their corresponding arguments, see the "Understanding Input and Output" chapter of the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. See the description of scanf in the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. Also see the vfscanf and vsscanf functions. 3 Return_Values n The number of successfully matched and assigned input items. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see vfscanf. 2 vsprintf Prints formatted output based on an argument list. This function is the same as the sprintf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by va_ start (and possibly with subsequent va_arg calls). Format #include int vsprintf (char *str, const char *format, va_list arg); 3 Arguments str A pointer to a string that will receive the formatted output. This string is assumed to be large enough to hold the output. format A pointer to a character string that contains the format specification. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Return_Value x The number of bytes written. Negative value Indicates an output error occurred.The function sets errno. For a list of possible errno values set, see fprintf. 2 vsscanf Reads formatted input based on an argument list. Format #include int vsscanf (char *str, const char *format, va_list arg); 3 Arguments str The address of the character string that provides the input text to sscanf. format A pointer to a character string that contains the format specification. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description This function is the same as the sscanf function except that instead of being called with a variable number of arguments, it is called with an argument list that has been initialized by va_ start (and possibly with subsequent va_arg calls). The vsscanf function is also equivalent to the vfscanf function, except that the first argument specifies a wide-character string rather than a stream. Reaching the end of the wide-character string is the same as encountering EOF for the vfscanf function. See also sscanf. For more information about format and conversion specifications and their corresponding arguments, see the "Understanding Input and Output" chapter of the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. 3 Return_Value n The number of successfully matched and assigned input items. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see vfscanf. 2 vswprintf Writes output to the stream under control of the wide-character format string. Format #include int vswprintf (wchar_t *s, size_t n, const wchar_t *format, va_list arg); 3 Arguments s A pointer to a multibyte character sequence. n The maximum number of bytes that comprise the multibyte character. format A pointer to a wide-character string containing the format specifications. arg A variable list of the items needed for output. 3 Description This function is equivalent to the swprintf function, with the variable argument list replaced by the arg argument. Initialize arg with the va_start macro, and possibly with subsequent va_arg calls. See also swprintf. 3 Return_Values n The number of wide characters written. Negative value Indicates an error. The function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This might indicate that conversion to a numeric value failed because of overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 vswscanf Reads input from the stream under control of the wide-character format string. Format #include int vswscanf (wchar_t *s, const wchar_t *format, va_list arg); 3 Arguments s A pointer to a wide-character string from which the input is to be obtained. format A pointer to a wide-character string containing the format specifications. arg A list of expressions whose results correspond to conversion specifications given in the format specification. 3 Description This function is equivalent to the swscanf function, except that instead of being called with a variable number of arguments, it is called with an argument list (arg) that has been initialized by va_start (and possibly with subsequent va_arg calls). The vswscanf function is also equivalent to the vfwscanf function, except that the first argument specifies a wide- character string rather than a stream. Reaching the end of the wide-character string is the same as encountering EOF for the vfwscanf function. Also see vfwscanf and swscanf. For more information about format and conversion specifications and their corresponding arguments, see the "Understanding Input and Output" chapter of the Compaq C Run-Time Library Reference Manual for OpenVMS Systems. 3 Return_Values n The number of wide characters read. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see vfscanf. 2 vwprintf Writes output to an array of wide characters under control of the wide-character format string. Format #include int vwprintf (const wchar_t *format, va_list arg); 3 Arguments format A pointer to a wide-character string containing the format specifications. arg The variable list of items needed for output. 3 Description This function is equivalent to the wprintf function, with the variable argument list replaced by the arg argument. Initialize arg with the va_start macro, and possibly with subsequent va_arg calls. The vwprintf function does not invoke the va_end macro. See also wprintf. 3 Return_Values x The number of wide characters written, not counting the terminating null wide character. Negative value Indicates an error. Either n or more wide characters were requested to be written, or a conversion error occurred, in which case errno is set to EILSEQ. 2 vwscanf Reads input from an array of wide characters under control of a wide-character format string. Format #include int vwscanf (const wchar_t *format, va_list arg); 3 Arguments format A pointer to a wide-character string containing the format specifications. arg A list of expressions whose resultant types correspond to the conversion specifications given in the format specifications. 3 Description This function is equivalent to the wscanf function, except that instead of being called with a variable number of arguments, it is called with an argument list (arg) that has been initialized by va_start (and possibly with subsequent va_arg calls). 3 Return_Values n The number of wide characters read. EOF Indicates that a read error occurred before any conversion. The function sets errno. For a list of the values set by this function, see vfscanf. 2 wait Checks the status of the child process before exiting. A child process is terminated when the parent process terminates. Format #include pid_t wait (int *status); 3 Argument status The address of a location to receive the final status of the terminated child. The child can set the status with the exit function and the parent can retrieve this value by specifying status. 3 Description This function suspends the parent process until the final status of a terminated child is returned from the child. On OpenVMS Version 7.0 and higher systems, the wait function is equivalent to waitpid( 0, status, 0 ) if you include and compile with the _POSIX_EXIT feature-test macro set (either with /DEFINE=_POSIX_EXIT or with #define _POSIX_EXIT at the top of your file, before any file inclusions). 3 Return_Values x The process ID (PID) of the terminated child. If more than one child process was created, wait will return the PID of the terminated child that was most recently created. Subsequent calls will return the PID of the next most recently created, but terminated, child. -1 No child process was spawned. 2 wait3 Waits for a child process to stop or terminate. Format #include pid_t wait3 (int *status_location, int options, struct rusage *resource_usage); 3 Arguments status_location A pointer to a location that contains the termination status of the child process as defined in the header file. Beginning with OpenVMS Version 7.2, when compiled with the _VMS_ WAIT macro defined, this function puts the OpenVMS completion code of the child process at the address specified in the status_ location argument. options Flags that modify the behavior of the function. These flags are defined in the Description section. resource_usage The location of a structure that contains the resource utilization information for terminated child processes. 3 Description This function suspends the calling process until the request is completed, and redefines it so that only the calling thread is suspended. The options argument modifies the behavior of the function. You can combine the flags for the options argument by specifying their bitwise inclusive OR. The flags are: WNOWAIT Specifies that the process whose status is returned in status_location is kept in a waitable state. You can wait for the process again with the same results. WNOHANG Prevents the suspension of the calling process. If there are child processes that stopped or terminated, one is chosen and the waitpid function returns its process ID, as when you do not specify the WNOHANG flag. If there are no terminated processes (that is, if waitpid suspends the calling process without the WNOHANG flag), 0 (zero) is returned. Because you can never wait for process 0, there is no confusion arising from this return. WUNTRACED Specifies that the call return additional information when the child processes of the current process stop because the child process received a SIGTTIN, SIGTTOU, SIGSTOP, or SIGTSTOP signal. If the wait3 function returns because the status of a child process is available, the process ID of the child process is returned. Information is stored in the location pointed to by status_location, if this pointer is not null. The value stored in the location pointed to by status_location is 0 (zero) only if the status is returned from a terminated child process that did one of the following: o Returned 0 from the main function. o Passed 0 as the status argument to the _exit or exit function. Regardless of the status_location value, you can define this information using the macros defined in the header file, which evaluate to integral expressions. In the following macro descriptions, the status_value argument is equal to the integer value pointed to by the status_location argument: WIFEXITED(status_ Evaluates to a nonzero value if status was value) returned for a child process that terminated normally. WEXITSTATUS(status_If the value of WIFEXITED(status_value) is value) nonzero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to the _exit or exit function, or to the value the child process returned from the main function. WIFSIGNALED(status_Evaluates to nonzero value if status was value) returned for a child process that terminated due to the receipt of a signal that was not caught. WTERMSIG(status_ If the value of WIFSIGNALED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the termination of the child process. WIFSTOPPED(status_ Evaluates to a nonzero value if status was value) returned for a child process that is currently stopped. WSTOPSIG(status_ If the value of WIFSTOPPED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the child process to stop. WIFCONTINUED(status_valuates to a nonzero value if status value) was returned for a child process that has continued. If the information stored at the location pointed to by status_ location was stored there by a call to wait3 that specified the WUNTRACED flag, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) o WIFSTOPPED(*status_value) o WIFCONTINUED(*status_value) If the information stored in the location pointed to by status_ location resulted from a call to wait3 without the WUNTRACED flag specified, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) The wait3 function provides compatibility with BSD systems. The resource_usage argument points to a location that contains resource usage information for the child processes as defined in the header file. If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes is assigned a parent process ID equal to the process ID of the init process. See also exit, -exit, and init. 3 Return_Values 0 Indicates success. There are no stopped or exited child processes, the WNOHANG option is specified. x The process_id of the child process. Status of a child process is available. -1 Indicates an error; errno is set to one of the following values: o ECHILD - There are no child processes to wait for. o EINTR - Terminated by receipt of a signal caught by the calling process. o EFAULT - The status_location or resource_ usage argument points to a location outside of the address space of the process. o EINVAL- The value of the options argument is not valid. 2 wait4 Waits for a child process to stop or terminate. Format #include pid_t wait4 (pid_t process_id, union wait *status_location, int options, struct rusage *resource_usage); 3 Arguments status_location A pointer to a location that contains the termination status of the child process as defined in the header file. Beginning with OpenVMS Version 7.2, when compiled with the _VMS_ WAIT macro defined, this function puts the OpenVMS completion code of the child process at the address specified in the status_ location argument. process_id The child process or set of child processes. options Flags that modify the behavior of the function. These flags are defined in the Description section. resource_usage The location of a structure that contains the resource utilization information for terminated child processes. 3 Description This function suspends the calling process until the request is completed. The process_id argument allows the calling process to gather status from a specific set of child processes, according to the following rules: If the process_ id is Then status is requested Equal to -1 For any child process. In this respect, the waitpid function is equivalent to the wait function. Greater than For a single child process and specifies the 0 process ID. The wait4 function only returns the status of a child process from this set. The options argument to the wait4 function modifies the behavior of the function. You can combine the flags for the options argument by specifying their bitwise-inclusive OR. The flags are: WNOWAIT Specifies that the process whose status is returned in status_location is kept in a waitable state. You can wait for the process again with the same results. WNOHANG Prevents the suspension of the calling process. If there are child processes that stopped or terminated, one is chosen and the waitpid function returns its process ID, as when you do not specify the WNOHANG flag. If there are no terminated processes (that is, if waitpid suspends the calling process without the WNOHANG flag), 0 is returned. Because you can never wait for process 0, there is no confusion arising from this return. WUNTRACED Specifies that the call return additional information when the child processes of the current process stop because the child process received a SIGTTIN, SIGTTOU, SIGSTOP, or SIGTSTOP signal. If the wait4 function returns because the status of a child process is available, the process ID of the child process is returned. Information is stored in the location pointed to by status_location, if this pointer is not null. The value stored in the location pointed to by status_location is 0 only if the status is returned from a terminated child process that did one of the following: o Returned 0 from the main function. o Passed 0 as the status argument to the _exit or exit function. Regardless of the status_location value, you can define this information using the macros defined in the header file, which evaluate to integral expressions. In the following macro descriptions, status_value is equal to the integer value pointed to by status_location: WIFEXITED(status_ Evaluates to a nonzero value if status was value) returned for a child process that terminated normally. WEXITSTATUS(status_If the value of WIFEXITED(status_value) is value) nonzero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to the _exit or exit function, or to the value the child process returned from the main function. WIFSIGNALED(status_Evaluates to nonzero value if status was value) returned for a child process that terminated due to the receipt of a signal that was not caught. WTERMSIG(status_ If the value of WIFSIGNALED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the termination of the child process. WIFSTOPPED(status_ Evaluates to a nonzero value if status was value) returned for a child process that is currently stopped. WSTOPSIG(status_ If the value of WIFSTOPPED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the child process to stop. WIFCONTINUED(status_valuates to a nonzero value if status value) was returned for a child process that has continued. If the information stored at the location pointed to by status_ location was stored there by a call to wait4 that specified the WUNTRACED flag, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) o WIFSTOPPED(*status_value) o WIFCONTINUED(*status_value) If the information stored in the location pointed to by status_ location resulted from a call to wait4 without the WUNTRACED flag specified, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) The wait4 function is similar to the wait3 function. However, the wait4 function waits for a specific child as indicated by the process_id argument. The resource_usage argument points to a location that contains resource usage information for the child processes as defined in the header file. See also exit and _exit. 3 Return_Values 0 Indicates success. There are no stopped or exited child processes, the WNOHANG option is specified. x The process_id of the child process. Status of a child process is available. -1 Indicates an error; errno is set to one of the following values: o ECHILD - There are no child processes to wait for. o EINTR - Terminated by receipt of a signal caught by the calling process. o EFAULT - The status_location or resource_ usage argument points to a location outside of the address space of the process. o EINVAL- The value of the options argument is not valid. 2 waitpid Waits for a child process to stop or terminate. Format #include pid_t waitpid (pid_t process_id, int *status_location, int options); 3 Arguments process_id The child process or set of child processes. status_location A pointer to a location that contains the termination status of the child process as defined in the header file. Beginning with OpenVMS Version 7.2, when compiled with the _VMS_ WAIT macro defined, this function puts the OpenVMS completion code of the child process at the address specified in the status_ location argument. options Flags that modify the behavior of the function. These flags are defined in the Description section. 3 Description This function suspends the calling process until the request is completed. It is redefined so that only the calling thread is suspended. If the process_id argument is -1 and the options argument is 0, the waitpid function behaves the same as the wait function. If these arguments have other values, the waitpid function is changed as specified by those values. The process_id argument allows the calling process to gather status from a specific set of child processes, according to the following rules: If the process_ id is Then status is requested Equal to -1 For any child process. In this respect, the waitpid function is equivalent to the wait function. Greater than For a single child process and specifies the 0 process ID. The waitpid function only returns the status of a child process from this set. The options argument to the waitpid function modifies the behavior of the function. You can combine the flags for the options argument by specifying their bitwise-inclusive OR. The flags are: WCONTINUED Specifies that the following is reported to the calling process: the status of any continued child process specified by the process_id argument whose status is unreported since it continued. WNOWAIT Specifies that the process whose status is returned in status_location is kept in a waitable state. You can wait for the process again with the same results. WNOHANG Prevents the calling process from being suspended. If there are child processes that stopped or terminated, one is chosen and waitpid returns its pid, as when you do not specify the WNOHANG flag. If there are no terminated processes (that is, if waitpid suspends the calling process without the WNOHANG flag), 0 (zero) is returned. Because you can never wait for process 0, there is no confusion arising from this return. WUNTRACED Specifies that the call return additional information when the child processes of the current process stop because the child process received a SIGTTIN, SIGTTOU, SIGSTOP, or SIGTSTOP signal. If the waitpid function returns because the status of a child process is available, the process ID of the child process is returned. Information is stored in the location pointed to by status_location, if this pointer is not null. The value stored in the location pointed to by status_location is 0 only if the status is returned from a terminated child process that did one of the following: o Returned 0 from the main function. o Passed 0 as the status argument to the _exit or exit function. Regardless of the value of status_location, you can define this information using the macros defined in the header file, which evaluate to integral expressions. In the following function descriptions, status_value is equal to the integer value pointed to by status_location: WIFEXITED(status_ Evaluates to a nonzero value if status was value) returned for a child process that terminated normally. WEXITSTATUS(status_If the value of WIFEXITED(status_value) is value) nonzero, this macro evaluates to the low-order 8 bits of the status argument that the child process passed to the _exit or exit function, or to the value the child process returned from the main function. WIFSIGNALED(status_Evaluates to nonzero value if status returned value) for a child process that terminated due to the receipt of a signal not caught. WTERMSIG(status_ If the value of WIFSIGNALED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the termination of the child process. WIFSTOPPED(status_ Evaluates to a nonzero value if status was value) returned for a child process that is currently stopped. WSTOPSIG(status_ If the value of WIFSTOPPED(status_value) is value) nonzero, this macro evaluates to the number of the signal that caused the child process to stop. WIFCONTINUED(status_valuates to a nonzero value if status value) returned for a child process that continued. If the information stored at the location pointed to by status_ location is stored there by a call to waitpid that specified the WUNTRACED flag, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) o WIFSTOPPED(*status_value) o WIFCONTINUED(*status_value) If the information stored in the buffer pointed to by status_ location resulted from a call to waitpid without the WUNTRACED flag specified, one of the following macros evaluates to a nonzero value: o WIFEXITED(*status_value) o WIFSIGNALED(*status_value) If a parent process terminates without waiting for all of its child processes to terminate, the remaining child processes is assigned a parent process ID equal to the process ID of the init process. See also exit, _exit, and wait. 3 Return_Values 0 Indicates success. If the WNOHANG option was specified, and there are no stopped or exited child processes, the waitpid function also returns a value of 0. -1 Indicates an error; errno is set to one of the following values: o ECHILD-The calling process has no existing unwaited-for child processes. The process or process group ID specified by the process_id argument does not exist or is not a child process of the calling process. o EINTR-The function was terminated by receipt of a signal. If the waitpid function returns because the status of a child process is available, the process ID of the child is returned to the calling process. If they return because a signal was caught by the calling process, -1 is returned. o EFAULT- The status_location argument points to a location outside of the address space of the process. o EINVAL- The value of the options argument is not valid. 2 wcrtomb Converts the wide character to its multibyte character representation. Format #include size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps); 3 Arguments s A pointer to the resulting multibyte character. wc A wide character. ps A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state-dependent codesets. 3 Description If s is a NULL pointer, the wcrtomb function is equivalent to the call: wcrtomb (buf, L'\0', ps) where buf is an internal buffer. If s is not a NULL pointer, the wcrtomb function determines the number of bytes needed to represent the multibyte character that corresponds to the wide character specified by wc (including any shift sequences), and stores the resulting bytes in the array whose first element is pointed to by s. At most MB_CUR_MAX bytes are stored. If wc is a null wide character, a null byte is stored preceded by any shift sequence needed to restore the initial shift state. The resulting state described is the initial conversion state. 3 Return_Values n The number of bytes stored in the resulting array, including any shift sequences to represent the multibyte character. -1 Indicates an encoding error. The wc argument is not a valid wide character. The global errno is set to EILSEQ; the conversion state is undefined. 2 wcscat Concatenates two wide-character strings. Format #include wchar_t *wcscat (wchar_t *wstr_1, const wchar_t *wstr_2); 3 Function_Variants This function also has variants named _wcscat32 and _wcscat64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr_1, wstr_2 Pointers to null-terminated wide-character strings. 3 Description This function appends the wide-character string wstr_2, including the terminating null character, to the end of wstr_1. See also wcsncat. 3 Return_Values x The first argument, wstr_1, which is assumed to be large enough to hold the concatenated result. 3 Example #include #include #include #include /* This program concatenates two wide-character strings using */ /* the wcscat function, and then manually compares the result */ /* to the expected result */ #define S1LENGTH 10 #define S2LENGTH 8 main() { int i; wchar_t s1buf[S1LENGTH + S2LENGTH]; wchar_t s2buf[S2LENGTH]; wchar_t test1[S1LENGTH + S2LENGTH]; /* Initialize the three wide-character strings */ if (mbstowcs(s1buf, "abcmnexyz", S1LENGTH) == (size_ t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } if (mbstowcs(s2buf, " orthis", S2LENGTH) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } if (mbstowcs(test1, "abcmnexyz orthis", S1LENGTH + S2LENGTH) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Concatenate s1buf with s2buf, placing the result into */ /* s1buf. Then compare s1buf with the expected result */ /* in test1. */ wcscat(s1buf, s2buf); for (i = 0; i < S1LENGTH + S2LENGTH - 2; i++) { /* Check that each character is correct */ if (test1[i] != s1buf[i]) { printf("Error in wcscat\n"); exit(EXIT_FAILURE); } } printf("Concatenated string: <%S>\n", s1buf); } Running the example produces the following result: Concatenated string: 2 wcschr Scans for a wide character in a specifed wide-character string. Format #include wchar_t *wcschr (const wchar_t *wstr, wchar_t wc); 3 Function_Variants This function also has variants named _wcschr32 and _wcschr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr A pointer to a null-terminated wide-character string. wc A character of type wchar_t. 3 Description This function returns the address of the first occurrence of a specified wide character in a null-terminated wide-character string. The terminating null character is considered to be part of the string. See also wcsrchr. 3 Return_Values x The address of the first occurrence of the specified wide character. NULL Indicates that the wide character does not occur in the string. 3 Example #include #include #include #include #define BUFF_SIZE 50 main() { int i; wchar_t s1buf[BUFF_SIZE]; wchar_t *status; /* Initialize the buffer */ if (mbstowcs(s1buf, "abcdefghijkl lkjihgfedcba", BUFF_ SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* This program checks the wcschr function by incrementally */ /* going through a string that ascends to the middle and then */ /* descends towards the end. */ for (i = 0; (s1buf[i] != '\0') && (s1buf[i] != ' '); i++) { status = wcschr(s1buf, s1buf[i]); /* Check for pointer to leftmost character - test 1. */ if (status != &s1buf[i]) { printf("Error in wcschr\n"); exit(EXIT_FAILURE); } } printf("Program completed successfully\n"); } When this example program is run, it produces the following result: Program completed successfully 2 wcscmp Compares two wide-character strings. It returns an integer that indicates if the strings are different, and how they differ. Format #include int wcscmp (const wchar_t *wstr_1, const wchar_t *wstr_2); 3 Arguments wstr_1, wstr_2 Pointers to null-terminated wide-character strings. 3 Description This function compares the wide characters in wstr_1 with those in wstr_2. If the characters differ, the function returns: o An integer less than 0, if the codepoint of the first differing character in wstr_1 is less than the codepoint of the corresponding character in wstr_2 o An integer greater than 0, if the codepoint of the first differing character in wstr_1 is greater than the codepoint of the corresponding character in wstr_2 If the wide-characters strings are identical, the function returns zero. Unlike the wcscoll function, the wcscmp function compares the string based on the binary value of each wide character. See also wcsncmp. 3 Return_Values < 0 Indicates that wstr_1 is less than wstr_2. = 0 Indicates that wstr_1 equals wstr_2. > 0 Indicates that wstr_1 is greater than wstr_2. 2 wcscoll Compares two wide-character strings and returns an integer that indicates if the strings differ, and how they differ. The function uses the collating information in the LC_COLLATE category of the current locale to determine how the comparison is performed. Format #include int wcscoll (const wchar_t *ws1, const wchar_t *ws2); 3 Arguments ws1, ws2 Pointers to wide-character strings. 3 Description This function, unlike wcscmp, compares two strings in a locale- dependent manner. Because no value is reserved for error indication, the application must check for one by setting errno to 0 before the function call and testing it after the call. See also the wcsxfrm function. 3 Return_Values < 0 Indicates that ws1 is less than ws2. 0 Indicates that the strings are equal. > 0 Indicates that ws1 is greater than ws2. 2 wcscpy Copies the wide-character string source, including the terminating null character, into dest. Format #include wchar_t *wcscpy (wchar_t *dest, const wchar_t *source); 3 Function_Variants This function also has variants named _wcscpy32 and _wcscpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest Pointer to the null-terminated wide-character destination string. source Pointer to the null-terminated wide-character source string. 3 Description This function copies source into dest, and stops after copying source's null character. If copying takes place between two ovelapping strings, the behavior is undefined. See also wcsncpy. 3 Return_Values x The address of source. 2 wcscspn Compares the characters in a wide-character string against a set of wide characters. The function returns the length of the initial substring that is comprised entirely of characters that are not in the set of wide characters. Format #include size_t wcscspn (const wchar_t *wstr1, const wchar_t *wstr2); 3 Arguments wstr1 A pointer to a null-terminated wide-character string. If this is a null string, 0 is returned. wstr2 A pointer to a null-terminated wide-character string that contains the set of wide characters for which the function will search. 3 Description This function scans the wide characters in the string pointed to by wstr1 until it encounters a character found in wstr2. The function returns the length of the initial segment of wstr1 that is formed by characters not found in wstr2. 3 Return_Values x The length of the segment. 3 Example #include #include #include #include /* This test sets up 2 strings, buffer and w_string, and then */ /* uses wcscspn() to calculate the maximum segment of w_string, */ /* which consists entirely of characters NOT from buffer. */ #define BUFF_SIZE 20 #define STRING_SIZE 50 main() { wchar_t buffer[BUFF_SIZE]; wchar_t w_string[STRING_SIZE]; size_t result; /* Initialize the buffer */ if (mbstowcs(buffer, "abcdefg", BUFF_SIZE) == (size_ t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Initialize the string */ if (mbstowcs(w_string, "jklmabcjklabcdehjklmno", STRING_ SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Using wcscspn - work out the largest string in w_string which */ /* consists entirely of characters NOT from buffer */ result = wcscspn(w_string, buffer); printf("Longest segment NOT found in w_ string is: %d", result); } Running the example program produces the following result: Longest segment NOT found in w_string is: 4 2 wcsftime Uses date and time information stored in a tm structure to create a wide-character output string. The format of the output string is controlled by a format string. Format #include size_t wcsftime (wchar_t *wcs, size_t maxsize, const char *format, const struct tm *timeptr); (XPG4) size_t wcsftime (wchar_t *wcs, size_t maxsize, const wchar_t *format, const struct tm *timeptr); (ISO C) 3 Function_Variants Compiling with the _DECC_V4_SOURCE and _VMS_V6_SOURCE feature- test macros defined enables a local-time-based entry point to this function that is equivalent to the behavior before OpenVMS Version 7.0. 3 Arguments wcs A pointer to the resultant wide-character string. maxsize The maximum number of wide characters to be stored in the resultant string. format A pointer to the string that controls the format of the output string. For the XPG4 interface, this argument is a pointer to a constant character string. For the ISO C interface, it is a pointer to a constant wide-character string. timeptr A pointer to the local time structure. The tm structure is defined in the header file. 3 Description This function uses data in the structure pointed to by timeptr to create the wide-character string pointed to by wcs. A maximum of maxsize wide characters is copied to wcs. The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters (including the terminating null character) are copied unchanged into the output string. A conversion specification defines how data in the tm structure is formatted in the output string. A conversion specification consists of a percent (%) character followed by one or more optional characters (see Optional Elements of wcsftime Conversion Specifications), and ending with a conversion specifier (see wcsftime Conversion Specifiers). If any of the optional characters listed in Optional Elements of wcsftime Conversion Specifications are specified, they must appear in the order shown in the table. Table REF-13 Optional Elements of wcsftime Conversion Specifications Element Meaning - Optional with the field width to specify that the field is left-justified and padded with spaces. This cannot be used with the 0 element. 0 Optional with the field width to specify that the field is right-justified and padded with zeros. This cannot be used with the - element. field A decimal integer that specifies the maximum field width width .precisioA decimal integer that specifies the precision of data in a field. For the d, H, I, j, m, M, o, S, U, w, W, y and Y conversion specifiers, the precision specifier is the minimum number of digits to appear in the field. If the conversion specification has fewer digits than that specified by the precision, leading zeros are added. For the a, A, b, B, c, D, E, h, n, N, p, r, t, T, x, X, Z, and % conversion specifiers, the precision specifier is the maximum number of wide characters to appear in the field. If the conversion specification has more characters than that specified by the the precision, characters are truncated on the right. The default precision for the d, H, I, m, M, o, S, U, w, W, y and Y conversion specifiers is 2, and the default precision for the j conversion specifier is 3. Note that the list of optional elements of conversion specifications from Optional Elements of wcsftime Conversion Specifications are Compaq extensions to the XPG4 specification. wcsftime Conversion Specifiers lists the conversion specifiers. The wcsftime function uses fields in the LC_TIME category of the program's current locale to provide a value. For example, if %B is specified, the function accesses the mon field in LC_TIME to find the full month name for the month specified in the tm structure. The result of using invalid conversion specifiers is undefined. Table REF-14 wcsftime Conversion Specifiers SpecifierReplaced by a The locale's abbreviated weekday name A The locale's full weekday name b The locale's abbreviated month name B The locale's full month name c The locale's appropriate date and time representation C The century number (the year divided by 100 and truncated to an integer) as a decimal number (00 - 99) d The day of the month as a decimal number (01 - 31) D Same as %m/%d/%y e The day of the month as a decimal number (1 - 31) in a 2 digit field with the leading space character fill Ec The locale's alternative date and time representation EC The name of the base year (period) in the locale's alternative representation Ex The locale's alternative date representation Ey The offset from the base year (%EC) in the locale's alternative representation EY The locale's full alternative year representation h Same as %b H The hour (24-hour clock) as a decimal number (00 - 23) I The hour (12-hour clock) as a decimal number (01 - 12) j The day of the year as a decimal number (001 - 366) m The month as a decimal number (01 - 12) M The minute as a decimal number (00 - 59) n The newline character Od The day of the month using the locale's alternative numeric symbols Oe The date of the month using the locale's alternative numeric symbols OH The hour (24-hour clock) using the locale's alternative numeric symbols OI The hour (12-hour clock) using the locale's alternative numeric symbols Om The month using the locale's alternative numeric symbols OM The minutes using the locale's alternative numeric symbols OS The seconds using the locale's alternative numeric symbols Ou The weekday as a number in the locale's alternative representation (Monday=1) OU The week number of the year (Sunday as the first day of the week) using the locale's alternative numeric symbols OV The week number of the year (Monday as the first day of the week) as a decimal number (01 -53) using the locale's alterntative numeric symbols. If the week containing January 1 has four or more days in the new year, it is considered as week 1. Otherwise, it is considered as week 53 of the previous year, and the next week is week 1. Ow The weekday as a number (Sunday=0) using the locale's alternative numeric symbols OW The week number of the year (Monday as the first day of the week) using the locale's alternative numeric symbols Oy The year without the century using the locale's alternative numeric symbols p The locale's equivalent of the AM/PM designations associated with a 12-hour clock r The time in AM/PM notation R The time in 24-hour notation (%H:%M) S The second as a decimal number (00 - 61) t The tab character T The time (%H:%M:%S) u The weekday as a decimal number between 1 and 7 (Monday=1) U The week number of the year (the first Sunday as the first day of week 1) as a decimal number (00 - 53) V The week number of the year (Monday as the first day of the week) as a decimal number (00 - 53). If the week containing January 1 has four or more days in the new year, it is considered as week 1. Otherwise, it is considered as week 53 of the previous year, and the next week is week 1. w The weekday as a decimal number (0 [Sunday] - 6) W The week number of the year (the first Monday as the first day of week 1) as a decimal number (00 - 53) x The locale's appropriate date representation X The locale's appropriate time representation y The year without century as a decimal number (00 - 99) Y The year with century as a decimal number Z Time-zone name or abbreviation. If time-zone information is not available, no character is output. % % 3 Return_Values x The number of wide characters placed into the array pointed to by wcs, not including the terminating null character. 0 Indicates an error occurred. The contents of the array are indeterminate. 3 Example /* Exercize the wcsftime formating routine. */ /* NOTE: the format string is an "L" (or wide character) */ /* string indicating that this call is NOT in */ /* the XPG4 format, but rather in ISO C format. */ #include #include #include #include #include #include #define NUM_OF_DATES 7 #define BUF_SIZE 256 /* This program formats a number of different dates, once */ /* using the C locale and then using the fr_FR.ISO8859-1 */ /* locale. Date and time formatting is done using wcsftime(). */ main() { int count, i; wchar_t buffer[BUF_SIZE]; struct tm *tm_ptr; time_t time_list[NUM_OF_DATES] = {500, 68200000, 694223999, 694224000, 704900000, 705000000, 705900000}; /* Display dates using the C locale */ printf("\nUsing the C locale:\n\n"); setlocale(LC_ALL, "C"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = wcsftime(buffer, BUF_ SIZE, L"Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("wcsftime"); exit(EXIT_FAILURE); } /* Print the result */ printf("%S", buffer); } /* Display dates using the fr_FR.ISO8859-1 locale */ printf("\nUsing the fr_FR.ISO8859-1 locale:\n\n"); setlocale(LC_ALL, "fr_FR.ISO8859-1"); for (i = 0; i < NUM_OF_DATES; i++) { /* Convert to a tm structure */ tm_ptr = localtime(&time_list[i]); /* Format the date and time */ count = wcsftime(buffer, BUF_ SIZE, L"Date: %A %d %B %Y%nTime: %T%n%n", tm_ptr); if (count == 0) { perror("wcsftime"); exit(EXIT_FAILURE); } /* Print the result */ printf("%S", buffer); } } Running the example program produces the following result: Using the C locale: Date: Thursday 01 January 1970 Time: 00:08:20 Date: Tuesday 29 February 1972 Time: 08:26:40 Date: Tuesday 31 December 1991 Time: 23:59:59 Date: Wednesday 01 January 1992 Time: 00:00:00 Date: Sunday 03 May 1992 Time: 13:33:20 Date: Monday 04 May 1992 Time: 17:20:00 Date: Friday 15 May 1992 Time: 03:20:00 Using the fr_FR.ISO8859-1 locale: Date: jeudi 01 janvier 1970 Time: 00:08:20 Date: mardi 29 février 1972 Time: 08:26:40 Date: mardi 31 décembre 1991 Time: 23:59:59 Date: mercredi 01 janvier 1992 Time: 00:00:00 Date: dimanche 03 mai 1992 Time: 13:33:20 Date: lundi 04 mai 1992 Time: 17:20:00 Date: vendredi 15 mai 1992 Time: 03:20:00 2 wcslen Returns the number of wide characters in a wide-character string. The returned length does not include the terminating null character. Format #include size_t wcslen (const wchar_t *wstr); 3 Arguments wstr A pointer to a null-terminated wide-character string. 3 Return_Values x The length of the wide-character string, excluding the terminating null wide character. 2 wcsncat Concatenates a counted number of wide-characters from one string to another. Format #include wchar_t *wcsncat (wchar_t *wstr_1, const wchar_t *wstr_2, size_t maxchar); 3 Function_Variants This function also has variants named _wcsncat32 and _wcsncat64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr_1, wstr_2 Pointers to null-terminated wide-character strings. maxchar The maximum number of wide characters from wstr_2 that are copied to wstr_1. If maxchar is 0, no characters are copied from wstr_2. 3 Description This function appends wide characters from the wide-character string wstr_2 to the end of wstr_1, up to a maximum of maxchar characters. A terminating null wide character is always appended to the result of the wcsncat function. Therefore, the maximum number of wide characters that can end up in wstr_1 is wcslen(wstr_1) + maxchar + 1). See also wcscat. 3 Return_Values x The first argument, wstr_1, which is assumed to be large enough to hold the concatenated result. 3 Example #include #include #include #include /* This program concatenates two wide-character strings using */ /* the wcsncat function, and then manually compares the result */ /* to the expected result */ #define S1LENGTH 10 #define S2LENGTH 8 #define SIZE 3 main() { int i; wchar_t s1buf[S1LENGTH + S2LENGTH]; wchar_t s2buf[S2LENGTH]; wchar_t test1[S1LENGTH + S2LENGTH]; /* Initialize the three wide-character strings */ if (mbstowcs(s1buf, "abcmnexyz", S1LENGTH) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } if (mbstowcs(s2buf, " orthis", S2LENGTH) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } if (mbstowcs(test1, "abcmnexyz orthis", S1LENGTH + SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Concatenate s1buf with SIZE characters from s2buf, placing the */ /* result into s1buf. Then compare s1buf with the expected result */ /* in test1. */ wcsncat(s1buf, s2buf, SIZE); for (i = 0; i <= S1LENGTH + SIZE - 2; i++) { /* Check that each character is correct */ if (test1[i] != s1buf[i]) { printf("Error in wcsncat\n"); exit(EXIT_FAILURE); } } printf("Concatenated string: <%S>\n", s1buf); } Running the example produces the following result: Concatenated string: 2 wcsncmp Compares not more than maxchar characters of two wide-character strings. It returns an integer that indicates if the strings are different, and how they differ. Format #include int wcsncmp (const wchar_t *wstr_1, const wchar_t *wstr_2, size_t maxchar); 3 Arguments wstr_1, wstr_2 Pointers to null-terminated wide-character strings. maxchar The maximum number of characters to search in both wstr_1 and wstr_2. If maxchar is 0, no comparison is performed and 0 is returned (the strings are considered equal). 3 Description The strings are compared until a null character is encountered, the strings differ, or maxchar is reached. If characters differ, the function returns: o An integer less than 0 if the codepoint of the first differing character in wstr_1 is less than the codepoint of the corresponding character in wstr_2 o An integer greater than 0 if the codepoint of the first differing character in wstr_1 is greater than the codepoint of the corresponding character in wstr_2 If no differences are found after comparing maxchar characters, the function returns zero. See also wcscmp. 3 Return_Values < 0 Indicates that wstr_1 is less than wstr_2. 0 Indicates that wstr_1 equals wstr_2. > 0 Indicates that wstr_1 is greater than wstr_2. 2 wcsncpy Copies wide characters from source into dest. The function copies up to a maximum of maxchar characters. Format #include wchar_t *wcsncpy (wchar_t *dest, const wchar_t *source, size_t maxchar); 3 Function_Variants This function also has variants named _wcsncpy32 and _wcsncpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest Pointer to the null-terminated wide-character destination string. source Pointer to the null-terminated wide-character source string. maxchar The maximum number of wide characters to copy from source to dest. 3 Description This function copies no more than maxchar characters from source to dest. If source contains less than maxchar characters, null characters are added to dest until maxchar characters have been written to dest. If source contains maxchar or more characters, as many characters as possible are copied to dest. The null terminator of source is not copied to dest. See also wcscpy. 3 Return_Values x The address of dest. 2 wcspbrk Searches a wide-character string for the first occurrence of one of a specified set of wide characters. Format #include wchar_t *wcspbrk (const wchar_t *wstr, const wchar_t *charset); 3 Function_Variants This function also has variants named _wcspbrk32 and _wcspbrk64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr A pointer to a wide-character string. If this is a null string, NULL is returned. charset A pointer to a wide-character string containing the set of wide characters for which the function will search. 3 Description This function scans the wide characters in the string, stops when it encounters a wide character found in charset, and returns the address of the first character in the string that appears in the character set. 3 Return_Values x The address of the first wide character in the string that is in the set. NULL Indicates that none of the characters are in charset. 2 wcsrchr Scans for the last occurrence of a wide-character in a given string. Format #include wchar_t *wcsrchr (const wchar_t *wstr, wchar_t wc); 3 Function_Variants This function also has variants named _wcsrchr32 and _wcsrchr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr A pointer to a null-terminated wide-character string. wc A character of type wchar_t. 3 Description This function returns the address of the last occurrence of a given wide character in a null-terminated wide-character string. The terminating null character is considered to be part of the string. See also wcschr. 3 Return_Values x The address of the last occurrence of the specified wide character. NULL Indicates that the wide character does not occur in the string. 3 Example #include #include #include #include #define BUFF_SIZE 50 #define STRING_SIZE 6 main() { int i; wchar_t s1buf[BUFF_SIZE], w_string[STRING_SIZE]; wchar_t *status; wchar_t *pbuf = s1buf; /* Initialize the buffer */ if (mbstowcs(s1buf, "hijklabcdefg ytuhijklfedcba", BUFF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Initialize the string to be searched for */ if (mbstowcs(w_string, "hijkl", STRING_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* This program checks the wcsrchr function by searching for the */ /* last occurrence of a string in the buffer s1buf and prints out */ /* the contents of s1buff from the location of the string found. */ status = wcsrchr(s1buf, w_string[0]); /* Check for pointer to start of rightmost character string. */ if (status == pbuf) { printf("Error in wcsrchr\n"); exit(EXIT_FAILURE); } printf("Program completed successfully\n"); printf("String found : [%S]\n", status); } Running the example produces the following result: Program completed successfully String found : [hijklfedcba] 2 wcsrtombs Converts a sequence of wide characters into a sequence of corresponding multibyte characters. Format #include size_t wcsrtombs (char *dst, const wchar_t **src, size_t len, mbstate_t *ps); 3 Function_Variants This function also has variants named _wcsrtombs32 and _ wcsrtombs64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dst A pointer to the destination array for converted multibyte character sequence. src An address of the pointer to an array containing the sequence of wide characters to be converted. len The maximum number of bytes that can be stored in the array pointed to by dst. ps A pointer to the mbstate_t object. If a NULL pointer is specified, the function uses its internal mbstate_t object. mbstate_t is an opaque datatype intended to keep the conversion state for the state-dependent codesets. 3 Description This function converts a sequence of wide characters from the array indirectly pointed to by src into a sequence of corresponding multibyte characters, beginning in the conversion state described by the object pointed to by ps. If dst is a not NULL pointer, the converted characters are then stored into the array pointed to by dst. Conversion continues up to and including a terminating null wide character, which is also stored. Conversion stops earlier in two cases: o When a code is reached that does not correspond to a valid multibyte character o If dst is not a NULL pointer, when the next multibyte character would exceed the limit of len total bytes to be stored into the array pointed to by dst Each conversion takes place as if by a call to the wcrtomb function. If dst is not a NULL pointer, the pointer object pointed to by src is assigned either a NULL pointer, (if the conversion stopped because it reached a terminating null wide character) or the address just beyond the last wide character converted (if any). If conversion stopped because it reached a terminating null wide character, the resulting state described is the initial conversion state. If the wcsrtombs function is called as a counting function, which means that dst is a NULL pointer, the value of the internal mbstate_t object will remain unchanged. See also wcrtomb. 3 Return_Values x The number of bytes stored in the resulting array, not including the terminating null (if any). -1 Indicates an encoding error-a character that does not correspond to a valid multibyte character was encountered; errno is set to EILSEQ; the conversion state is undefined. 2 wcsspn Compares the characters in a wide-character string against a set of wide characters. The function returns the length of the first substring comprised entirely of characters in the set of wide characters. Format #include size_t wcsspn (const wchar_t *wstr1, const wchar_t *wstr2); 3 Arguments wstr1 A pointer to a null-terminated wide-character string. If this string is a null string, 0 is returned. wstr2 A pointer to a null-terminated wide-character string that contains the set of wide characters for which the function will search. 3 Description This function scans the wide characters in the wide-character string pointed to by wstr1 until it encounters a character not found in wstr2. The function returns the length of the first segment of wstr1 formed by characters found in wstr2. 3 Return_Values x The length of the segment. 3 Example #include #include #include #include /* This test sets up 2 strings, buffer and w_string. It then */ /* uses wcsspn() to calculate the maximum segment of w_string */ /* that consists entirely of characters from buffer. */ #define BUFF_SIZE 20 #define STRING_SIZE 50 main() { wchar_t buffer[BUFF_SIZE]; wchar_t w_string[STRING_SIZE]; size_t result; /* Initialize the buffer */ if (mbstowcs(buffer, "abcdefg", BUFF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Initialize the string */ if (mbstowcs(w_string, "abcedjklmabcjklabcdehjkl", STRING_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Using wcsspn - work out the largest string in w_string that */ /* consists entirely of characters from buffer */ result = wcsspn(w_string, buffer); printf("Longest segment found in w_string is: %d", result); } Running the example program produces the following result: Longest segment found in w_string is: 5 2 wcsstr Locates the first occurrence in the string pointed to by s1 of the sequence of wide characters in the string pointed to by s2. Format #include wchar_t *wcsstr (const wchar_t *s1, const wchar_t *s2); 3 Function_Variants This function also has variants named _wcsstr32 and _wcsstr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s1, s2 Pointers to null-terminated, wide-character strings. 3 Description If s2 points to a wide-character string of zero length, the function returns s1. 3 Return_Values x A pointer to the located string. NULL Indicates an error; the string was not found. 2 wcstod Converts a given wide-character string to a double-precision number. Format #include double wcstod (const wchar_t *nptr, wchar_t **endptr); 3 Arguments nptr A pointer to the wide-character string to be converted to a double-precision number. endptr The address of an object where the function can store the address of the first unrecognized wide character that terminates the scan. If endptr is a NULL pointer, the address of the first unrecognized wide character is not retained. 3 Description This function recognizes an optional sequence of white-space characters (as defined by iswspace), then an optional plus or minus sign, then a sequence of digits optionally containing a radix character, then an optional letter (e or E) followed by an optionally signed integer. The first unrecognized character ends the conversion. The string is interpreted by the same rules used to interpret floating constants. The radix character is defined in the program's current locale (category LC_NUMERIC). This function returns the converted value. For wcstod, overflows are accounted for in the following manner: o If the correct value causes an overflow, HUGE_VAL (with a plus or minus sign according to the sign of the value) is returned and errno is set to ERANGE. o If the correct value causes an underflow, 0 is returned and errno is set to ERANGE. If the string starts with an unrecognized wide character, *endptr is set to nptr and a 0 value is returned. 3 Return_Values x The converted string. 0 Indicates the conversion could not be performed. The function sets errno to one of: o EINVAL - No conversion could be performed. o ERANGE - The value would cause an underflow. o ENOMEM - Not enough memory available for internal conversion buffer. (+/ -)HUGE_VAL Indicates overflow. The function sets errno to ERANGE. 2 wcstok Locates text tokens in a given wide-character string. Format #include wchar_t *wcstok (wchar_t *ws1, const wchar_t *ws2); (XPG4) wchar_t *wcstok (wchar_t *ws1, const wchar_t *ws2, wchar_t **ptr); (ISO C) 3 Function_Variants This function also has variants named _wcstok32 and _wcstok64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments ws1 A pointer to a wide-character string containing 0 or more text tokens. ws2 A pointer to a separator string consisting of one or more wide characters. The separator string can differ from call to call. ptr ISO C Standard only. Used only when ws1 is NULL, ptr is a caller- provided wchar_t pointer into which wcstok stores information necessary for it to continue scanning the same wide-character string. 3 Description A sequence of calls to wcstok breaks the wide-character string pointed to by ws1 into a sequence of tokens, each of which is delimited by a wide character from the wide-character string pointed to by ws2. The wcstok function keeps track of its position in the wide- character string between calls and, as successive calls are made, the function works through the wide-character string, identifying the text token following the one identified by the previous call. Tokens in ws1 are delimited by null characters that wcstok inserts into ws1. Therefore, ws1 cannot be a const object. The following describes differences between the XPG4 Standard and ISO C Standard interface to wcstok. XPG4 Standard Behavior The first call to the wcstok function searches the wide-character string for the first character that is not found in the separator string pointed to by ws2. The first call returns a pointer to the first wide character in the first token and writes a null wide character into ws1 immediately following the returned token. Subsequent calls to wcstok search for a wide character that is in the separator string pointed to by ws2. Each subsequent call (with the value of the first argument remaining NULL) returns a pointer to the next token in the string originally pointed to by ws1. When no tokens remain in the string, wcstok returns a NULL pointer. ISO C Standard Behavior For the first call in the sequence, ws1 points to a wide- character string. In subsequent calls for the same string, ws1 is NULL. When ws1 is NULL, the value pointed to by ptr matches that stored by the previous call for the same wide-character string. Otherwise, the value pointed to by ptr is ignored. The first call in the sequence searches the wide-character string pointed to by ws1 for the first wide character that is not contained in the current separator wide-character string pointed to by ws2. If no such wide character is found, then there are no tokens in the wide-character string pointed to by ws1, and wcstok returns a NULL pointer. The wcstok function then searches from there for a wide character that is contained in the current separator wide-character string. If no such wide character is found, the current token extends to the end of the wide-character string pointed to by ws1, and subsequent searches in the same wide-character string for a token return a NULL pointer. If such a wide character is found, it is overwritten by a null wide character, which terminates the current token. In all cases, wcstok stores sufficient information in the pointer pointed to by ptr so that subsequent calls with a NULL pointer for ws1 and the unmodified pointer value for ptr start searching just past the element overwritten by a null wide character (if any). 3 Return_Values x A pointer to the first character of a token. NULL Indicates that no token was found. 3 Examples 1./* XPG4 version of wcstok call */ #include #include #include main() { wchar_t str[] = L"...ab..cd,,ef.hi"; printf("|%S|\n", wcstok(str, L".")); printf("|%S|\n", wcstok(NULL, L",")); printf("|%S|\n", wcstok(NULL, L",.")); printf("|%S|\n", wcstok(NULL, L",.")); } 2./* ISO C version of wcstok call */ #include #include #include main() { wchar_t str[] = L"...ab..cd,,ef.hi"; wchar_t *savptr = NULL; printf("|%S|\n", wcstok(str, L".", &savptr)); printf("|%S|\n", wcstok(NULL, L",", &savptr)); printf("|%S|\n", wcstok(NULL, L",.", &savptr)); printf("|%S|\n", wcstok(NULL, L",.", &savptr)); } Running this example produces the following results: $ $ RUN WCSTOK_EXAMPLE |ab| |.cd| |ef| |hi| $ 2 wcstol Converts a wide-character string in a specified base to a long integer value. Format #include long int wcstol (const wchar_t *nptr, wchar_t **endptr, int base); 3 Function_Variants This function also has variants named _wcstol32 and _wcstol64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the wide-character string to be converted to a long integer. endptr The address of an object where the function can store a pointer to the first unrecognized character encountered in the conversion process (the character that follows the last character processed in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. If base is 16, leading zeros after the optional sign are ignored, and 0x or 0X is ignored. If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant-After the optional sign: o A leading 0 indicates octal conversion. o A leading 0x or 0X indicates hexadecimal conversion. o Any other combination of leading characters indicates decimal conversion. 3 Description This function recognizes strings in various formats, depending on the value of the base. This function ignores any leading white-space characters (as defined by the iswspace function) in the given string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that can represent an integer constant according to the value of the base. The first unrecognized character ends the conversion. 3 Return_Values x The converted value. 0 Indicates that the string starts with an unrecognized wide character or that the value for base is invalid. If the string starts with an unrecognized wide character, *endptr is set to nptr. The function sets errno to EINVAL. LONG_MAX or LONG_ Indicates that the converted value would cause MIN a positive or negative overflow, respectively. The function sets errno to ERANGE. 2 wcstombs Converts a sequence of wide-character codes to a sequence of multibyte characters. Format #include size_t wcstombs (char *s, const wchar_t *pwcs, size_t n); 3 Arguments s A pointer to the array containing the resulting multibyte characters. pwcs A pointer to the array containing the sequence of wide-character codes. n The maximum number of bytes to be stored in the array pointed to by s. 3 Description This function converts a sequence of codes corresponding to multibyte characters from the array pointed to by pwcs to a sequence of multibyte characters that are stored into the array pointed to by s, up to a maximum of n bytes. The value returned is equal to the number of characters converted or a -1 if an error occurred. This function is affected by the LC_CTYPE category of the program's current locale. See also wctomb. If s is NULL, this function call is a counting operation and n is ignored. 3 Return_Values x The number of bytes stored in s, not including the null terminating byte. If s is NULL, wcstombs returns the number of bytes required for the multibyte character array. (size_t) -1 Indicates an error occurred. The function sets errno to EILSEQ - invalid character sequence, or a wide-character code does not correspond to a valid character. 2 wcstoul Converts the initial portion of the wide-character string pointed to by nptr to an unsigned long integer. Format #include unsigned long int wcstoul (const wchar_t *nptr, wchar_t **endptr, int base); 3 Function_Variants This function also has variants named _wcstoul32 and _wcstoul64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments nptr A pointer to the wide-character string to be converted to an unsigned long. endptr The address of an object where the function can store the address of the first unrecognized character encountered in the conversion process (The character that follows the last character in the string being converted). If endptr is a NULL pointer, the address of the first unrecognized character is not retained. base The value, 2 through 36, to use as the base for the conversion. If base is 16, leading zeros after the optional sign are ignored, and 0x or 0X is ignored. If base is 0, the sequence of characters is interpreted by the same rules used to interpret an integer constant: after the optional sign, a leading 0 indicates octal conversion, a leading 0x or 0X indicates hexadecimal conversion, and any other combination of leading characters indicates decimal conversion. 3 Description This function recognizes strings in various formats, depending on the value of the base. It ignores any leading white-space characters (as defined by the iswspace function) in the string. It recognizes an optional plus or minus sign, then a sequence of digits or letters that may represent an integer constant according to the value of the base. The first unrecognized wide character ends the conversion. 3 Return_Values x The converted value. 0 Indicates that the string starts with an unrecognized wide character or that the value for base is invalid. If the string starts with an unrecognized wide character, *endptr is set to nptr. The function sets errno to EINVAL. ULONG_MAX Indicates that the converted value would cause an overflow. The function sets errno to ERANGE. 3 Example #include #include #include #include #include /* This test calls wcstoul() to convert a string to an */ /* unsigned long integer. wcstoul outputs the resulting */ /* integer and any characters that could not be converted. */ #define MAX_STRING 128 main() { int base = 10, errno; char *input_string = "1234.56"; wchar_t string_array[MAX_STRING], *ptr; size_t size; unsigned long int val; printf("base = [%d]\n", base); printf("String to convert = %s\n", input_string); if ((size = mbstowcs(string_array, input_string, MAX_STRING)) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("wchar_t string is = [%S]\n", string_array); errno = 0; val = wcstoul(string_array, &ptr, base); if (errno == 0) { printf("returned unsigned long int from wcstoul = [%u]\n", val); printf("wide char terminating scan(ptr) = [%S]\n\n", ptr); } if (errno == ERANGE) { perror("error value is :"); printf("ULONG_MAX = [%u]\n", ULONG_MAX); printf("wcstoul failed, val = [%d]\n\n", val); } } Running the example program produces the following result: base = [10] String to convert = 1234.56 wchar_t string is = [1234.56] returned unsigned long int from wcstoul = [1234] wide char terminating scan(ptr) = [.56] 2 wcswcs Locates the first occurrence in the string pointed to by wstr1 of the sequence of wide characters in the string pointed to by wstr2. Format #include wchar_t *wcswcs (const wchar_t *wstr1, const wchar_t *wstr2); 3 Function_Variants This function also has variants named _wcswcs32 and _wcswcs64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments wstr1, wstr2 Pointers to null-terminated wide-character strings. 3 Return_Values Pointer A pointer to the located wide-character string. NULL Indicates that the wide-character string was not found. 3 Example #include #include #include /* This test uses wcswcs() to find the occurrence of each */ /* sub wide-character string, string1 and string2, within */ /* the main wide-character string, lookin. */ #define BUF_SIZE 50 main() { static char lookin[] = "that this is a test was at the end"; char string1[] = "this", string2[] = "the end"; wchar_t buffer[BUF_SIZE], input_buffer[BUF_SIZE]; /* Convert lookin to wide-character format. */ /* Buffer and print it out. */ if (mbstowcs(buffer, lookin, BUF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("Buffer to look in: %S\n", buffer); /* Convert string1 to wide-character format and use */ /* wcswcs() to locate it within buffer */ if (mbstowcs(input_buffer, string1, BUF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("this: %S\n", wcswcs(buffer, input_buffer)); /* Convert string2 to wide-character format and use */ /* wcswcs() to locate it within buffer */ if (mbstowcs(input_buffer, string2, BUF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } printf("the end: %S\n", wcswcs(buffer, input_buffer)); exit(1); } Running this example produces the following results: Buffer to look in: that this is a test was at the end this: this is a test was at the end the end: the end 2 wcswidth Determines the number of printing positions on a display device that are required for a wide-character string. Format #include int wcswidth (const wchar_t *pwcs, size_t n); 3 Arguments pwcs A pointer to a wide-character string. n The maximum number of characters in the string. 3 Description This function returns the number of printing positions required to display the first n characters of the string pointed to by pwcs. If there are less than n wide characters in the string, the function returns the number of positions required for the whole string. 3 Return_Values x The number of printing positions required. 0 If pwcs is a null character. -1 Indicates that one (or more) of the wide characters in the string pointed to by pwcs is not a printable character. 2 wcsxfrm Changes a wide-character string such that the changed string can be passed to the wcscmp function and produce the same result as passing the unchanged string to the wcscoll function. Format #include size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t maxchar); 3 Arguments ws1, ws2 Pointers to wide-character strings. maxchar The maximum number of wide-characters, including the null wide- character terminator, allowed to be stored in s1. 3 Description This function transforms the string pointed to by ws2 and stores the resulting string in the array pointed to by ws1. No more than maxchar wide characters, including the null wide terminator, are placed into the array pointed to by ws1. If the value of maxchar is less than the required size to store the transformed string (including the terminating null), the contents of the array pointed to by ws1 is indeterminate. In such a case, the function returns the size of the transformed string. If maxchar is zero, then, ws1 is allowed to be a NULL pointer, and the function returns the required size of the ws1 array before making the transformation. The wide-character string comparison functions, wcscoll and wcscmp, can produce different results given the same two wide- character strings to compare. This is because wcscmp does a straightforward comparison of the code point values of the characters in the strings, whereas wcscoll uses the locale information to do the comparison. Depending on the locale, the wcscoll comparison can be a multi-pass operation, which is slower than wcscmp. The wcsxfrm function transforms wide character strings in such a way that if you pass two transformed strings to the wcscmp function, the result is the same as passing the two original strings to the wcscoll function. The wcsxfrm function is useful in applications that need to do a large number of comparisons on the same wide-character strings using wcscoll. In this case, it may be more efficient (depending on the locale) to transform the strings once using wcsxfrm and then use the wcscmp function to do comparisons. 3 Return_Values x Length of the resulting string pointed to by ws1, not including the terminating null character. (size_t) -1 Indicates an error occurred. The function sets errno to EINVAL - The string pointed to by ws2 contains characters outside the domain of the collating sequence. 3 Example #include #include #include #include /* This program verifies that two transformed strings, */ /* when passed through wcsxfrm and then compared, provide */ /* the same result as if passed through wcscoll without */ /* any transformation. */ #define BUFF_SIZE 20 main() { wchar_t w_string1[BUFF_SIZE]; wchar_t w_string2[BUFF_SIZE]; wchar_t w_string3[BUFF_SIZE]; wchar_t w_string4[BUFF_SIZE]; int errno; int coll_result; int wcscmp_result; size_t wcsxfrm_result1; size_t wcsxfrm_result2; /* setlocale to French locale */ if (setlocale(LC_ALL, "fr_FR.ISO8859-1") == NULL) { perror("setlocale"); exit(EXIT_FAILURE); } /* Convert each of the strings into wide-character format. */ if (mbstowcs(w_string1, "bcd", BUFF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } if (mbstowcs(w_string2, "abcz", BUFF_SIZE) == (size_t)-1) { perror("mbstowcs"); exit(EXIT_FAILURE); } /* Collate string 1 and string 2 and store the result. */ errno = 0; coll_result = wcscoll(w_string1, w_string2); if (errno) { perror("wcscoll"); exit(EXIT_FAILURE); } else { /* Transform the strings (using wcsxfrm) into */ /* w_string3 and w_string4. */ wcsxfrm_result1 = wcsxfrm(w_string3, w_string1, BUFF_SIZE); if (wcsxfrm_result1 == ((size_t) - 1)) perror("wcsxfrm"); else if (wcsxfrm_result1 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } else { wcsxfrm_result2 = wcsxfrm(w_string4, w_string2, BUFF_SIZE); if (wcsxfrm_result2 == ((size_t) - 1)) { perror("wcsxfrm"); exit(EXIT_FAILURE); } else if (wcsxfrm_result2 > BUFF_SIZE) { perror("\n** String is too long **\n"); exit(EXIT_FAILURE); } /* Compare the two transformed strings and verify that */ /* the result is the same as the result from wcscoll on */ /* the original strings. */ else { wcscmp_result = wcscmp(w_string3, w_string4); if (wcscmp_result == 0 && (coll_result == 0)) { printf("\nReturn value from wcscoll() and return value" " from wcscmp() are both zero."); printf("\nThe program was successful\n\n"); } else if ((wcscmp_result < 0) && (coll_result < 0)) { printf("\nReturn value from wcscoll() and return value" " from wcscmp() are less than zero."); printf("\nThe program was successful\n\n"); } else if ((wcscmp_result > 0) && (coll_result > 0)) { printf("\nReturn value from wcscoll() and return value" " from wcscmp() are greater than zero."); printf("\nThe program was successful\n\n"); } else { printf("** Error **\n"); printf("\nReturn values are not of the same type"); } } } } } Running the example program produces the following result: Return value from wcscoll() and return value from wcscmp() are less than zero. The program was successful 2 wctob Determines if a wide character corresponds to a single- byte multibyte character and returns its multibyte character representation. Format #include #include int wctob (wint_t c); 3 Arguments c The wide character to be converted to a single-byte multibyte character. 3 Description This function determines whether the specified wide character corresponds to a single-byte multibyte character when in the initial shift state and, if so, returns its multibyte character representation. 3 Return_Values x The single-byte representation of the wide character specified. EOF Indicates an error. The wide character specified does not correspond to a single-byte multibyte character. 2 wctomb Converts a wide character to its multibyte character representation. Format #include int wctomb (char *s, wchar_t wchar); 3 Arguments s A pointer to the resulting multibyte character. wchar The code for the wide character. 3 Description This function converts the wide character specified by wchar to its multibyte character representation. If s is NULL, then 0 is returned. Otherwise, the number of bytes comprising the multibyte character is returned. At most, MB_CUR_MAX bytes are stored in the array object pointed to by s. This function is affected by the LC_CTYPE category of the program's current locale. 3 Return_Values x The number of bytes comprising the multibyte character corresponding to wchar. 0 If s is NULL. -1 If wchar is not a valid character. 2 wctrans Returns the description of a mapping, corresponding to specified property, that can later be used in a call to towctrans. Format #include wctrans_t wctrans (const char *property); 3 Arguments property The name of the mapping. The following property names are defined for all locales: o "touppper" o "tolower" Additional property names may also be defined in the LC_CTYPE category of the current locale. 3 Description This function constructs a value with type wctrans_t that describes a mapping between wide characters identified by the property argument. See also towctrans. 3 Return_Values nonzero According to the LC_CTYPE category of the current program locale, the string specified as a property argument is the name of an existing character mapping. The value returned can be used in a call to the towctrans function. 0 Indicates an error. The property argument does not identify a character mapping in the current program's locale. 2 wctype Used for defining a character class. The value returned by this function is used in calls to the iswctype function. Format #include (ISO C) #include (XPG4) wctype_t wctype (const char *char_class); 3 Arguments char_class A pointer to a valid character class name. 3 Description This function converts a valid character class defined for the current locale to an object of type wctype_t. The following character class names are defined for all locales: alnum cntrl lower space alpha digit print upper blank graph punct xdigit Additional character class names may also be defined in the LC_ CTYPE category of the current locale. See also iswctype. 3 Return_Values x An object of type wctype_t that can be used in calls to the iswctype function. 0 If the character class name is not valid for the current locale. 3 Example #include #include #include #include #include #include /* This test will set up a number of character class */ /* using wctype() and then verify whether calls to iswctype() */ /* using these classes produce the same results as calls */ /* to the is**** routines. */ main() { wchar_t w_char; wctype_t ret_val; char *character = "A"; /* Convert character to wide character format - w_char */ if (mbtowc(&w_char, character, 1) == -1) { perror("mbtowc"); exit(EXIT_FAILURE); } /* Check if results from iswalnum() matches check on alnum */ /* character class */ if ((iswalnum((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("alnum")))) printf("[%C] is a member of the character class alnum\n", w_char); else printf("[%C] is not a member of the character class alnum\n", w_char); /* Check if results from iswalpha() matches check on alpha */ /* character class */ if ((iswalpha((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("alpha")))) printf("[%C] is a member of the character class alpha\n", w_char); else printf("[%C] is not a member of the character class alpha\n", w_char); /* Check if results from iswcntrl() matches check on cntrl */ /* character class */ if ((iswcntrl((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("cntrl")))) printf("[%C] is a member of the character class cntrl\n", w_char); else printf("[%C] is not a member of the character class cntrl\n", w_char); /* Check if results from iswdigit() matches check on digit */ /* character class */ if ((iswdigit((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("digit")))) printf("[%C] is a member of the character class digit\n", w_char); else printf("[%C] is not a member of the character class digit\n", w_char); /* Check if results from iswgraph() matches check on graph */ /* character class */ if ((iswgraph((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("graph")))) printf("[%C] is a member of the character class graph\n", w_char); else printf("[%C] is not a member of the character class graph\n", w_char); /* Check if results from iswlower() matches check on lower */ /* character class */ if ((iswlower((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("lower")))) printf("[%C] is a member of the character class lower\n", w_char); else printf("[%C] is not a member of the character class lower\n", w_char); /* Check if results from iswprint() matches check on print */ /* character class */ if ((iswprint((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("print")))) printf("[%C] is a member of the character class print\n", w_char); else printf("[%C] is not a member of the character class print\n", w_char); /* Check if results from iswpunct() matches check on punct */ /* character class */ if ((iswpunct((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("punct")))) printf("[%C] is a member of the character class punct\n", w_char); else printf("[%C] is not a member of the character class punct\n", w_char); /* Check if results from iswspace() matches check on space */ /* character class */ if ((iswspace((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("space")))) printf("[%C] is a member of the character class space\n", w_char); else printf("[%C] is not a member of the character class space\n", w_char); /* Check if results from iswupper() matches check on upper */ /* character class */ if ((iswupper((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("upper")))) printf("[%C] is a member of the character class upper\n", w_char); else printf("[%C] is not a member of the character class upper\n", w_char); /* Check if results from iswxdigit() matches check on xdigit */ /* character class */ if ((iswxdigit((wint_t) w_char)) && (iswctype((wint_t) w_char, wctype("xdigit")))) printf("[%C] is a member of the character class xdigit\n", w_char); else printf("[%C] is not a member of the character class xdigit\n", w_char); } Running this example produces the following result: [A] is a member of the character class alnum [A] is a member of the character class alpha [A] is not a member of the character class cntrl [A] is not a member of the character class digit [A] is a member of the character class graph [A] is not a member of the character class lower [A] is a member of the character class print [A] is not a member of the character class punct [A] is not a member of the character class space [A] is a member of the character class upper [A] is a member of the character class xdigit 2 wcwidth Determines the number of printing positions on a display device required for the specified wide character. Format #include int wcwidth (wchar_t wc); 3 Arguments wc A wide character. 3 Description This function determines the number of column positions needed for the specified wide character wc. The value of wc must be a valid wide character in the current locale. 3 Return_Values x The number of printing positions required for wc. 0 If wc is a null character. -1 Indicates that wc does not represent a valid printing wide character. 2 wmemchr Locates the first occurence of a specified wide character in an array of wide characters. Format #include wchar_t wmemchr (const wchar_t *s, wchar_t c, size_t n); 3 Function_Variants This function also has variants named _wmemchr32 and _wmemchr64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s A pointer to an array of wide characters to be searched. c The wide character value to search for. n The maximum number of wide characters in the array to be searched. 3 Description This function locates the first occurrence of the specified wide character in the initial n wide characters of the array pointed to by s. 3 Return_Values x A pointer to the first occurrence of the wide character in the array. NULL The specified wide character does not occur in the array. 2 wmemcmp Compares two arrays of wide characters. Format #include int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n); 3 Arguments s1, s2 Pointers to wide-character arrays. n The maximum number of wide characters to be compared. 3 Description This function compares the first n wide characters of the array pointed to by s1 with the first n wide characters of the array pointed to by s2. The wide characters are compared not according to locale-dependent collation rules, but as integral objects of type wchar_t. 3 Return_Values 0 Arrays are equal. Positive value The first array is greater than the second. Negative value The first array is less than the second. 2 wmemcpy Copies a specified number of wide characters from one wide- character array to another. Format #include wchar_t wmemcpy (wchar_t *dest, const wchar_t *source, size_t n); 3 Function_Variants This function also has variants named _wmemcpy32 and _wmemcpy64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest A pointer to the destination array. source A pointer to the source array. n The number of wide characters to be copied. 3 Description This function copies n wide characters from the array pointed to by source to the array pointed to by dest. 3 Return_Values x The value of dest. 2 wmemmove Copies a specified number of wide characters from one wide- character array to another. Format #include wchar_t wmemmove (wchar_t *dest, const wchar_t *source, size_t n); 3 Function_Variants This function also has variants named _wmemmove32 and _wmemmove64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments dest A pointer to the destination array. source A pointer to the source array. n The number of wide characters to be moved. 3 Description This function copies n wide characters from the location pointed to by source to the location pointed to by dest. The wmemmove and wmemcpy routines perform the same function, except that wmemmove ensures that the original contents of the source array are copied to the destination array even if the two arrays overlap. Where such overlap is possible, programs that require portability should use wmemmove, not wmemcopy. 3 Return_Values x The value of dest. 2 wmemset Sets a specified value to a specified number of wide characters in an array of wide characters. Format #include wchar_t wmemset (wchar_t *s, wchar_t c, size_t n); 3 Function_Variants This function also has variants named _wmemset32 and _wmemset64 for use with 32-bit and 64-bit pointer sizes, respectively. 3 Arguments s A pointer to the array of wide characters. c The value to be placed in the first n wide characters of the array. n The number of wide characters to be set to the specified value c. 3 Description This function copies the value of c into each of the first n wide characters of the array pointed to by s. 3 Return_Values x The value of s. 2 wprintf Performs formatted output from the standard output (stdout). See the Input/Output chapter of the Compaq C Run-Time Library Reference Manual for information on format specifiers. Format #include int wprintf (const wchar_t *format, . . . ); 3 Arguments format A pointer to a wide-character string containing the format specifications. . . . Optional expressions whose resultant types correspond to conversion specifications given in the format specification. If no conversion specifications are given, the output sources can be omitted. Otherwise, the function calls must have exactly as many output sources as there are conversion specifications, and the conversion specifications must match the types of the output sources. Conversion specifications are matched to output sources in left- to-right order. Excess output pointers, if any, are ignored. 3 Description This function is equivalent to the fwprintf function with the stdout argument interposed before the wprintf arguments. 3 Return_Values n The number of wide characters written. Negative value Indicates an error. The function sets errno to one of the following: o EILSEQ - Invalid character detected. o EINVAL - Insufficient arguments. o ENOMEM - Not enough memory available for conversion. o ERANGE - Floating-point calculations overflow. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This might indicate that conversion to a numeric value failed because of overflow. The function can also set errno to the following as a result of errors returned from the I/O subsystem: o EBADF - The file descriptor is not valid. o EIO - I/O error. o ENOSPC - No free space on the device containing the file. o ENXIO - Device does not exist. o EPIPE - Broken pipe. o ESPIPE - Illegal seek in a file opened for append. o EVMSERR - Nontranslatable VMS error. vaxc$errno contains the VMS error code. This indicates that an I/O error occurred for which there is no equivalent C error code. 2 wrapok In the UNIX system environment, allows the wrapping of a word from the right border of the window to the beginning of the next line. This routine is provided only for UNIX software compatibility and serves no function in the OpenVMS environment. Format #include wrapok (WINDOW *win, bool boolf); 3 Arguments win A pointer to the window. boolf A Boolean TRUE or FALSE value. If boolf is FALSE, scrolling is not allowed. This is the default setting. The bool type is defined in the header file as follows: #define bool int 2 write Writes a specified number of bytes from a buffer to a file. Format #include ssize_t write (int file_desc, void *buffer, size_t nbytes); (ISO POSIX-1) int write (int file_desc, void *buffer, int nbytes); (Compatability) 3 Arguments file_desc A file descriptor that refers to a file currently opened for writing or updating. buffer The address of contiguous storage from which the output data is taken. nbytes The maximum number of bytes involved in the write operation. 3 Description If the write is to an RMS record file and the buffer contains embedded new-line characters, more than one record may be written to the file. Even if there are no embedded new-line characters, if nbytes is greater than the maximum record size for the file, more than one record will be written to the file. The write function always generates at least one record. If the write is to a mailbox and the third argument, nbytes, specifies a length of 0, an end-of-file message is written to the mailbox. This occurs for mailboxes created by the application using SYS$CREMBX, but not for mailboxes created to implement POSIX pipes. For more information see the "Subprocess Functions" chapter of the Compaq C RTL Reference Manual. 3 Return_Values x The number of bytes written. -1 Indicates errors, including undefined file descriptors, illegal buffer addresses, and physical I/O errors. 2 writev Writes to a file. Format #include ssize_t writev (int fildes, const struct iovec *iov, int iovcnt); 3 Argument filedes A file descriptor that refers to a file currently opened for writing or updating. iov Array of iovec structures from which the output data is gathered. iovcnt The number of buffers specified by the members of the iov array. 3 Description The writev function is equivalent to write but gathers the output data from the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., iov[iovcnt-1]. The iovcnt argument is valid if greater than 0 and less than or equal to {IOV_MAX}, defined in . Each iovec entry specifies the base address and length of an area in memory from which data should be written. The writev function writes a complete area before proceeding to the next. If filedes refers to a regular file and all of the iov_len members in the array pointed to by iov are 0, writev returns 0 and has no other effect. For other file types, the behavior is unspecified. If the sum of the iov_len values is greater than SSIZE_MAX, the operation fails and no data is transferred. Upon successful completion, writev returns the number of bytes actually written. Otherwise, it returns a value of -1, the file- pointer remains unchanged, and errno is set to indicate an error. 3 Return_Values x The number of bytes written. -1 Indicates an error. The file times do not change, and the function sets errno to one of the following values: o EBADF - The filedes argument is not a valid file descriptor open for writing. o EINTR - The write operation was terminated due to the receipt of a signal, and no data was transferred. o EINVAL - The sum of the iov_len values in the iov array would overflow an ssize_t, or the iovcnt argument was less than or equal to 0, or greater than {IOV_MAX}. o EIO - A physical I/O error has occurred. o ENOSPC - There was no free space remaining on the device containing the file. o EPIPE - An attempt is made to write to a pipe or FIFO that is not open for reading by any process, or that only has one end open. A SIGPIPE signal will also be sent to the thread. 2 wscanf Reads input from the standard input (stdin) under control of the wide-character format string. Format #include int wscanf (const wchar_t *format, . . . ); 3 Arguments format A pointer to a wide-character string containing the format specifications. . . . Optional expressions whose results correspond to conversion specifications given in the format specification. If no conversion specifications are given, you can omit the input pointers. Otherwise, the function calls must have exactly as many input pointers as there are conversion specifications, and the conversion specifications must match the types of the input pointers. Conversion specifications are matched to input sources in left- to-right order. Excess input pointers, if any, are ignored. 3 Description This function is equivalent to the fwscanf function with the stdin arguments interposed before the wscanf arguments. 3 Return_Values n The number of input items assigned. The number can be less than provided for, even zero, in the event of an early matching failure. EOF Indicates an error. An input failure occurred before any conversion. 2 y0,_y1,_yn Compute Bessel functions of the second kind. This function is OpenVMS Alpha only. Format #include double y0 (double x); float y0f (float x); long double y0l (long double x); double y1 (double x); float y1f (float x); long double y1l (long double x); double yn (int n, double x); float ynf (int n, float x); long double ynl (int n, long double x); 3 Argument x A positive, real value. n An integer. 3 Description The y0 functions return the value of the Bessel function of the second kind of order 0. The y1 functions return the value of the Bessel function of the second kind of order 1. The yn functions return the value of the Bessel function of the second kind of order n. 3 Return_Values x The relevant Bessel value of x of the second kind. -HUGE_VAL The x argument is 0.0; errno is set to ERANGE. NaN The x argument is negative or NaN; errno is set to EDOM. 0 Underflow occurred; errno is set to ERANGE. HUGE_VAL Overflow occurred; errno is set to ERANGE.