English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] Matching when
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-08-06 (14:01)
From: Bruno.Verlyck@i...
Subject: Re: [Caml-list] Sharing Files between OCaml and C
   From: Olivier Andrieu <andrieu@ijm.jussieu.fr>
   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
   - 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.

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