关于网友提出的“ 关于打开文件出现errno 84错误的问题”问题疑问,本网通过在网上对“ 关于打开文件出现errno 84错误的问题”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 关于打开文件出现errno 84错误的问题描述:
问题如下,在打开文件前先使用了access(tmpFileName,0) 测试了这个文件可不可以操作
int nFile = open ( tmpFileName, O_CREAT|O_RDWR, S_IROTH|S_IRUSR|S_IRGRP );
if(-1 == nFile)
{
//printf("\n调试位置为: %s %d \n",__FILE__,__LINE__);
//printf("打开文件 %s 失败, 编号为 %d\n\n",tmpFileName,errno);
//打开失败
return NULL;
}
------------输出errno为84的问题 查了下说是不合法的二进制序列,但是我这个文件是空的,一直都不是不存在的文件,打开发现不存在创建的,而且试了在打开前用touch创建文件,再OPEN也是出现同样的问题,大家有遇到过这种问题吗。
谢谢
解决方案1:没问题了 解决方案2:
字符集问题。
http://ubuntuforums.org/showthread.php?t=911599
别人送过来的文件看运行程序的用户属于其他组用户、本组内用户或者文件属主, 继而调用函数来赋予相应的写权限.
#include
#include
int chmod(const char *path, mode_t mode);
int fchmod(int fildes, mode_t mode);
File mode bits:
S_IRWXU
read, write, execute/search by owner
S_IRUSR
read permission, owner
S_IWUSR
write permission, owner
S_IXUSR
execute/search permission, owner
S_IRWXG
read, write, execute/search by group
S_IRGRP
read permission, group
S_IWGRP
write permission, group
S_IXGRP
execute/search permission, group
S_IRWXO
read, write, execute/search by others
S_IROTH
read permission, others
S_IWOTH
write permission, others
S_IXOTH
execute/search permission, others
S_ISUID
set-user-ID on execution
S_ISGID
set-group-ID on execution
S_ISVTX
on directories, restricted deletion flag
The bits defined by S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, S_ISUID, S_ISGID and S_ISVTX are unique.
S_IRWXU is the bitwise OR of S_IRUSR, S_IWUSR and S_IXUSR.
S_IRWXG is the bitwise OR of S_IRGRP, S_IWGRP and S_IXGRP.
S_IRWXO is the bitwise OR of S_IROTH, S_IWOTH and S_IXOTH.
errno.84 is: Invalid or incomplete multibyte or wide character
检查一下你的文件名
在linux/unix上吧,没遇见过这种问题。是不是temp文件本身的问题,比如文件格式异常、不合法等等什么的。
解决方案7:会不会是你的打开方式是O_RDWR,可读可写打开,但是你给用户权限都只有读权限S_IROTH|S_IRUSR|S_IRGRP ,权限不匹配呢?
解决方案8: ls -l
看一下文件的权限.
程序是正常的,应该是权限不够.因为创建文件的时候只对所有用户开放了只读权限.
第一次创建是成功的, 故4L的程序每次都能程序.
当文件存在的时候, 如果不删除原来的文件, 那么该文件将会以读写方式打开.
所以权限不足. 解决方案10:
文件存在时,所有的用户都只有只读权限.
而你程序里如果文件存在时用读写方式打开,明显权限不足.
用命令
chmod 777 程序中要打开的文件名.
然后用ll 文件名,看一下权限打开是否成功. 解决方案11:
这样试试:
#include
#include
#include
#include
int main()
{
char tmpFileName[255] = "kkk_hw";
int nFile;
if(access(tmpFileName, 0) == 0) { //判断文件是否存在, 如果存在,删除.
printf("文件已经存在!\n");
unlink(tmpFileName);
printf("文件已经删除!\n");
}
nFile = open( tmpFileName, O_CREAT|O_RDWR, S_IROTH|S_IRUSR|S_IRGRP );
if(-1 == nFile)
{
printf("\n调试位置为: %s %d \n",__FILE__,__LINE__);
printf("打开文件 %s 失败, 编号为 %d\n\n",tmpFileName,errno);
//打开失败
return 1;
}
close(nFile); //关闭
printf("文件创建成功!\n");
return 0;
}