I remembered it as something like the below, simpler than the mess that I found. That's why I went looking. But when I found what I did find I figured that was what I recalled.
Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:[email protected]] On Behalf Of Frank Swarbrick Sent: Thursday, October 11, 2018 2:35 PM To: [email protected] Subject: Re: C errno from COBOL Thanks Allan, that looks to do the trick! I was going to ask how you found the __errno() function, but now I see it in errno.h: #ifndef __NO_STATIC #undef errno extern int errno; extern int *__errno(void); #define errno (*__errno()) #endif It's defined later than the stuff Charles was talking about, so both of us missed it. Great! Frank ________________________________ From: IBM Mainframe Discussion List <[email protected]> on behalf of Allan Kielstra <[email protected]> Sent: Thursday, October 11, 2018 1:21 PM To: [email protected] Subject: Re: C errno from COBOL Hi Frank: I'm not sure if this will work for all times and in all cases. Here is my C program simulating a C API that sets errno: #include <errno.h> int cfunc() { errno = 8; } Compiled with no options with z/OS V2.3 XL C/C++ Here is a small COBOL program I wrote CBL PGMNAME(LongMixed) Identification Division. program-id. "FS". Data Division. Working-Storage Section. 1 pointer-to-errno usage pointer. Linkage Section. 1 errno pic S9(9) COMP-5. Procedure Division. Display "Calling dummy C API" Call "cfunc" Call "__errno" returning pointer-to-errno Set Address Of errno To pointer-to-errno Display "errno = " errno stop run. End program "FS". I call my C program to simulate calling a C API. Then, I call __errno which appears to return the address of errno. I compiled this with V6.2 with no options other than what is in the CBL card. I compiled, bound and ran on USS. The result of the run is: $ ./a.out Calling dummy C API errno = 0000000008 $ Try it and if it works, great but put in some comments that say that this relies on some implementation behaviour. (I'm Canadian and that's how we spell that last word.) ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
