extern "C" {
#endif
-/* argc and argv of the main program are saved under gnat_argc and gnat_argv,
- envp of the main program is saved under gnat_envp.
- While gnat_argc and gnat_envp are not needed, they are referenced from
- the binder-generated file so they need to be defined here */
+/* argc and argv of the main program are saved under gnat_argc and gnat_argv.
+ While gnat_argc is not needed, it's referenced from the binder-generated
+ file so it needs to be defined here */
int gnat_argc = 0;
char **gnat_argv = NULL;
+
+/* It used to be the case that users were required to forward the envp
+ parameter of main to the variable below when using a non-Ada main. The
+ consequences for failing to meet the requirement was improper operation of
+ Ada.Command_Line.Environment.
+
+ Today, users are not required to do anything with gnat_envp and
+ Ada.Command_Line.Environment does not use it anymore. In fact it's not used
+ by anything, but we keep its definition so that programs that obey the old
+ requirement keep linking. */
char **gnat_envp = NULL;
int
gnat_argv are the values as modified by toplev, and these routines
are accessed from the Osint package. */
-/* Also routines for accessing the environment from the runtime library.
- Gnat_envp is the original envp value as stored by the binder generated
- main program, and these routines are accessed from the
- Ada.Command_Line.Environment package. */
-
#ifdef IN_RTS
#include "runtime.h"
#include <stdlib.h>
#include "adaint.h"
#endif
+#include "env.h"
+
#ifdef __cplusplus
extern "C" {
#endif
-/* argc and argv of the main program are saved under gnat_argc and gnat_argv,
- envp of the main program is saved under gnat_envp. */
+/* argc and argv of the main program are saved under gnat_argc and gnat_argv */
int gnat_argc = 0;
char **gnat_argv = NULL;
-char **gnat_envp = NULL;
-#if defined (_WIN32) && !defined (RTX)
-/* Note that on Windows environment the environ point to a buffer that could
- be reallocated if needed. It means that gnat_envp needs to be updated
- before using gnat_envp to point to the right environment space */
-/* for the environ variable definition */
-#define gnat_envp (environ)
-#endif
+/* It used to be the case that users were required to forward the envp
+ parameter of main to the variable below when using a non-Ada main. The
+ consequences for failing to meet the requirement was improper operation of
+ Ada.Command_Line.Environment.
+
+ Today, users are not required to do anything with gnat_envp and
+ Ada.Command_Line.Environment does not use it anymore. In fact it's not used
+ by anything, but we keep its definition so that programs that obey the old
+ requirement keep linking. */
+char **gnat_envp = NULL;
int
__gnat_arg_count (void)
__gnat_env_count (void)
{
int i;
+ char **envp = __gnat_environ();
- for (i = 0; gnat_envp[i]; i++)
+ for (i = 0; envp[i]; i++)
;
return i;
}
int
__gnat_len_env (int env_num)
{
- if (gnat_envp != NULL)
- return strlen (gnat_envp[env_num]);
+ char **envp = __gnat_environ();
+
+ if (envp != NULL)
+ return strlen (envp[env_num]);
else
return 0;
}
void
__gnat_fill_env (char *a, int i)
{
- if (gnat_envp != NULL)
- memcpy (a, gnat_envp[i], strlen (gnat_envp[i]));
+ char **envp = __gnat_environ();
+
+ if (envp != NULL)
+ memcpy (a, envp[i], strlen (envp[i]));
}
#ifdef __cplusplus
-- Flag indicating whether the unit Ada.Command_Line is in the closure of
-- the partition. This is set by Resolve_Binder_Options, and is used to
-- determine whether or not to import and use symbols defined in
- -- Ada.Command_Line's support packages (gnat_argc, gnat_argv, gnat_envp
- -- and gnat_exit_status). Conservatively, it is always set to True for
+ -- Ada.Command_Line's support packages (gnat_argc, gnat_argv and
+ -- gnat_exit_status). Conservatively, it is always set to True for
-- non-configurable run-times as parts of the compiler and run-time assume
-- these symbols are available and can be imported directly.
if Command_Line_Args_On_Target then
Write_Statement_Buffer;
WBI (" (argc : Integer;");
- WBI (" argv : System.Address;");
- WBI (" envp : System.Address)");
+ WBI (" argv : System.Address)");
if Exit_Status_Supported_On_Target then
WBI (" return Integer");
WBI (" gnat_argc := argc;");
WBI (" gnat_argv := argv;");
WBI (" end if;");
- WBI (" gnat_envp := envp;");
WBI ("");
end if;
WBI ("");
WBI (" gnat_argc : Integer;");
WBI (" gnat_argv : System.Address;");
- WBI (" gnat_envp : System.Address;");
WBI ("");
WBI (" pragma Import (C, gnat_argc);");
WBI (" pragma Import (C, gnat_argv);");
- WBI (" pragma Import (C, gnat_envp);");
end if;
-- Define exit status if supported by the target. The exit status is
if Command_Line_Args_On_Target then
Write_Statement_Buffer;
WBI (" (argc : Integer;");
- WBI (" argv : System.Address;");
Set_String
- (" envp : System.Address)");
+ (" argv : System.Address)");
if Exit_Status_Supported_On_Target then
Write_Statement_Buffer;
* *
****************************************************************************/
+#ifdef __cplusplus
+extern "C" {
+#endif
+
extern void __gnat_getenv (char *name, int *len, char **value);
extern void __gnat_setenv (char *name, char *value);
extern char **__gnat_environ (void);
extern void __gnat_unsetenv (char *name);
extern void __gnat_clearenv(void);
+
+#ifdef __cplusplus
+}
+#endif
-- --
------------------------------------------------------------------------------
--- Note: Services offered by this package are guaranteed to be platform
--- independent as long as no call to GNAT.OS_Lib.Setenv or to C putenv
--- routine is done. On some platforms the services below will report new
--- environment variables (e.g. Windows) on some others it will not
--- (e.g. GNU/Linux and Solaris).
-
package Ada.Command_Line.Environment is
function Environment_Count return Natural;
-- main program, and the following is an example of a complete C main
-- program that stores the required information:
- -- main(int argc, char **argv, char **envp)
+ -- main(int argc, char **argv)
-- {
-- extern int gnat_argc;
-- extern char **gnat_argv;
- -- extern char **gnat_envp;
-- gnat_argc = argc;
-- gnat_argv = argv;
- -- gnat_envp = envp;
-- adainit();
-- adamain();
--
-- This has some specific effects as follows
--
- -- The binder generates the gnat_argc/argv/envp variables in the
- -- binder file instead of being imported from the run-time library.
- -- If Command_Line_Args_On_Target is set to False, then the
- -- generation of these variables is suppressed completely.
+ -- The binder generates the gnat_argc/argv variables in the binder file
+ -- instead of being imported from the run-time library. If
+ -- Command_Line_Args_On_Target is set to False, then the generation of
+ -- these variables is suppressed completely.
--
-- The routine __gnat_break_start is defined within the binder file
-- instead of being imported from the run-time library.