#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
//判断路径是 目录还是文件 0:文件 1:目录
int CheckIsFile(char *InPath, char OutPath[256])
{
struct stat info;
//LOGI("g_DataPath===%s", g_DataPath);
//判断是相对路径还是绝对路径
if (InPath[0] == '/')
{
LOGI("absolute InPath--->OutPat!\n");
snprintf(OutPath, 256, "%s", InPath);
}
else
{
snprintf(OutPath, 256, "%s/%s", g_DataPath, InPath); //g_DataPath由java端传递进来的路径
}
//LOGI("g_DataPath_len==%d InPath_len==%d OutPath_len==%d ", sizeof(g_DataPath),sizeof(InPath),sizeof(*OutPath));
//LOGI("InPath==%s OutPath==%s", InPath, OutPath);
//路径还是文件?
stat(OutPath, &info);
if (S_ISREG(info.st_mode))//file
{
LOGI("This is a file!");
// LOGI("Flag==%d %d %d ",access(OutPath, R_OK ),access(OutPath, W_OK ), access(OutPath, F_OK));
//是否是文件且可读写
if(access(OutPath, R_OK | W_OK | F_OK) == 0)
{
LOGI("file exsit and W&R!\n");
return 0;
}
else
{
return -1;
}
}
else if(S_ISDIR(info.st_mode))//目录
{
LOGI("This is a directory\n");
return 1;
}
else
{
LOGI("Others\n");
return -2;
}
}
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
//判断路径是 目录还是文件 0:文件 1:目录
int CheckIsFile(char *InPath, char OutPath[256])
{
struct stat info;
//LOGI("g_DataPath===%s", g_DataPath);
//判断是相对路径还是绝对路径
if (InPath[0] == '/')
{
LOGI("absolute InPath--->OutPat!\n");
snprintf(OutPath, 256, "%s", InPath);
}
else
{
snprintf(OutPath, 256, "%s/%s", g_DataPath, InPath); //g_DataPath由java端传递进来的路径
}
//LOGI("g_DataPath_len==%d InPath_len==%d OutPath_len==%d ", sizeof(g_DataPath),sizeof(InPath),sizeof(*OutPath));
//LOGI("InPath==%s OutPath==%s", InPath, OutPath);
//路径还是文件?
stat(OutPath, &info);
if (S_ISREG(info.st_mode))//file
{
LOGI("This is a file!");
// LOGI("Flag==%d %d %d ",access(OutPath, R_OK ),access(OutPath, W_OK ), access(OutPath, F_OK));
//是否是文件且可读写
if(access(OutPath, R_OK | W_OK | F_OK) == 0)
{
LOGI("file exsit and W&R!\n");
return 0;
}
else
{
return -1;
}
}
else if(S_ISDIR(info.st_mode))//目录
{
LOGI("This is a directory\n");
return 1;
}
else
{
LOGI("Others\n");
return -2;
}
}