Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Reading into a string from C code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-02-21 (16:28)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Reading into a string from C code
This is my wrapper around the Apache ap_get_client_block call:

CAMLprim value
mod_caml_request_get_client_block (value rv, value str)
  CAMLparam2 (rv, str);
  request_rec *r = Request_rec_val (rv);
  int n = string_length (str);
  char *buffer = String_val (str);
  int i = ap_get_client_block (r, buffer, n);
  if (i == -1) raise_http_error (HTTP_INTERNAL_SERVER_ERROR);
  CAMLreturn (Val_int (i));

ap_get_client_block is prototyped as:

long ap_get_client_block (request_rec *, char *buffer, int buffer_size);

Its job is to read up to buffer_size bytes into buffer and return the
number of bytes actually written into this buffer.

Is my wrapper correct?  Can I call String_val (str) and then write
into that buffer in order to write into the string?  I suspect not,
actually, since although it works most of the time, I seem to be
getting some data corruption errors occasionally.


Richard Jones.
Merjis Ltd. - improving website return on investment
C2LIB is a library of basic Perl/STL-like types for C. Vectors, hashes,
trees, string funcs, pool allocator:

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: