C'S open()函數時,我有一個Fortran程序使用它調用C函數,並打開一個文件打開()不正確的文件權限調用從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
我很困惑,爲什麼它工作時,我稱之爲從C函數,而不是Fortran語言的功能? – jitihsk
你的C調用是什麼樣的?如果使用「0600」,則前導「0」指定八進制(參見[C標準的第6.4.4.1節](http://c0x.coding-guidelines.com/6.4.4.1.html))。 –
你是對的。我在我的C函數中有一個領先的「0」 – jitihsk