File : s-cstrle-zfp.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- S Y S T E M . C . S T R L E N --
4 -- --
5 -- S p e c --
6 -- --
7 -- Copyright (C) 2013, AdaCore --
8 -- --
9 -- GNAT is free software; you can redistribute it and/or modify it under --
10 -- terms of the GNU General Public License as published by the Free Soft- --
11 -- ware Foundation; either version 3, or (at your option) any later ver- --
12 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
13 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
14 -- or FITNESS FOR A PARTICULAR PURPOSE. --
15 -- --
16 -- --
17 -- --
18 -- --
19 -- --
20 -- You should have received a copy of the GNU General Public License and --
21 -- a copy of the GCC Runtime Library Exception along with this program; --
22 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
23 -- <http://www.gnu.org/licenses/>. --
24 -- --
25 -- GNAT was originally developed by the GNAT team at New York University. --
26 -- Extensive contributions were provided by Ada Core Technologies Inc. --
27 -- --
28 ------------------------------------------------------------------------------
29
30 package body System.C.Strlen is
31
32 type C_String is array (size_t) of Character;
33
34 ------------
35 -- strlen --
36 ------------
37
38 function strlen (Str : Address) return size_t is
39 str_p : C_String;
40 for str_p'Address use Str;
41 pragma Import (Ada, str_p);
42
43 begin
44 for J in str_p'Range loop
45 if str_p (J) = ASCII.NUL then
46 return J;
47 end if;
48 end loop;
49
50 return size_t'Last;
51 end strlen;
52
53 end System.C.Strlen;