linux下c/c++语言判断文件是否存在,是否可写

代码如下:

#include <unistd.h>

int FindFile(const char *file)
{

	/* Check for existence */
   	if( (access( file, 0 )) != -1 )
   	{
      	cm_printf(LOG_LEVEL_DEBUG, "File %s  exists .", file );

      	/* Check for write permission */
      	if( (access( file, 2 )) != -1 )
      	{
         	cm_printf(LOG_LEVEL_DEBUG, "File %s  has write permission ", file );
			return 2;
   		}
		
		return 1;
   	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/sun007700/article/details/89211857
今日推荐