On 20 January 2018 at 22:08, john skaller <[email protected]> wrote:
> According to Real World Ocaml string_of_char_ptr can be used to convert a
> C char* to an Ocaml string. But I can’t find it anywhere in the API!
>
> Any clues?

I don't think that function is exposed in the API, at least in recent
versions.  But if you have a 'char ptr' value 'p' then you can convert
it to a string using 'coerce':

     coerce (ptr char) string p

For example:

     # let getenv = foreign "getenv" (string @-> returning (ptr char));;
     val getenv : string -> char Ctypes_static.ptr = <fun>
     # let p = getenv "USER";;
     val p : char Ctypes_static.ptr = (char*) 0x7ffe712cd9f8
     # coerce (ptr char) string p;;
     - : string = "jeremy"

Kind regards,

Jeremy
_______________________________________________
Ctypes mailing list
[email protected]
http://lists.ocaml.org/listinfo/ctypes

Reply via email to