我有一个调用 C 函数并使用 open() 打开文件的 fortran 程序
main.f90:
PROGRAM TEST
integer :: oflag, mode
!Set oflag to O_CREAT|O_RDWR
oflag = 66
mode = 600
call test2("test.txt", oflag, mode)
END PROGRAM
测试.c:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#pragma weak test2_ = test2
#pragma weak test2__ = test2
#pragma weak TEST2 = test2
void test2(char* filename, int* flag, int* mode)
{
int fd;
if(-1 == (fd = open(filename, *flag, *mode)))
puts("Returned -1");
}
我编译为:
gcc -c test.c
gfortran main.f90 test.o
当我运行程序时,它会创建文件 test.txt,但权限不正确:
---x--x--T 1 xyz users 0 2011-09-24 16:40 test.txt
应该是什么时候
-rw------- 1 xyz users 0 2011-09-24 16:45 test.txt
如果我从另一个 C 程序调用此函数,它工作正常。有人可以指出出了什么问题吗?
规格:64 位 linux GNU Fortran (SUSE Linux) 4.5.0, GCC (SUSE Linux) 4.5.0
谢谢, Kshitij