怎样检查对应的路径是一个链接目录
来源:互联网 发布:unity3d接入ios内购 编辑:程序博客网 时间:2024/04/27 22:33
int check_linkdir( char *pathname )
{
int res = 0;
struct stat lstatbuf;
struct stat statbuf;
res = stat( pathname, &statbuf );
if (res != 0)
{
perror("stat");
return 0 ;
}
res = lstat( pathname, &lstatbuf );
if (res != 0)
{
perror("lstat");
return 0 ;
}
if ( (lstatbuf.st_mode & S_IFMT) == S_IFLNK)
{
if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
{
printf("this is a link dir /n");
return 1 ;
}
}
else
return 0 ;
}
这个用到二个函数,stat和lstat,它们对应的原型是:
int stat(const char *path, struct stat *buf);
int lstat(const char *path, struct stat *buf);
These functions return information about a file. No permissions are required on the file itself, but -- in the
case of stat() and lstat() -- execute (search) permission is required on all of the directories in path that lead to the file.
stat() stats the file pointed to by path and fills in buf.
lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the
file that it refers to.
详细资料查看man手册
{
int res = 0;
struct stat lstatbuf;
struct stat statbuf;
res = stat( pathname, &statbuf );
if (res != 0)
{
perror("stat");
return 0 ;
}
res = lstat( pathname, &lstatbuf );
if (res != 0)
{
perror("lstat");
return 0 ;
}
if ( (lstatbuf.st_mode & S_IFMT) == S_IFLNK)
{
if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
{
printf("this is a link dir /n");
return 1 ;
}
}
else
return 0 ;
}
这个用到二个函数,stat和lstat,它们对应的原型是:
int stat(const char *path, struct stat *buf);
int lstat(const char *path, struct stat *buf);
These functions return information about a file. No permissions are required on the file itself, but -- in the
case of stat() and lstat() -- execute (search) permission is required on all of the directories in path that lead to the file.
stat() stats the file pointed to by path and fills in buf.
lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the
file that it refers to.
详细资料查看man手册
- 怎样检查对应的路径是一个链接目录
- 怎样使用 Python 来判断一个路径是否存在判断一个路径是文件还是目录
- shell小记-检查一个目录是够为空
- 沙盒目录结构是怎样的?
- maven项目的classpath路径对应的文件目录
- 怎样得到一个进程的全路径
- php根据路径生成对应的文件目录
- 黑马程序员:判断一个路径是否是目录
- Linux/Unix 判断一个路径是目录还是文件
- 怎样删除一个目录
- 忘了是怎样的一个冬天
- 哼哼,又是怎样的一个开始。
- 这是一个怎样的时代?
- 5月是怎样的一个月
- 学习是怎样的一个过程??
- Throwable是一个怎样的类?
- Throwable是一个怎样的类?
- 这是怎样的一个女孩子
- struts-config配置数据源
- SQL Server 2005中的T-SQL增强
- 编码一个月,记录一下
- 有用的国外开源项目网址- -
- 苦恼啊,仿真!
- 怎样检查对应的路径是一个链接目录
- 利用WSO2发布数据服务
- winsock中select的作用
- 一个撕心裂肺的爱情故事(转)
- 关于web打印隐藏打印按扭
- 在socket通讯程序里,select 起到什么作用
- “开始->运行”命令大全
- DataBinder.Eval与Bind对比总结
- WebService 建立VBA与Java之间的通信