1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
5 -- G N A T . B I N D _ E N V I R O N M E N T --
9 -- Copyright (C) 2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNARL was developed by the GNARL team at Florida State University. --
28 -- Extensive contributions were provided by AdaCore. --
30 ------------------------------------------------------------------------------
34 package body GNAT
.Bind_Environment
is
40 function Get
(Key
: String) return String is
41 use type System
.Address
;
43 Bind_Env_Addr
: System
.Address
;
44 pragma Import
(C
, Bind_Env_Addr
, "__gl_bind_env_addr");
45 -- Variable provided by init.c/s-init.ads, and initialized by
46 -- the binder generated file.
48 Bind_Env
: String (Positive);
49 for Bind_Env
'Address use Bind_Env_Addr
;
50 pragma Import
(Ada
, Bind_Env
);
51 -- Import Bind_Env string from binder file. Note that we import
52 -- it here as a string with maximum boundaries. The "real" end
53 -- of the string is indicated by a NUL byte.
55 Index
, KLen
, VLen
: Integer;
58 if Bind_Env_Addr
= System
.Null_Address
then
62 Index
:= Bind_Env
'First;
64 -- Index points to key length
67 KLen
:= Character'Pos (Bind_Env
(Index
));
70 Index
:= Index
+ KLen
+ 1;
72 -- Index points to value length
74 VLen
:= Character'Pos (Bind_Env
(Index
));
75 exit when Bind_Env
(Index
- KLen
.. Index
- 1) = Key
;
77 Index
:= Index
+ VLen
+ 1;
80 return Bind_Env
(Index
+ 1 .. Index
+ VLen
);
83 end GNAT
.Bind_Environment
;