- #include "apue.h"
-
int
-
main(int argc,char * argv[] )
-
{
-
int i;
-
struct stat buf;
-
char *ptr;
-
-
for( i = 1; i < argc ; i++)
-
{
-
printf("%s:",argv[i]);
-
if (lstat(argv[i],&buf) < 0) {
-
err_ret("lstat error ");
-
continue;
-
}
-
-
if ( S_ISREG(buf.st_mode))
-
ptr = "regular";
-
else if ( S_ISDIR(buf.st_mode))
-
ptr = "direcotry ";
-
else if ( S_ISCHR(buf.st_mode))
-
ptr = "character special ";
-
else if ( S_ISBLK(buf.st_mode))
-
ptr = "block special ";
-
else if ( S_ISFIFO(buf.st_mode))
-
ptr = "FILE special ";
-
else if ( S_ISLNK(buf.st_mode))
-
ptr = "link special ";
-
else if ( S_ISSOCK(buf.st_mode))
-
ptr = "sock special ";
-
else
-
ptr =" ** unknown mode ** ";
-
printf("%s\n",ptr);
-
}
-
exit(0);
-
}
output of the test:
./c4-1.c[K[K /etc/password /etc /e[Kdev/in
itctl /dev/log /dev/tty \[K /dev/scsi/host0/buf[Ks0/target0/lun0/cd /v[Kdev/cdrom
/etc/password:lstat error ;No such file or directory
/etc:direcotry
/dev/initctl:lstat error ;No such file or directory
/dev/log:sock special
/dev/tty:character special
/dev/scsi/host0/bus0/target0/lun0/cd:lstat error ;No such file or directory
/dev/cdrom:link special
阅读(1229) | 评论(0) | 转发(0) |