Re: Determining a file's unix file descriptor int value from its pathname?

Raymond Toy <[email protected]>
Newsgroups gmane.lisp.cmucl.general
Message-ID <[email protected]>
Denis Papathanasiou wrote:
> I'm experimenting with alien objects to get my lisp app to use the
> unix native fcntl function for file locking.
>
> Following the example in "Advanced Programming in the UNIX
> Environment" book (http://apuebook.com/), I've built the lockfile.o
> object file.
>
> Its function call is: int lockfile(int fd) where fd is the integer
> representation of the file, as the unix os knows it.
>
> Inside my lisp code, I'm able load the object file by calling
> (ext:load-foreign "lockfile.o") and I'm all set to invoke the lockfile
> function with the (def-alien-routine) macro.
>
> But now, I need to pass it an integer (fd) which represents the unix
> file descriptor.
>
> All I have, though, is the lisp pathname object.
>
> Is there a way to convert pathname to the correct integer value?
>
The lockfile wants an fd, which, AFAIK, only exists AFTER you open the 
file.  So you have to open the file in Lisp too, via, with-open-file or 
open or whatever.  This will produce a fd-stream object and then you can 
use sys:fd-stream-fd to get the fd associated with that file.

Ray
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.