By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 2,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

get user id

P: n/a
What is the function to obtain the user id when
running a C program? Or does it go thru an
environment module?
Oct 21 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On October 21, 2008 13:01, in comp.lang.c, monkeys paw (us**@example.net)
wrote:
What is the function to obtain the user id when
running a C program?
It depends on your OS and the add-on libraries available under it. The C
standard does not speak of "user id", let alone define a standard function
to access it.
Or does it go thru an environment module?
Not sure what you are asking here. If, by "environment module", you
mean "function defined in an add-on library available under my OS", then
yes, you obtain a user id through an environment module.
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Oct 21 '08 #2

P: n/a
On 21 Oct 2008 at 17:01, monkeys paw wrote:
What is the function to obtain the user id when running a C program?
getuid(2) to get the real user ID
geteuid(2) to get the effective user ID

Oct 21 '08 #3

P: n/a
Antoninus Twink wrote:
On 21 Oct 2008 at 17:01, monkeys paw wrote:
>What is the function to obtain the user id when running a C program?

getuid(2) to get the real user ID
geteuid(2) to get the effective user ID
which are topical in comp.unix.prgrammer, not here.

Bye, Jojo
Oct 21 '08 #4

P: n/a
Thanks, what i was looking for (and found):
main()
{

struct passwd *pwd;

pwd = getpwuid(getuid());

if ((pwd) && (!strcmp(pwd->pw_name, "pamelah")))
printf("It's Pam!\n");

}

Lew Pitcher wrote:
On October 21, 2008 13:01, in comp.lang.c, monkeys paw (us**@example.net)
wrote:
>What is the function to obtain the user id when
running a C program?

It depends on your OS and the add-on libraries available under it. The C
standard does not speak of "user id", let alone define a standard function
to access it.
>Or does it go thru an environment module?

Not sure what you are asking here. If, by "environment module", you
mean "function defined in an add-on library available under my OS", then
yes, you obtain a user id through an environment module.

Oct 21 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.