caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Returning a file handle from C (fopen)
@ 2004-09-21 22:06 Jeremy Cowgar
  2004-09-22  0:14 ` David Brown
  2004-09-22  1:20 ` Eric C. Cooper
  0 siblings, 2 replies; 3+ messages in thread
From: Jeremy Cowgar @ 2004-09-21 22:06 UTC (permalink / raw)
  To: OCaml Mailing List

Greetings,

I am trying to return a file handle from C. A simple Val_long does not
work, so I did some research and found something like the following:

  return caml_alloc_channel(caml_open_descriptor_out(myhandle));

This compiles (with 2 warnings):

  warning: implicit declaration of function `caml_alloc_channel'
  warning: implicit declaration of function `caml_open_descriptor_out'

However, the functions should be avaliable once running in ocaml, no?

Anyway, my real problem lies in the fact that when I do something like:

let fh = get_my_out_handle () in
Printf.fprintf fh "Hello, World!\n";;

nothing appears in my output file. No warning, errors or anything. In my
C source, I can do the exact thing and the contents are written.

Can anyone help me return a file handle from C to OCaml that can be used
with the OCaml output/input functions? I do realize a different type
would have to be returned for input/output. I was working on the output
portion first.

Thanks,

Jeremy Cowgar

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Returning a file handle from C (fopen)
  2004-09-21 22:06 [Caml-list] Returning a file handle from C (fopen) Jeremy Cowgar
@ 2004-09-22  0:14 ` David Brown
  2004-09-22  1:20 ` Eric C. Cooper
  1 sibling, 0 replies; 3+ messages in thread
From: David Brown @ 2004-09-22  0:14 UTC (permalink / raw)
  To: Jeremy Cowgar; +Cc: OCaml Mailing List

On Tue, Sep 21, 2004 at 06:06:20PM -0400, Jeremy Cowgar wrote:
> Greetings,
> 
> I am trying to return a file handle from C. A simple Val_long does not
> work, so I did some research and found something like the following:

You could just return the Val_long, and use Unix.out_channel_of_descr in
the ocaml world to get an ocaml channel.

Dave

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Returning a file handle from C (fopen)
  2004-09-21 22:06 [Caml-list] Returning a file handle from C (fopen) Jeremy Cowgar
  2004-09-22  0:14 ` David Brown
@ 2004-09-22  1:20 ` Eric C. Cooper
  1 sibling, 0 replies; 3+ messages in thread
From: Eric C. Cooper @ 2004-09-22  1:20 UTC (permalink / raw)
  To: OCaml Mailing List

On Tue, Sep 21, 2004 at 06:06:20PM -0400, Jeremy Cowgar wrote:
> I am trying to return a file handle from C. A simple Val_long does not
> work, so I did some research and found something like the following:
> 
>   return caml_alloc_channel(caml_open_descriptor_out(myhandle));
> [...] 
> Anyway, my real problem lies in the fact that when I do something like:
> 
> let fh = get_my_out_handle () in
> Printf.fprintf fh "Hello, World!\n";;
> 
> nothing appears in my output file. No warning, errors or anything. In my
> C source, I can do the exact thing and the contents are written.

Have you called either flush or close_out on your handle?  The OCaml
channel values add a layer of buffering, similar to C stdio, on top of
the file descriptor.

-- 
Eric C. Cooper          e c c @ c m u . e d u

-------------------
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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-09-22  1:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-21 22:06 [Caml-list] Returning a file handle from C (fopen) Jeremy Cowgar
2004-09-22  0:14 ` David Brown
2004-09-22  1:20 ` Eric C. Cooper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).