linux,stat 函数请教
请教大家:
环境:centos5.2
功能:调用stat 函数获取文件的大小。
问题:需要获取 /mnt/1/2/1001$[1](2001-9-1 2001-9-2).dat 的文件大小,调用stat 如下:
//测试1:
char filefullpath[] = "/mnt/1/2/1001$[1](2001-9-1 2001-9-2).dat" ;
struct stat filestat;
int nRet = stat(filefullpath, &filestat);
printf("nRet %d ,errno %d,fileSize %d \n",nRet,errno,filestat.st_size);//实际输出 nRet = -1, errno :2 ,no such file
//测试2:
struct stat filestat;
int nRet = stat("/mnt/1/2/1001$[1](2001-9-1 2001-9-2).dat" , &filestat);
int nRet = stat(filefullpath, &filestat);
printf("nRet %d ,fileSize %d \n",nRet,filestat.st_size);//输出结果正确
//测试3:
char filefullpath[] = "/mnt/1/2/1001\\$\\[1\\]\\(2001-9-1\\ 2001-9-2\\).dat" ;
struct stat filestat;
int nRet = stat(filefullpath, &filestat);
printf("nRet %d ,fileSize %d \n",nRet,filestat.st_size);//实际输出 nRet = -1, errno :2 ,no such file
上述测试1,3 哪里不对?谢谢