From: Patrick Bernardi Date: Thu, 30 Jul 2020 23:06:13 +0000 (-0400) Subject: [Ada] Use VxWorks 7 APIs for accessing environment variables in kernel mode X-Git-Tag: upstream/12.2.0~12800 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=603b57c732314e57fcc4257603fd3b482b097ac7;p=platform%2Fupstream%2Fgcc.git [Ada] Use VxWorks 7 APIs for accessing environment variables in kernel mode gcc/ada/ * env.c (__gnat_setenv): call setenv for VxWorks 7 kernel mode. (__gnat_environ): envGet takes an int instead of a NULL pointer. (__gnat_unsetenv): call unsetenv for VxWorks 7 kernel mode. (__gnat_clearenv): use __gnat_unsetenv to clear environment variables. --- diff --git a/gcc/ada/env.c b/gcc/ada/env.c index 287260d..0ee09f4 100644 --- a/gcc/ada/env.c +++ b/gcc/ada/env.c @@ -99,7 +99,8 @@ __gnat_getenv (char *name, int *len, char **value) void __gnat_setenv (char *name, char *value) { -#if (defined (__vxworks) && defined (__RTP__)) || defined (__APPLE__) +#if (defined (__vxworks) && (defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7)) \ + || defined (__APPLE__) setenv (name, value, 1); #else @@ -110,9 +111,9 @@ __gnat_setenv (char *name, char *value) sprintf (expression, "%s=%s", name, value); putenv (expression); -#if defined (__MINGW32__) || (defined (__vxworks) && ! defined (__RTP__)) - /* On some systems like MacOS X and Windows, putenv is making a copy of the - expression string so we can free it after the call to putenv */ +#if defined (__MINGW32__) || defined (__vxworks) + /* putenv for Windows and VxWorks 6 kernel modules makes a copy of the + expression string, so we need to free it after the call to putenv. */ free (expression); #endif #endif @@ -138,8 +139,13 @@ __gnat_environ (void) #if defined (__RTP__) || defined (VTHREADS) return environ; #else - /* Kernel mode */ - return envGet (NULL); + /* For VxWorks kernel modules use envGet to get the task's environment + (either the task's private environment if it has one or the global + environment otherwise). taskId parameter of 0 refers to the current + task (the VxWorks documentation says to use NULL but the compiler + complains that taskId is an int rather than a pointer. Internally, + VxWorks uses 0 as well). */ + return envGet (0); #endif #endif } @@ -147,7 +153,8 @@ __gnat_environ (void) void __gnat_unsetenv (char *name) { #if defined (__hpux__) || defined (__sun__) \ - || (defined (__vxworks) && ! defined (__RTP__)) \ + || (defined (__vxworks) && ! defined (__RTP__) \ + && _WRS_VXWORKS_MAJOR <= 6) \ || defined (_AIX) || defined (__Lynx__) /* On Solaris and HP-UX there is no function to clear an environment @@ -170,7 +177,7 @@ void __gnat_unsetenv (char *name) if (strlen (env[index]) > size) { if (strstr (env[index], name) == env[index] && env[index][size] == '=') { -#if defined (__vxworks) && ! defined (__RTP__) +#if defined (__vxworks) /* on Vxworks we are sure that the string has been allocated using malloc */ free (env[index]); @@ -203,9 +210,10 @@ void __gnat_unsetenv (char *name) void __gnat_clearenv (void) { #if defined (__sun__) \ - || (defined (__vxworks) && ! defined (__RTP__)) || defined (__Lynx__) \ + || (defined (__vxworks) && !defined (__RTP__) && _WRS_VXWORKS_MAJOR <= 6) \ + || defined (__Lynx__) \ || defined (__PikeOS__) - /* On Solaris, VxWorks (not RTPs), and Lynx there is no system + /* On Solaris, VxWorks kernel pre 7, and Lynx there is no system call to unset a variable or to clear the environment so set all the entries in the environ table to NULL (see comment in __gnat_unsetenv for more explanation). */ @@ -217,7 +225,8 @@ void __gnat_clearenv (void) index++; } #elif defined (__MINGW32__) || defined (__FreeBSD__) || defined (__APPLE__) \ - || (defined (__vxworks) && defined (__RTP__)) || defined (__CYGWIN__) \ + || (defined (__vxworks) && defined (__RTP__) || _WRS_VXWORKS_MAJOR >= 7) \ + || defined (__CYGWIN__) \ || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__rtems__) \ || defined (__DragonFly__) || defined (__DJGPP__) /* On Windows, FreeBSD and MacOS there is no function to clean all the