]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix light runtime configurations
authorRonan Desplanques <desplanques@adacore.com>
Wed, 25 Mar 2026 13:39:35 +0000 (14:39 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Fri, 29 May 2026 08:49:50 +0000 (10:49 +0200)
A recent changed added a dependency from the environment-related
functions in argv.c to env.c. This broke some runtime configurations that
provide command line support but no environment variable support.

This fixes the issue by moving all of argv.c's environment-related code
to env.c. It also tweaks a comment in passing.

gcc/ada/ChangeLog:

* argv.c (__gnat_env_count) (__gnat_len_env) (__gnat_fill_env): Move
to...
* env.c (__gnat_env_count) (__gnat_len_env) (__gnat_fill_env):
...here. Tweak comment.

gcc/ada/argv.c
gcc/ada/env.c

index 6d670e1aa5dd62f8eeadc156109b262cd80e96c1..8eb7de4f2f84a7f81d15b50c8e230d60d88e06c5 100644 (file)
@@ -61,17 +61,6 @@ extern "C" {
 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_arg_count (void)
 {
@@ -94,37 +83,6 @@ __gnat_fill_arg (char *a, int i)
     memcpy (a, gnat_argv[i], strlen (gnat_argv[i]));
 }
 
-int
-__gnat_env_count (void)
-{
-  int i;
-  char **envp = __gnat_environ();
-
-  for (i = 0; envp[i]; i++)
-    ;
-  return i;
-}
-
-int
-__gnat_len_env (int 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)
-{
-  char **envp = __gnat_environ();
-
-  if (envp != NULL)
-    memcpy (a, envp[i], strlen (envp[i]));
-}
-
 #ifdef __cplusplus
 }
 #endif
index c4d9424c65ef6826e15490c83c71d22b5a072a78..2931220f069b431803e89f92124fb5d94ad08cff 100644 (file)
@@ -256,6 +256,48 @@ void __gnat_clearenv (void)
 #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.
+
+   Nowadays, 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_env_count (void)
+{
+  int i;
+  char **envp = __gnat_environ();
+
+  for (i = 0; envp[i]; i++)
+    ;
+  return i;
+}
+
+int
+__gnat_len_env (int 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)
+{
+  char **envp = __gnat_environ();
+
+  if (envp != NULL)
+    memcpy (a, envp[i], strlen (envp[i]));
+}
+
 #ifdef __cplusplus
 }
 #endif