From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 32EE97ED26 for ; Thu, 7 Jun 2012 19:37:10 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlABAAnm0E/RVdW2imdsb2JhbABFtBkIIgEBAQoJDQcSBiOCMQITGQEbHgMSEF0BEQEFASIbGodaAQMLC5dpgmAJA4wignCFAwoZJw1XiHEBBQyRHQOVHYESiBGEej6EAA X-IronPort-AV: E=Sophos;i="4.75,732,1330902000"; d="scan'208";a="161814407" Received: from mail-yx0-f182.google.com ([209.85.213.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-MD5; 07 Jun 2012 19:37:09 +0200 Received: by yenl8 with SMTP id l8so974297yen.27 for ; Thu, 07 Jun 2012 10:37:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=b5KFISDDgOxLfO1SVZA+lAxtOBQMS6W43beBfk1w1DI=; b=BLxpPotD/tIArJUwIKDgLW6sWIwDP1R7b4rnkVk8iw5sxxe4sf13zTTYpuZWI7mHm2 WGOUUQqEQfaItTOYQogVai332Rv+KNKw3cdkALFxFVCl/JthvKUZNjfNryB3MfiHqfgP xFLavtmeaJ3wmQGid5OxJgM/UOS0XX2LFmy9NTkOSxUBme5aSzjAf3tqm4StmxdqFQkA XwdlBI4Cmhe0cXCILl1hnVX0ZMANXcxIRn37605DvqEN5Gy88/U+yuxncrtLEFFSZNGO ybJQk5zMgK0GYkv2MIOWBm7WTCX/3+AuJjJf8+7nHi5JXQK1yF44BR/Fk1JlAw57Nlcl Tbnw== MIME-Version: 1.0 Received: by 10.68.189.198 with SMTP id gk6mr10393856pbc.102.1339090628291; Thu, 07 Jun 2012 10:37:08 -0700 (PDT) Received: by 10.68.38.166 with HTTP; Thu, 7 Jun 2012 10:37:08 -0700 (PDT) Date: Thu, 7 Jun 2012 18:37:08 +0100 Message-ID: From: Joel Reymont To: caml-list Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] input_line for zero-terminated strings I'm trying to read C-style strings terminated with \0. Does Pervasives.input_line provide the optimal implementation for me to clone? Thanks, Joel --- let input_line ic = let buf = ref (string_create 128) in let pos = ref 0 in begin try while true do if !pos = string_length !buf then begin let newbuf = string_create (2 * !pos) in string_blit !buf 0 newbuf 0 !pos; buf := newbuf end; let c = input_char ic in if c = '\n' then raise Exit; !buf.[!pos] <- c; incr pos done with Exit -> () | End_of_file -> if !pos = 0 then raise End_of_file end; let res = string_create !pos in string_blit !buf 0 res 0 !pos; res -------------------------------------------------------------------------- AlgoKit: EasyLanguage trading strategies, on the server, w/ Rithmic R|API ---------------------+------------+--------------------------------------- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont ---------------------+------------+---------------------------------------