[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
Compaq C
|
Previous | Contents | Index |
Finds and points to a duplicate string.
#include <string.h>Function Variants This function also has variants named _strdup32 and _strdup64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.10 for more information on using pointer-size-specific functions.char *strdup (const char *s1);
s1
The first of two strings to compare.
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.
x A pointer to the resulting string. NULL Indicates an error.
Maps the error number in error_code to a locale-dependent error message string.
#include <string.h>char *strerror (int error_code); (ANSI C)
char *strerror (int error_code[, int vms_error_code]); (COMPAQ C EXTENSION)
error_code
An error code.vms_error_code
An OpenVMS error code.
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 (see Section 1.5.1), strerror has a second argument (vms_error_code), which is used in the following way:
- If error_code is EVMSERR and there is a second argument, then that second argument is used as the vaxc$errno value.
- 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.
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.
#include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <ssdef.h> 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: <none> network partner exited abort |
Converts a number of monetary values into a string. The conversion is controlled by a format string.
#include <monetary.h>ssize_t strfmon (char *s, size_t maxsize, const char *format, ...);
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.
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 Table REF-5), and concluding with a conversion specifier (see Table REF-6).
If any of the optional characters listed in Table REF-5 is included in a conversion specification, they must appear in the order shown.
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:
- EINVAL -- A conversion specification is syntactically incorrect.
- E2BIG -- Processing the complete format string would produce more than maxsize bytes.
#include <stdlib.h> #include <stdio.h> #include <locale.h> #include <monetary.h> #include <errno.h> #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 |
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.
#include <time.h>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.size_t strftime (char *s, size_t maxsize, const char *format, const struct tm *timeptr);
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 <time.h> header file.
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 Table REF-7), and concluding with a conversion specifier (see Table REF-8). If any of the optional characters listed in Table REF-7 are specified, they must appear in the order shown in the table.
The strftime function behaves as if it called tzset .
Note that the list of conversion specifications in Table REF-7 are extensions to the XPG4 specification.
Table REF-8 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.
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.
#include <stdlib.h> #include <stdio.h> #include <time.h> #include <locale.h> #include <errno.h> #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 |
Previous | Next | Contents | Index |