> Hi Everyone,
> I am writing a progam that can find information for a file by using
> stat() func. Although I can get user id and group id from this
> function.I am trying to find if there's a function in C that can help
> convert a known user id to a user name in Linux OS?
getpwuid(3), and reference the *pw_name field of the returned structure.
Quote:>And how to convert
> a known group id to the group name?
getgrgid(3), and reference the *gr_name field of the returned structure
Quote:> If there is no such a function,
> can I write one and how to do it?
For userid/username values, you can use the
getpwent(3) set of functions, or open and read the /etc/passwd file
For groupid/groupname values, you can use the
getgrent(3) set of functions, or open and read the /etc/group file
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)