Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user names

Status
Not open for further replies.

zskater

Programmer
Apr 14, 2001
22
GB
my problem is I cant find how to access the users name who created each file in a directory
I know using ls -l can tell you this but Im not accessing it from the command line

For finding the size of the files and the times they were last modified I have been using stbuf.st_size and stbuf.st_mtime
both from stat.h

In stat.h there is information for getting UID and GID but I cant find anything for the actual name (user name eg. steve)

Can anyone help

Cheers Steve
 
If i remember correct there is a fuction "id" which gives the current Id.
hnd
hasso55@yahoo.com

 
Be easy.
Just call "ls -l" trough system(); call
and parse the output.
Will work on all unixes.
 
How about this?

Use stat to get the UID for the file and then call getpwent to convert UID into a name:

#include <sys/types.h>
#include <sys/stat.h>
#include <pwd.h>

struct passwd *userinfo;
struct stat buf;
char *filespec = &quot;/usr/home/example&quot;;

stat(filespec, &buf);
userinfo = getpwuid(buf.st_uid);
printf(&quot;User %s owns file %s\n&quot;, userinfo.pw_name, filespec);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top