C/C++ 判断路径为文件
/***************************************************
* 函数说明: 判断当前path参数是否为一个可读的文件
* 函数返回: 0 - 文件刻度 1 - 权限拒绝 -1 -函数错误
* 参 数 : path 文件路径.
***************************************************/
int isReadFile(const char *path)
{
struct stat info;
int euid,egid;
if ( 0!= stat(path,&info) )
{
return -1;
}
//if it is a file
if( S_IFREG != (info.st_mode & S_IFMT ) )
{
return 1;
}
euid=geteuid();//returns the real user ID of the
current process
egid=getegid();//returns the effective user ID of the
current process
//if effective user is root
if(euid==0)
{
if(info.st_mode & S_IRUSR || info.st_mode &
S_IRGRP ||info.st_mode & S_IROTH)
{
return 0;
}
相关文档:
系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......
Boss说,要看OpenGL,看了快一个月,总算出了个像样的东西,用C写了个3D迷宫,
虽然只有350行
代码,不过边学边写,足足写了一周时间,还是小有成就感的,活活活!
&n ......
字符数组和字符串
&字符数组和字符串的概念 &字符数组的初始化
&字符串的输入输出 &综合举例
字符数组和字符串的概念
字符数组是元素类型为字符的数组 ,它既具有普通数组的一般性质 ,又具有某些特殊性质。
& ......
1.求下面函数的返回值(微软)
int func(x)
{
int countx = 0;
while(x)
{
countx ++;
x = x&(x-1);
}
return countx;
}
假定x = 9999。 答案:8
思路:将x转化为2进制,看含有的1的个数。
2. 什么是“引用”?申明和使用“引用”要注意哪些问题?
答:引用就是某个目标变量的&ldquo ......
#include <list.h>
#include <dirent.h>
#include <iostream.h>
#include <sys/stat.h>
#include <sys/types.h>
/*****************************************************************
*函数功能: 目_录_遍_历.
*返回值: 成功返回0,失败返回非0.
*参数 path ......