[GRASS5] cuserid alternative?

I checked the Mac OS X UNIX porting list archives and found a suggestion to use getlogin() instead of cuserid (at least for the case of passing a null pointer to cuserid). Any thoughts? I tried it by changing dbmi_base/whoami.c to use that instead of cuserid - compiles OK.

Is db_whoami() even used anywhere? I didn't see it used in any of the source. Without it being used anywhere, I can't really say if replacing cuserid() with getlogin() works (it's beyond my C knowledge to say if it should work).

FYI, this is my new whoami.c (let me know if anything is wrong with it):

#include <unistd.h>

/*!
  \fn
  \brief
  \return
  \param
*/
char *
db_whoami()
{
     char *getlogin();

     return getlogin();
}

-----
William Kyngesburye <kyngchaos@charter.net>
http://webpages.charter.net/kyngchaos/

[Trillian] What are you supposed to do WITH a maniacally depressed robot?

[Marvin] You think you have problems? What are you supposed to do if you ARE a maniacally depressed robot? No, don't try and answer, I'm 50,000 times more intelligent than you and even I don't know the answer...

- HitchHiker's Guide to the Galaxy

William K wrote:

I checked the Mac OS X UNIX porting list archives and found a
suggestion to use getlogin() instead of cuserid (at least for the case
of passing a null pointer to cuserid). Any thoughts? I tried it by
changing dbmi_base/whoami.c to use that instead of cuserid - compiles
OK.

Is db_whoami() even used anywhere? I didn't see it used in any of the
source. Without it being used anywhere, I can't really say if
replacing cuserid() with getlogin() works (it's beyond my C knowledge
to say if it should work).

cuserid() returns the username corresponding to the effective UID of
the calling process, while getlogin returns the username corresponding
to the utmp entry for the TTY associated with descriptor 0 (standard
input).

They may not produce the same result, e.g. if the user has switched
UIDs with su. Also, getlogin() will fail if stdin doesn't refer to a
TTY, or if no utmp entry exists for the TTY (this is quite common for
xterms and similar).

In all probability, db_whoami() (and, for that matter, G_whoami())
should be using getenv("LOGNAME") rather than either cuserid() or
getlogin().

FYI, this is my new whoami.c (let me know if anything is wrong with it):

char *
db_whoami()
{
     char *getlogin();

Don't provide your own prototypes for library functions; include the
appropriate header instead.

--
Glynn Clements <glynn.clements@virgin.net>

In all probability, db_whoami() (and, for that matter, G_whoami())
should be using getenv("LOGNAME") rather than either cuserid() or
getlogin().

So, could this be changed in the source? Didn't think to search for 'whoami' (doh!), just db_whoami. Hmm, looks like G_whoami() uses getlogin(). So, is there any point to db_whoami?

FYI, this is my new whoami.c (let me know if anything is wrong with it):

char *
db_whoami()
{
     char *getlogin();

Don't provide your own prototypes for library functions; include the
appropriate header instead.

Yep, my lack of C skill shows here. Just mimicking the cuserid version of db_whoami.

-----
William Kyngesburye <kyngchaos@charter.net>
http://webpages.charter.net/kyngchaos/

Earth: "Mostly harmless"

- revised entry in the HitchHiker's Guide to the Galaxy