From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f0d9db8126fd91cb,start X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!u13g2000yqg.googlegroups.com!not-for-mail From: xorquewasp@googlemail.com Newsgroups: comp.lang.ada Subject: Converting pointers to non nul-terminated C "strings" to Ada string Date: Fri, 13 Feb 2009 22:58:55 -0800 (PST) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 81.86.41.187 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1234594735 20978 127.0.0.1 (14 Feb 2009 06:58:55 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 14 Feb 2009 06:58:55 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u13g2000yqg.googlegroups.com; posting-host=81.86.41.187; posting-account=D9GNUgoAAAAmg7CCIh9FhKHNAJmHypsp User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008122011 Iceweasel/3.0.5 (Debian-3.0.5-1),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:3625 Date: 2009-02-13T22:58:55-08:00 List-Id: Hello. I have some C code that returns a pointer to a buffer of "data" (not a string, just raw data) and also returns the size of the buffer: void get_data (char **ptr, int *size); int size; char *ptr; get_data (&ptr, &size); The code is part of a library that I don't control, so I can't change the interface. I've defined the Ada equivalent as: package CS renames Interfaces.C.Strings; package C renames Interfaces.C; procedure memory_data (data : out CS.chars_ptr; size : out C.int); pragma Import (C, memory_data, "get_data"); This works correctly, however I'm having trouble converting the chars_ptr type to an Ada string given that it's not nul- terminated. Attempts to do the following: return CS.Value (Item => data, Length => size); ... results in a String as long as the position of the first nul in the C string (the position is inevitably less than the length of the string). Is it possible to properly convert unterminated C strings or do I need to start messing about with raw System.Address types?