Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rice!uw-beaver!uw-june!ka From: ka@cs.washington.edu (Kenneth Almquist) Newsgroups: comp.unix.wizards Subject: Re: FORTRAN I/O channel => file descriptor..how?? Summary: Use stat and fstat Message-ID: <11029@june.cs.washington.edu> Date: 9 Mar 90 05:09:26 GMT References: <5725.25f25d3d@elroy.uh.edu> Organization: U of Washington, Computer Science, Seattle Lines: 33 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