- 论坛徽章:
- 0
|
代码如下
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
write_tgt_id_fzs_no(0,1,0);
return 0;
}
int write_tgt_id_fzs_no(int tgt_id, int fzs_no, int queue_id)
{
char filename[8] = {0};
char buf[32] = {0};
int fd = -1;
size_t len = 0;
snprintf(filename, 8, "conf/%d", queue_id);
fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, 777);
if (-1 == fd)
{
printf("open %s error\n", filename);
perror("open");
return -1;
}
snprintf(buf, 32, "%d %d", tgt_id, fzs_no);
len = write(fd, buf, strlen(buf) + 1);
if (strlen(buf)+1 != len)
{
printf("write fail:%d:%d\n", (int)(strlen(buf)), (int)len);
perror("write");
return -1;
}
printf("success\n");
return 0;
}
为什么生成的文件权限是这样的?为什么不是可读可写的权限??请大神指导,谢谢了!
-r----x--t. 1 anxuan anxuan 4 Dec 31 16:42 0
|
|