chee13h@elroy.uh.edu (A JETSON News User) (03/06/90)
Hi, I am porting a FORTRAN application to the DG AVION unix system and have run up against this problem. The FORTRAN(alas!) compile supplied by them doesnot provide the fortran channel to file descriptor conversion. I need this desperately to use the file locking mechanishms. Can anybody suggest a way to hack an implementation to achieve the above?? I have come up with the following solution :: Convert the filename to an inode using stat() and try to access the file descriptor table and search. However, how do I access this table? I donot seem to find a functional interface to this table. thanks ashok chee13h@jane.uh.edu
ka@cs.washington.edu (Kenneth Almquist) (03/09/90)
chee13h@elroy.uh.edu (A JETSON News User) writes: > Hi, I am porting a FORTRAN application to the DG AVION unix system and > have run up against this problem. The FORTRAN(alas!) compile supplied by them > doesnot provide the fortran channel to file descriptor conversion. I need > this desperately to use the file locking mechanishms. Can anybody suggest a > way to hack an implementation to achieve the above?? > > I have come up with the following solution :: > > Convert the filename to an inode using stat() and try to access the > file descriptor table and search. However, how do I access this table? I do > not seem to find a functional interface to this table. Your idea is right, but there is no routine specificly designed to access the file table. However, fstat will do what you want: struct stat statb, fstatb; int fd; if (stat(filename, &statb) < 0) die("stat call failed"); for (fd = 0 ; ; fd++) { if (fd >= NOFILE) die("file not open!"); if (fstat(fd, &fstatb) >= 0 && fstatb.st_dev == statb.st_dev && fstatb.st_ino == statb.st_ino) break; /* file descriptor found */ } The preprocessor variable NOFILE is the maximum number of open files your system supports. On many systems this is defined in sys/param.h. Kenneth Almquist