From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA18908; Tue, 6 Aug 2002 16:01:03 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA18953 for ; Tue, 6 Aug 2002 16:01:02 +0200 (MET DST) Received: from waco.inria.fr (waco.inria.fr [128.93.25.2]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g76E10105775; Tue, 6 Aug 2002 16:01:00 +0200 (MET DST) Received: (from verlyck@localhost) by waco.inria.fr (8.11.1/8.11.1) id g76E10K24093; Tue, 6 Aug 2002 16:01:00 +0200 Date: Tue, 6 Aug 2002 16:01:00 +0200 Message-Id: <200208061401.g76E10K24093@waco.inria.fr> X-Authentication-Warning: waco.inria.fr: verlyck set sender to Bruno.Verlyck@inria.fr using -f To: andrieu@ijm.jussieu.fr CC: mtucker@eecs.harvard.edu, caml-list@inria.fr In-reply-to: <15695.51531.965211.875413@akasha.ijm.jussieu.fr> (andrieu@ijm.jussieu.fr) Subject: Re: [Caml-list] Sharing Files between OCaml and C From: Bruno.Verlyck@inria.fr References: <200208051929.VAA0000007257@beaune.inria.fr> <15695.51531.965211.875413@akasha.ijm.jussieu.fr> Mime-Version: 1.0 (generated by tm-edit 7.106) Content-Type: text/plain; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Olivier Andrieu Date: Tue, 6 Aug 2002 15:04:11 +0200 Michael Tucker [Monday 5 August 2002] : > I would like to share access to a file between a C function and an OCaml > function in an application put together with CamlIDL. If I have a C > function with prototype: > int manip_file(FILE* f, int x); > Is there any support in CamlIDL for passing a file that was opened in > OCaml. I checked the archives, and found a message that described pulling > out the integer file descriptor, and passing that to fdopen on the C side, > but that was it -- the same message asked about better support from CamlIDL > (this was winter 2000), but I couldn't find a response. Has this changed > over the past year and a half, or is that the best method? Yes, I think that's still the best method: - get the descriptor with Unix.descr_of_in_channel or Unix.descr_of_out_channel - fdopen it on the C side You might also want to call dup() on the fd so that your FILE* stream is still working if the original caml channel is closed. But of course you now have two concurrent buffering mechanisms, so flushing when switching the writing side (C vs Caml) for out_channels is mandatory, and seeking cautiously when switching the reading side (for in_channels) too. Bruno. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners