fopen()函数在linux下的权限问题

cqmcgrady 2008-04-27 11:03:33
初学linux 碰到一个问题 在redhat9.0下 我编的一个c文件
FILE *f;
f=fopen("/tmp/test","w");
if(f==NULL){printf ("failed");}
else.....
可是总是返回NULL 没有创建成功 我已经修改了test目录权限为777

google了下但是有人说php权限是不一样的 搞不懂了 大家帮帮忙
...全文
673 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
不知,帮顶
visame 2008-04-28
  • 打赏
  • 举报
回复
我把//和\弄反了。
andy_cai 2008-04-27
  • 打赏
  • 举报
回复
用户权限呢?
Leejun527 2008-04-27
  • 打赏
  • 举报
回复
应该看以什么权限运行的该程序吧!
iu_81 2008-04-27
  • 打赏
  • 举报
回复
[henryfour@www test]$ cat a.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main() {
FILE* file_desc;

file_desc = fopen("/mnt/std.txt", "wb");
if (file_desc == NULL)
printf("error\n");
return 0;
}


[henryfour@www test]$ ll /mnt/std.txt
-rw-r--r-- 1 root root 0 01-09 20:06 /mnt/std.txt
[henryfour@www test]$ ./a.out
error
[henryfour@www test]$ su -c "chmod o+w /mnt/std.txt"
口令:
[henryfour@www test]$ ./a.out



fibbery 2008-04-27
  • 打赏
  • 举报
回复

if(f==NULL)
{
perror("Can not open file");//like this ,you can print error string
return -1;
}
cqmcgrady 2008-04-27
  • 打赏
  • 举报
回复
我是用root用户登陆的 今天因为系统问题重装了一次redhat系统 居然昨天的的fopen就可以用了(程序没变) 真的有点糊涂了
我现在是这样想的 我编的c程序运行时是不是也有root的权限(不是这个c本身的权限 那是别人access它的 我理解) 小弟初学 菜的很 请见谅

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧