I have a fortran program which calls a C function and opens a file using open()
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
test.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");
}
I compile as:
gcc -c test.c
gfortran main.f90 test.o
When I run the program, it creates the file test.txt, but with incorrect permissions:
---x--x--T 1 xyz users 0 2011-09-24 16:40 test.txt
when it should have been
-rw------- 1 xyz users 0 2011-09-24 16:45 test.txt
If I call this function from another C program, it works fine. Can someone point out what is going wrong?
Specs:
64 bit linux
GNU Fortran (SUSE Linux) 4.5.0, GCC (SUSE Linux) 4.5.0
Thanks,
Kshitij
Your constants are wrong because permissions are typically specified in octal. Try this program:
I get:
600 octal eqals 384 decimal.