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
Copying strings which may contain NUL chars
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Copying strings which may contain NUL chars
Is this code safe?  hv_iterkey returns a string and a length, but the
string may contain ASCII NUL characters, and hence I cannot use
caml_copy_string directly.


CAMLprim value
perl4caml_hv_iterkey (value hev)
  CAMLparam1 (hev);
  CAMLlocal1 (strv);
  HE *he = He_val (hev);
  I32 len;
  char *str = hv_iterkey (he, &len);
  strv = caml_alloc_string (len);
  memcpy (String_val (strv), str, len);
  CAMLreturn (strv);

Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology -
Team Notepad - intranets and extranets for business -