Use the __errno2() function when diagnosing problems in an application program. This function enables z/OS® XL C/C++ application programs to access additional diagnostic information, errno2 (errnojr), associated with errno. The __errno2 may be set by the z/OS XL C/C++ runtime library, z/OS UNIX callable services, or other callable services. The errno2 is intended for diagnostic display purposes only and is not a programming interface.
Figure 1 is an example of a routine using __errno2().
#pragma runopts(posix(on))
#define _EXT
#include <stdio.h>
#include <errno.h>
int main(void) {
FILE *f;
f = fopen("testfile.dat", "r");
if (f==NULL) {
perror("fopen() failed");
printf("__errno2 = %08x\n", __errno2());
}
return 0;
}
Figure 2 shows the output from the sample routine in Figure 1.
fopen() failed: EDC5129I No such file or directory. (errno2=0x05620062)
__errno2 = 05620062
Figure 3 is an example of a routine using the environment variable _EDC_ADD_ERRNO2.
#pragma runopts(posix(on))
#define _EXT
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
int main(void) {
FILE *fp;
/* do NOT add errno2 to perror message */
setenv("_EDC_ADD_ERRNO2", "0", 1);
fp = fopen("testfile.dat", "r");
if (fp == NULL)
perror("fopen() failed");
return 0;
}
Figure 4 shows the sample output from the routine in Figure 3.
fopen() failed: EDC5129I No such file or directory.
Figure 5 is an example of a routine using __err2ad() in combination with __errno2() .
#pragma runopts(posix(on))
#define _EXT
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
int main(void) {
FILE *f;
setenv("_EDC_ADD_ERRNO2", "0", 1);
f = fopen("testfile.dat", "r");
if (f == NULL) {
perror("fopen() failed");
printf("__errno2 = %08x\n", __errno2());
}
/* reset errno2 to zero */
*__err2ad() = 0x0;
printf("__errno2 = %08x\n", __errno2());
f = fopen("testfile.dat", "r");
if (f == NULL) {
perror("fopen() failed");
printf("__errno2 = %08x\n", __errno2());
}
return 0;
}
Figure 6 shows the sample output from the routine shown in Figure 5.
fopen() failed: EDC5129I No such file or directory.
__errno2 = 05620062
__errno2 = 00000000
fopen() failed: EDC5129I No such file or directory.
__errno2 = 05620062
For more information about _EDC_ADD_ERRNO2, see z/OS XL C/C++ Programming Guidez/OS XL C/C++ Programming Guide.
For more information about __errno2() and __err2ad(), see z/OS XL C/C++ Runtime Library Reference.