Although it does not solve the more general issue with calling intrinsics
from gcc, the easiest and most portable way of getting environment
variables is to use getenv():
#include <stdlib.h>
char Sys_Id_Code(void)
{
char *sysname = getenv("HPSYSNAME");
return sysname[0];
}
int main(int argc, char *argv[])
{
printf("The system name starts with %c\n",Sys_Id_Code());
}
I don't have gcc on my system, but it works fine with the HP's c89
compiler, and it should work fine with gcc, too.
--
Gary W. Smith
[log in to unmask]
"Emerson, Tom # El Monte" <[log in to unmask]> wrote in message
news:8vcbbh014k3@enews4.newsguy.com...
> I'm encountering a strange problem calling the system intrinsic HPCIGETVAR
> from within a "C" program compiled with the gnu gcc compiler [2.95.2] The
> program is aborting from within the SYSTEM code, not my user code, so it
> makes it difficult to debug "as a user"...
>
>[stuff omitted for brevity]
>
> /***** procedure to get system id from 'HPSYSNAME var ****/
> char Sys_Id_Code(void)
> {
> int status=0;
> /* broken down as:
> short info; (i.e., status >> 16)
> short subsys; ( status & 0xff)
> */
> int strlen;
> char _ret='Z';
> char varvalu[32]="";
> char varname[]="HPSYSNAME ";
>
> strlen = 32;
>
> HPCIGETVAR(varname,&status,
> 10,&strlen,
> 2, varvalu,
> 0, 0);
>
> if (status == 0)
> _ret = varvalu[0];
> return(_ret);
> }
> /********* end of psysid ************/
>
> int main(int argc, char *argv[])
> {
> printf("The system name starts with %c\n",Sys_Id_Code());
> }
>
> [error dump omitted]
>
> Tom Emerson
> Sr. Systems Analyst
> NDC | e COMMERCE
> [log in to unmask]
> 626-258-4309
> 626-350-3832 FAX
>
|