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
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: 2005-01-29 (12:00)
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 - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com