Re: getting login name in 4GL
Posted in 1996
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Cheryl Kendricks wrote: > > I did not say whoami was the answer. You should use an universal UNIX > eviromnent variable. Are you telling me UNIX does not have one for user > id? whoami is just the only one I know (which does not say a whole lot), > Yet, UNIX must have at least one that is always set! I've never had to > deal with this in the mainframe world. If UNIX does not have a universal > set of environment vars then I say pooh on it! > > On Tue, 14 May 1996, Chris Drauch wrote: > > } Cheryl Kendricks wrote > } > > } >I'm not in anyway a UNIX expert. But what is wrong with just using what is > } >returned from the whoami command. To have control you could even set some > } >var SYSUSERID='whoami' at the SYSTEM DEFAULT LOGIN SHELL. > } > } One some systems you will maybe find 'whoami', on some 'who am i' or just > } 'who'. There are more risks using a external command, script or shell > } variable than lib calls. > } Well, You could always read the USER or LOGNAME environment vars. These are on nearly every *nix _but_ are not 100% portable, specifically between BSD and ATT. (BSD likes to use USER and ATT likes to use LOGNAME). In addition, if the shell does not make these vars "readonly" the can be made to lie to your program. Not a desirable thing. The best way (IMHO) to address this issue is to do somthing like: #include <pwd.h> . . . { struct passwd *pw; pw=getpwuid(getuid()); /* fetch the passwd entry */ /* now, pw->pw_name contains what USER and/or LOGNAME should */ } Pretty simple. Hope this helps. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Kevin Franden Informix Software, Inc. 16011 College Blvd kevinf@informix.com Lenexa, KS. 66219 uunet!infmx!kevinf #include <patchlevel.h> fprintf(DISCLAIMER,"I said what I said.\\n"); =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- You only live once but if you do it right, once is enough Carpe Diem