get user id

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monkeys paw

    #1

    get user id

    What is the function to obtain the user id when
    running a C program? Or does it go thru an
    environment module?
  • Lew Pitcher

    #2
    Re: get user id

    On October 21, 2008 13:01, in comp.lang.c, monkeys paw (user@example.n et)
    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 "environmen t 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. ------


    Comment

    • Antoninus Twink

      #3
      Re: get user id

      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

      Comment

      • Joachim Schmitz

        #4
        Re: get user id

        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.prgra mmer, not here.

        Bye, Jojo


        Comment

        • monkeys paw

          #5
          Re: get user id

          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 (user@example.n et)
          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 "environmen t 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.
          >
          >

          Comment

          Working...