]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/m2/mc-boot/GEnvironment.c
Update copyright years.
[thirdparty/gcc.git] / gcc / m2 / mc-boot / GEnvironment.c
CommitLineData
1eee94d3
GM
1/* do not edit automatically generated by mc from Environment. */
2/* Environment.mod provides access to the environment settings of a process.
3
83ffe9cd 4Copyright (C) 2001-2023 Free Software Foundation, Inc.
1eee94d3
GM
5Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6
7This file is part of GNU Modula-2.
8
9GNU Modula-2 is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 3, or (at your option)
12any later version.
13
14GNU Modula-2 is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17General Public License for more details.
18
19Under Section 7 of GPL version 3, you are granted additional
20permissions described in the GCC Runtime Library Exception, version
213.1, as published by the Free Software Foundation.
22
23You should have received a copy of the GNU General Public License and
24a copy of the GCC Runtime Library Exception along with this program;
25see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26<http://www.gnu.org/licenses/>. */
27
28#include "config.h"
29#include "system.h"
30# if !defined (PROC_D)
31# define PROC_D
32 typedef void (*PROC_t) (void);
33 typedef struct { PROC_t proc; } PROC;
34# endif
35
36#if defined(__cplusplus)
37# undef NULL
38# define NULL 0
39#endif
40#define _Environment_H
41#define _Environment_C
42
43# include "GSYSTEM.h"
44# include "Glibc.h"
45# include "GASCII.h"
46# include "GStrLib.h"
47
48
49/*
50 GetEnvironment - gets the environment variable Env and places
51 a copy of its value into string, dest.
52 It returns TRUE if the string Env was found in
53 the processes environment.
54*/
55
56extern "C" unsigned int Environment_GetEnvironment (const char *Env_, unsigned int _Env_high, char *dest, unsigned int _dest_high);
57
58/*
59 PutEnvironment - change or add an environment variable definition EnvDef.
60 TRUE is returned if the environment variable was
61 set or changed successfully.
62*/
63
64extern "C" unsigned int Environment_PutEnvironment (const char *EnvDef_, unsigned int _EnvDef_high);
65
66
67/*
68 GetEnvironment - gets the environment variable Env and places
69 a copy of its value into string, dest.
70 It returns TRUE if the string Env was found in
71 the processes environment.
72*/
73
74extern "C" unsigned int Environment_GetEnvironment (const char *Env_, unsigned int _Env_high, char *dest, unsigned int _dest_high)
75{
76 typedef char *GetEnvironment__T1;
77
78 unsigned int High;
79 unsigned int i;
80 GetEnvironment__T1 Addr;
81 char Env[_Env_high+1];
82
83 /* make a local copy of each unbounded array. */
84 memcpy (Env, Env_, _Env_high+1);
85
86 i = 0;
87 High = _dest_high;
88 Addr = static_cast<GetEnvironment__T1> (libc_getenv (&Env));
89 while (((i < High) && (Addr != NULL)) && ((*Addr) != ASCII_nul))
90 {
91 dest[i] = (*Addr);
92 Addr += 1;
93 i += 1;
94 }
95 if (i < High)
96 {
97 dest[i] = ASCII_nul;
98 }
99 return Addr != NULL;
100 /* static analysis guarentees a RETURN statement will be used before here. */
101 __builtin_unreachable ();
102}
103
104
105/*
106 PutEnvironment - change or add an environment variable definition EnvDef.
107 TRUE is returned if the environment variable was
108 set or changed successfully.
109*/
110
111extern "C" unsigned int Environment_PutEnvironment (const char *EnvDef_, unsigned int _EnvDef_high)
112{
113 char EnvDef[_EnvDef_high+1];
114
115 /* make a local copy of each unbounded array. */
116 memcpy (EnvDef, EnvDef_, _EnvDef_high+1);
117
118 return (libc_putenv (&EnvDef)) == 0;
119 /* static analysis guarentees a RETURN statement will be used before here. */
120 __builtin_unreachable ();
121}
122
123extern "C" void _M2_Environment_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
124{
125}
126
127extern "C" void _M2_Environment_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
128{
129}