chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Getting C file handle from port?


From: Peter Bex
Subject: Re: [Chicken-users] Getting C file handle from port?
Date: Sat, 20 Mar 2010 15:08:39 +0100
User-agent: Mutt/1.4.2.3i

On Sat, Mar 20, 2010 at 10:58:54AM -0300, Jeronimo Pellegrini wrote:
> Hello,
> 
> Suppose I have an open port:
> 
> (let ((in (open-input-file "whatever")))
>   ...
>   (let ((x (read in)))
>     ...))
> 
> I'd like to switch from using Chicken's read implementation to
> something I'd write in C (using the FFI). But I didn't find in
> the documentation anything that would allow me to turn a port
> into a C file handle.

I don't know about file *handles* (ie of type FILE *), but you can
obtain the descriptor using port->fileno in the POSIX unit:
http://chicken.wiki.br/man/4/Unit posix#port-fileno

You might then use the POSIX function fdopen(3) to convert the
descriptor into a FILE *.

> Is it possible at all?

It's always possible!

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth




reply via email to

[Prev in Thread] Current Thread [Next in Thread]