From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 15-JUN-1992 07:17:12.24
To:	MBSAMUDR@ECUVAX.CIS.ECU.EDU, INFO-VAX@SRI.COM
CC:	
Subj:	Re: help with sys$getjpi...

> I'd like to use sys$getjpi to find the username for a process in a C
> program. Before I used the lexical f$getjpi in this form:
> 
> username_string = f$getjpi("", "USERNAME") to get the current process'
> username.
> 
> But I'm confused as to how sys$getjpi returns the username_string (or
> other info). Here's what I want to do (descriptor is a function that
> sets up the structure).
> 
> 	long int pid, efn;
> 	char string[20];
> 
>   $DESCRIPTOR(prcnam, string);
>   $DESCRIPTOR(itmlst, "USERNAME");
>   pid = getpid();
>   descriptor(&prcnam, string, 20);
>   descriptor(&itmlst, "USERNAME", strlen("USERNAME"));
>   sys$getjpi(&efn, &pid, &prcnam, itmlst);
> 
> But I'm stuck because I don't know where the username_string will be
> returned. Is it in the "prcnam" field? Thanks a lot in advance!!!

The following small program is equivalent to

    WRITE SYS$OUTPUT "username="+f$getjpi("","USERNAME")


#include <stdio.h>
#include <jpidef.h>
#include <ssdef.h>

int sys$getjpiw();

struct item {
            short bufsiz,itmcod;
            long bufadr,retlenadr;
            };

main(int argc,char *argv[])
{
   int stat;
   short unlen;
   char un[13];
   struct item itmlst[2] = {{sizeof(un)-1,JPI$_USERNAME,&un,&unlen},{0,0,0,0}};
   stat = sys$getjpiw(0,0,0,&itmlst,0,0,0);
   un[unlen] = '\0';
   printf("username=%s\n",&un);
   return SS$_NORMAL;
};

Other items are retrived tha same way.

                                                          Arne Vajhxj

Arne Vajhxj                             local DECNET:  KO::ARNE
Computer Department                     PSI:           PSI%238310013040::ARNE
Business School of Southern Denmark     Internet:      ARNE@KO.HHS.DK


