home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
-
- int laststat=1,i=1;
- char *name;
- struct stat buf;
- struct stat *pb = &buf;
- if(argc<=1)
- {
- printf("requires an argument\n");
- exit(1);
- }
- for(i=1;i<argc;i++)
- {
- name = argv[i];
- if(lstat(name,pb)== -1)
- printf("lstat: %s not found, i=%d\n",name,i);
- else
- {
- printstat(pb,name);
- if((pb->st_mode&S_IFLNK)==S_IFLNK)
- {
- char realname[257]; int i,jhn;
- for(i=0;i<257;i++)realname[i]='\0';
- readlink(name,realname,257);
- printf(
- "---symbolic link, here's what it points to:---\n");
- laststat=0;/*for exiting with 0 status (true)*/
- jhn=stat(name,pb);
- if(jhn==0)
- printstat(pb,realname);
- else {printf("\"%s\" not found--this could be a real problem!!\n",realname);exit(1);}
- }
- else
- laststat=1; /*for exiting with false status*/
- }
- }
- exit(laststat);
- }
- printstat(pb,name)
- struct stat *pb;
- char *name;
- {
- char *ptime, *ctime();
- printf("%s: ---------\n",name);
- printf("file-mode=%o(oct) inode=%d st_dev=%x(hex) #links=%d\n",
- pb->st_mode,
- pb->st_ino,
- pb->st_dev,
- pb->st_nlink);
- printf("owner=%d group=%d filesize=%d bytes\n",
- pb->st_uid,pb->st_gid,pb->st_size);
- ptime=ctime(&(pb->st_atime));
- printf("data last accessed %s",ptime);
- ptime=ctime(&(pb->st_mtime));
- printf("data last modified %s",ptime);
- ptime=ctime(&(pb->st_ctime));
- printf("file status last changed %s",ptime);
- }
-