#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
struct stat file_attr;
if (stat(argv[0], &file_attr) == -1)
{
perror("stat failure");
return -1;
}
std::string file_attr_name;
if (S_ISDIR(file_attr.st_mode))
{
file_attr_name = "file is dir";
}
else if (S_ISREG(file_attr.st_mode))
{
file_attr_name = "file is normal";
}
else if (S_ISBLK(file_attr.st_mode))
{
file_attr_name = "file is block device";
}
else if (S_ISCHR(file_attr.st_mode))
{
file_attr_name = "file is char device";
}
else if (S_ISFIFO(file_attr.st_mode))
{
file_attr_name = "file is FIFO";
}
else if (S_ISSOCK(file_attr.st_mode))
{
file_attr_name = "file is socket";
}
else if (S_ISLNK(file_attr.st_mode))
{
file_attr_name = "file is link";
}
else
{
file_attr_name = "unkown file type";
}
std::cout<<file_attr_name<<std::endl;
return 0;
}
#include <fcntl.h>
#include <errno.h>
#include <string>
#include <iostream>
int main(int argc, char* argv[])
{
struct stat file_attr;
if (stat(argv[0], &file_attr) == -1)
{
perror("stat failure");
return -1;
}
std::string file_attr_name;
if (S_ISDIR(file_attr.st_mode))
{
file_attr_name = "file is dir";
}
else if (S_ISREG(file_attr.st_mode))
{
file_attr_name = "file is normal";
}
else if (S_ISBLK(file_attr.st_mode))
{
file_attr_name = "file is block device";
}
else if (S_ISCHR(file_attr.st_mode))
{
file_attr_name = "file is char device";
}
else if (S_ISFIFO(file_attr.st_mode))
{
file_attr_name = "file is FIFO";
}
else if (S_ISSOCK(file_attr.st_mode))
{
file_attr_name = "file is socket";
}
else if (S_ISLNK(file_attr.st_mode))
{
file_attr_name = "file is link";
}
else
{
file_attr_name = "unkown file type";
}
std::cout<<file_attr_name<<std::endl;
return 0;
}