日期:2014-05-16  浏览次数:20664 次

程序出错的问题
最近在看UNIX环境下的   高级编程,在书的56页有这样一个程序
#include   <unistd.h>
#include   <stdio.h>
#include   <stdlib.h>
#include   <sys/types.h>
#include   <sys/stat.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   )
                                {
                                                printf( "lstat   error.\n ");
                                                continue;
                                }
                                if             (S_ISREG(buf.st_mode))   ptr= "regular ";
                                else   if   (S_ISDIR(buf.st_mode))   ptr= "directory ";
                                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= "fifo ";
#ifdef     S_ISLNK
                                else   if   (S_ISLNK(buf.st_mode))   ptr= "symbolic   link ";
#endif
#ifdef   S_ISSOCK
                                else   if   (S_ISSOCK(buf.st_mode))   ptr= "socket ";
#endif
                                else         ptr= "**   unknown   mode   ** ";
                                printf( "%s\n ",ptr);