On Thu, 30 Oct 2003 06:25:39 -0600
"Vu Pham" <[EMAIL PROTECTED]> wrote:
>
> ----- Original Message -----
> From: "James McDonald" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, October 30, 2003 5:57 AM
> Subject: Re: username / id
>
>
> > Vu Pham wrote:
> > > Hi all,
> > >
> > > Is there any function to get the user name if uid is known, and vice
> versa ?
> > > Similar for group.
> > >
> > > Thanks,
> > >
> >
> > cat /etc/passwd | grep ^.*:x:500: | awk -F: '{print $1}'
> > cat /etc/passwd | grep ^.*:x:[0-9]*:500 | awk -F: '{print $1}'
> >
> > This is probably not what you want but it does return a name from uid or
> > gid...
>
> Oh, that works. I would like to know if there is an API so that I can use
> it in my C app, or do I need to run some commands like your suggestion and
> capture the output.
The closest to a C function I have seen is only for the current user:
getlogin or cuserid. For other users, I do not know. These functions use the
'utmp' function to get their information, and not /etc/passwd.
So, if you are interested in currently logged in users, you can use the
utmp() function. Otherwise, fopen("/etc/passwd", ...)/fread() is the way to
go.
--
+����������������������������+�������������������������������+
� Roger Oberholtzer � E-mail: [EMAIL PROTECTED] �
� OPQ Systems AB � WWW: http://www.opq.se/ �
� Erik Dahlbergsgatan 41-43 � Phone: Int + 46 8 314223 �
� 115 34 Stockholm � Mobile: Int + 46 733 621657 �
� Sweden � Fax: Int + 46 8 302602 �
+����������������������������+�������������������������������+
_______________________________________________
Linux-users mailing list
[EMAIL PROTECTED]
Unsubscribe/Suspend/Etc -> http://smtp.linux-sxs.org/mailman/listinfo/linux-users