Re: USER function
Posted in 1991
> You may want to use a C function which picks up the LOGNAME from the > environment instead. 4.1 has a function like this built in to 4GL. Is 4.1 supposed to let you do something like the following? DEFINE cur_user CHAR(8) LET cur_user = USER # or maybe LET cur_user = some_kind_of_user_ID_function_thing() If so, I'm not holding my tongue right or I4GL 4.10.UC1/SunOS 4.1 has a bug. Anyone know for sure? The 4.00 manuals are kind of ambiguous, and I may have missed it in the 4.10 update supplement. Actually, I can see how ISI would avoid providing such a function. Here's a sure-fire way to get your next party going: get a bunch of Unix people in one room and ask them what "current user" means and how to obtain it from the system :-). If you decide to use a C function to get the user's login-ID, and you haven't done it before, read up on real vs. effective uid on your system and what routines return which. Below is some C code that demonstrates the method we use here. Good luck, Walt. -- Walt Hultgren Internet: walt@rmy.emory.edu (IP 128.140.8.1) Emory University UUCP: {...,gatech,rutgers,uunet}!emory!rmy!walt 954 Gatewood Road, NE BITNET: walt@EMORY Atlanta, GA 30329 USA Voice: +1 404 727 0648 #!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # get_user.c # # This shell archive created: Thu Dec 12 15:07:49 EST 1991 # echo "Extracting file get_user.c" sed -e 's/^X//' <<\\++EOF++EOF++ > get_user.c X/* get_user.c Get User Login Name X * X * X * This function allows an Informix-4GL routine to obtain the Login-ID X * under which the process is running. This is sometimes necessary X * since the "user" keyword can only be used in certain situations. X * X * X * Example: X * X * define user_id char(8) { user login-ID } X * X * call get_user() returning user_id X * X */ X X X#include <stdio.h> X#include <pwd.h> X X Xint get_user ( narg ) X X int narg; X X { X struct passwd *pwentry; /* pointer to a passwd entry */ X X static char *null_st = ""; /* pointer to a null string, as opposed to */ X /* a null string pointer */ X X X /* Get passwd entry for real uid */ X X if ( ( pwentry = getpwuid ( getuid() ) ) == (struct passwd *)NULL ) X { X pwentry->pw_name = null_st; X } X X X /* Return user name to Informix-4GL by pushing its pointer onto */ X /* I4GL's stack. */ X X retquote( pwentry->pw_name ); X X return 1; X } ++EOF++EOF++ if [ `wc -c < get_user.c` -ne 1062 ] then echo "Lengths do not match -- Bad Copy of get_user.c" fi echo "Done."