2006-10-31 Robert Dewar <dewar@adacore.com> Thomas Quinot <quinot@adacore.com> Arnaud Charlet <charlet@adacore.com> * fmap.adb: Put routines in alpha order * g-boumai.ads: Remove redundant 'in' keywords * g-cgi.adb: Minor reformatting * g-cgi.ads: Remove redundant 'in' keywords * get_targ.adb: Put routines in alpha order * prj-attr.ads: Minor reformatting * s-atacco.ads: Minor reformatting * scn.adb: Put routines in alpha order * sinput-l.adb: Minor comment fix * sinput-p.adb: Minor comment fix * s-maccod.ads: Minor reformatting * s-memory.adb: Minor reformatting * s-htable.adb: Fix typo in comment. * s-secsta.adb: Minor comment update. * s-soflin.adb: Minor reformatting * s-stoele.ads: Add comment about odd qualification in Storage_Offset declaration * s-strxdr.adb: Remove unnecessary 'in' keywords for formal parameters. * treeprs.adt: Minor reformatting * urealp.adb: Put routines in alpha order * s-wchcon.ads, s-wchcon.adb (Get_WC_Encoding_Method): New version taking string. * s-asthan-vms-alpha.adb: Remove redundant 'in' keywords * g-trasym-vms-ia64.adb: Remove redundant 'in' keywords * env.c (__gnat_unsetenv): Unsetenv is unavailable on LynxOS, so workaround as on other platforms. * g-eacodu-vms.adb: Remove redundant 'in' keywords * g-expect-vms.adb: Remove redundant 'in' keywords * gnatdll.adb (Add_Files_From_List): Handle Name_Error and report a clear error message if the list-of-files file cannot be opened. * g-thread.adb (Unregister_Thread_Id): Add use type Thread_Id so the equality operator is always visible. * lang.opt: Woverlength-strings: New option. * nmake.adt: Update copyright, since nmake.ads and nmake.adb have changed. * osint-b.ads, osint-b.adb (Time_From_Last_Bind): removed function . (Binder_Output_Time_Stamps_Set): removed. (Old_Binder_Output_Time_Stamp): idem. (New_Binder_Output_Time_Stamp): idem. (Recording_Time_From_Last_Bind): idem. (Recording_Time_From_Last_Bind): Make constant. * output.ads, output.adb (Write_Str): Allow LF characters (Write_Spaces): New procedure * prepcomp.adb (Preproc_Data_Table): Change Increment from 5% to 100% * inline.adb: Minor reformatting * s-asthan-vms-alpha.adb: Remove redundant 'in' keywords * s-mastop-vms.adb: Remove redundant 'in' keywords * s-osprim-vms.adb: Remove redundant 'in' keywords * s-trafor-default.adb: Remove redundant 'in' keywords * 9drpc.adb: Remove redundant 'in' keywords * s-osinte-mingw.ads: Minor reformatting * s-inmaop-posix.adb: Minor reformatting * a-direio.ads: Remove quotes from Compile_Time_Warning message * a-exexda.adb: Minor code reorganization * a-filico.adb: Minor reformatting * a-finali.adb: Minor reformatting * a-nudira.ads: Remove quote from Compile_Time_Warning message * a-numeri.ads: Minor reformatting * a-sequio.ads: Remove quotes from Compile_Time_Warning message * exp_pakd.ads: Fix obsolete comment * a-ztenau.adb, a-ztenio.adb, a-wtenau.adb, a-tienau.adb, a-wtenio.adb (Put): Avoid assuming low bound of string is 1. Probably not a bug, but certainly neater and more efficient. * a-tienio.adb: Minor reformatting * comperr.adb (Compiler_Abort): Call Cancel_Special_Output at start Avoid assuming low bound of string is 1. * gnatbind.adb: Change Bindusg to package and rename procedure as Display, which now ensures that it only outputs usage information once. (Scan_Bind_Arg): Avoid assuming low bound of string is 1. * g-pehage.adb (Build_Identical_Keysets): Replace use of 1 by Table'First. * g-regpat.adb (Insert_Operator): Add pragma Warnings (Off) to kill warning. (Match): Add pragma Assert to ensure that Matches'First is zero * g-regpat.ads (Match): Document that Matches lower bound must be zero * makeutl.adb (Is_External_Assignment): Add pragma Assert's to check documented preconditions (also kills warnings about bad indexes). * mdll.adb (Build_Dynamic_Library): Avoid assumption that Afiles'First is 1. (Build_Import_Library): Ditto; * mdll-utl.adb: (Gnatbind): Avoid assumption that Alis'First = 1 * rtsfind.adb (RTE_Error_Msg): Avoid assuming low bound of string is 1. * sem_case.adb (Analyze_Choices): Add pragma Assert to check that lower bound of choice table is 1. * sem_case.ads (Analyze_Choices): Document that lower bound of Choice_Table is 1. * s-imgdec.adb (Set_Decimal_Digits): Avoid assuming low bound of string is 1. * uintp.adb (Init_Operand): Document that low bound of Vec is always 1, and add appropriate Assert pragma to suppress warnings. * atree.h, atree.ads, atree.adb Change Elist24 to Elist25 Add definitions of Field28 and Node28 (Traverse_Field): Use new syntactic parent table in sinfo. * cstand.adb: Change name Is_Ada_2005 to Is_Ada_2005_Only * itypes.adb: Change name Is_Ada_2005 to Is_Ada_2005_Only * exp_tss.adb: Put routines in alpha order * fe.h: Remove redundant declarations. From-SVN: r118330
315 lines
9.5 KiB
C
315 lines
9.5 KiB
C
/****************************************************************************
|
|
* *
|
|
* GNAT COMPILER COMPONENTS *
|
|
* *
|
|
* E N V *
|
|
* *
|
|
* C Implementation File *
|
|
* *
|
|
* Copyright (C) 2005-2006, Free Software Foundation, Inc. *
|
|
* *
|
|
* GNAT is free software; you can redistribute it and/or modify it under *
|
|
* terms of the GNU General Public License as published by the Free Soft- *
|
|
* ware Foundation; either version 2, or (at your option) any later ver- *
|
|
* sion. GNAT is distributed in the hope that it will be useful, but WITH- *
|
|
* OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
|
|
* for more details. You should have received a copy of the GNU General *
|
|
* Public License distributed with GNAT; see file COPYING. If not, write *
|
|
* to the Free Software Foundation, 51 Franklin Street, Fifth Floor, *
|
|
* Boston, MA 02110-1301, USA. *
|
|
* *
|
|
* As a special exception, if you link this file with other files to *
|
|
* produce an executable, this file does not by itself cause the resulting *
|
|
* executable to be covered by the GNU General Public License. This except- *
|
|
* ion does not however invalidate any other reasons why the executable *
|
|
* file might be covered by the GNU Public License. *
|
|
* *
|
|
* GNAT was originally developed by the GNAT team at New York University. *
|
|
* Extensive contributions were provided by Ada Core Technologies Inc. *
|
|
* *
|
|
****************************************************************************/
|
|
|
|
#ifdef IN_RTS
|
|
#include "tconfig.h"
|
|
#include "tsystem.h"
|
|
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <time.h>
|
|
#ifdef VMS
|
|
#include <unixio.h>
|
|
#endif
|
|
|
|
#if defined (__APPLE__)
|
|
#include <crt_externs.h>
|
|
#endif
|
|
|
|
#if defined (__MINGW32__)
|
|
#include <stdlib.h>
|
|
#endif
|
|
|
|
#if defined (__vxworks) && ! (defined (__RTP__) || defined (__COREOS__))
|
|
#include "envLib.h"
|
|
extern char** ppGlobalEnviron;
|
|
#endif
|
|
|
|
/* We don't have libiberty, so use malloc. */
|
|
#define xmalloc(S) malloc (S)
|
|
#else /* IN_RTS */
|
|
#include "config.h"
|
|
#include "system.h"
|
|
#endif /* IN_RTS */
|
|
|
|
#include "env.h"
|
|
|
|
void
|
|
__gnat_getenv (char *name, int *len, char **value)
|
|
{
|
|
*value = getenv (name);
|
|
if (!*value)
|
|
*len = 0;
|
|
else
|
|
*len = strlen (*value);
|
|
|
|
return;
|
|
}
|
|
|
|
/* VMS specific declarations for set_env_value. */
|
|
|
|
#ifdef VMS
|
|
|
|
static char *to_host_path_spec (char *);
|
|
|
|
struct descriptor_s
|
|
{
|
|
unsigned short len, mbz;
|
|
__char_ptr32 adr;
|
|
};
|
|
|
|
typedef struct _ile3
|
|
{
|
|
unsigned short len, code;
|
|
__char_ptr32 adr;
|
|
unsigned short *retlen_adr;
|
|
} ile_s;
|
|
|
|
#endif
|
|
|
|
void
|
|
__gnat_setenv (char *name, char *value)
|
|
{
|
|
#ifdef MSDOS
|
|
|
|
#elif defined (VMS)
|
|
struct descriptor_s name_desc;
|
|
/* Put in JOB table for now, so that the project stuff at least works. */
|
|
struct descriptor_s table_desc = {7, 0, "LNM$JOB"};
|
|
char *host_pathspec = value;
|
|
char *copy_pathspec;
|
|
int num_dirs_in_pathspec = 1;
|
|
char *ptr;
|
|
long status;
|
|
|
|
name_desc.len = strlen (name);
|
|
name_desc.mbz = 0;
|
|
name_desc.adr = name;
|
|
|
|
if (*host_pathspec == 0)
|
|
/* deassign */
|
|
{
|
|
status = LIB$DELETE_LOGICAL (&name_desc, &table_desc);
|
|
/* no need to check status; if the logical name is not
|
|
defined, that's fine. */
|
|
return;
|
|
}
|
|
|
|
ptr = host_pathspec;
|
|
while (*ptr++)
|
|
if (*ptr == ',')
|
|
num_dirs_in_pathspec++;
|
|
|
|
{
|
|
int i, status;
|
|
ile_s *ile_array = alloca (sizeof (ile_s) * (num_dirs_in_pathspec + 1));
|
|
char *copy_pathspec = alloca (strlen (host_pathspec) + 1);
|
|
char *curr, *next;
|
|
|
|
strcpy (copy_pathspec, host_pathspec);
|
|
curr = copy_pathspec;
|
|
for (i = 0; i < num_dirs_in_pathspec; i++)
|
|
{
|
|
next = strchr (curr, ',');
|
|
if (next == 0)
|
|
next = strchr (curr, 0);
|
|
|
|
*next = 0;
|
|
ile_array[i].len = strlen (curr);
|
|
|
|
/* Code 2 from lnmdef.h means it's a string. */
|
|
ile_array[i].code = 2;
|
|
ile_array[i].adr = curr;
|
|
|
|
/* retlen_adr is ignored. */
|
|
ile_array[i].retlen_adr = 0;
|
|
curr = next + 1;
|
|
}
|
|
|
|
/* Terminating item must be zero. */
|
|
ile_array[i].len = 0;
|
|
ile_array[i].code = 0;
|
|
ile_array[i].adr = 0;
|
|
ile_array[i].retlen_adr = 0;
|
|
|
|
status = LIB$SET_LOGICAL (&name_desc, 0, &table_desc, 0, ile_array);
|
|
if ((status & 1) != 1)
|
|
LIB$SIGNAL (status);
|
|
}
|
|
|
|
#elif defined (__vxworks) && defined (__RTP__)
|
|
setenv (name, value, 1);
|
|
|
|
#else
|
|
size_t size = strlen (name) + strlen (value) + 2;
|
|
char *expression;
|
|
|
|
expression = (char *) xmalloc (size * sizeof (char));
|
|
|
|
sprintf (expression, "%s=%s", name, value);
|
|
putenv (expression);
|
|
#if defined (__FreeBSD__) || defined (__APPLE__) || defined (__MINGW32__) \
|
|
||(defined (__vxworks) && ! defined (__RTP__))
|
|
/* On some systems like FreeBSD, MacOS X and Windows, putenv is making
|
|
a copy of the expression string so we can free it after the call to
|
|
putenv */
|
|
free (expression);
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
char **
|
|
__gnat_environ (void)
|
|
{
|
|
#if defined (VMS)
|
|
/* Not implemented */
|
|
return NULL;
|
|
#elif defined (__APPLE__)
|
|
char ***result = _NSGetEnviron ();
|
|
return *result;
|
|
#elif defined (__MINGW32__)
|
|
return _environ;
|
|
#elif defined (sun)
|
|
extern char **_environ;
|
|
return _environ;
|
|
#else
|
|
#if ! (defined (__vxworks) && ! (defined (__RTP__) || defined (__COREOS__)))
|
|
/* in VxWorks kernel mode environ is macro and not a variable */
|
|
/* same thing on 653 in the CoreOS */
|
|
extern char **environ;
|
|
#endif
|
|
return environ;
|
|
#endif
|
|
}
|
|
|
|
void __gnat_unsetenv (char *name) {
|
|
#if defined (VMS)
|
|
/* Not implemented */
|
|
return;
|
|
#elif defined (__hpux__) || defined (sun) \
|
|
|| (defined (__mips) && defined (__sgi)) \
|
|
|| (defined (__vxworks) && ! defined (__RTP__)) \
|
|
|| defined (_AIX) || defined (__Lynx__)
|
|
|
|
/* On Solaris, HP-UX and IRIX there is no function to clear an environment
|
|
variable. So we look for the variable in the environ table and delete it
|
|
by setting the entry to NULL. This can clearly cause some memory leaks
|
|
but free cannot be used on this context as not all strings in the environ
|
|
have been allocated using malloc. To avoid this memory leak another
|
|
method can be used. It consists in forcing the reallocation of all the
|
|
strings in the environ table using malloc on the first call on the
|
|
functions related to environment variable management. The disadvantage
|
|
is that if a program makes a direct call to getenv the return string
|
|
may be deallocated at some point. */
|
|
/* Note that on AIX, unsetenv is not supported on 5.1 but it is on 5.3.
|
|
As we are still supporting AIX 5.1 we cannot use unsetenv */
|
|
char **env = __gnat_environ ();
|
|
int index = 0;
|
|
size_t size = strlen (name);
|
|
|
|
while (env[index] != NULL) {
|
|
if (strlen (env[index]) > size) {
|
|
if (strstr (env[index], name) == env[index] &&
|
|
env[index][size] == '=') {
|
|
#if defined (__vxworks) && ! defined (__RTP__)
|
|
/* on Vxworks we are sure that the string has been allocated using
|
|
malloc */
|
|
free (env[index]);
|
|
#endif
|
|
while (env[index] != NULL) {
|
|
env[index]=env[index + 1];
|
|
index++;
|
|
}
|
|
} else
|
|
index++;
|
|
} else
|
|
index++;
|
|
}
|
|
#elif defined (__MINGW32__)
|
|
/* On Windows platform putenv ("key=") is equivalent to unsetenv (a
|
|
subsequent call to getenv ("key") will return NULL and not the "\0"
|
|
string */
|
|
size_t size = strlen (name) + 2;
|
|
char *expression;
|
|
expression = (char *) xmalloc (size * sizeof (char));
|
|
|
|
sprintf (expression, "%s=", name);
|
|
putenv (expression);
|
|
free (expression);
|
|
#else
|
|
unsetenv (name);
|
|
#endif
|
|
}
|
|
|
|
void __gnat_clearenv (void) {
|
|
#if defined (VMS)
|
|
/* not implemented */
|
|
return;
|
|
#elif defined (sun) || (defined (__mips) && defined (__sgi)) \
|
|
|| (defined (__vxworks) && ! defined (__RTP__)) || defined (__Lynx__)
|
|
/* On Solaris, IRIX, VxWorks (not RTPs), 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). */
|
|
char **env = __gnat_environ ();
|
|
int index = 0;
|
|
|
|
while (env[index] != NULL) {
|
|
env[index]=NULL;
|
|
index++;
|
|
}
|
|
#elif defined (__MINGW32__) || defined (__FreeBSD__) || defined (__APPLE__) \
|
|
|| (defined (__vxworks) && defined (__RTP__)) || defined (__CYGWIN__)
|
|
/* On Windows, FreeBSD and MacOS there is no function to clean all the
|
|
environment but there is a "clean" way to unset a variable. So go
|
|
through the environ table and call __gnat_unsetenv on all entries */
|
|
char **env = __gnat_environ ();
|
|
size_t size;
|
|
|
|
while (env[0] != NULL) {
|
|
size = 0;
|
|
while (env[0][size] != '=')
|
|
size++;
|
|
/* create a string that contains "name" */
|
|
size++;
|
|
{
|
|
char expression[size];
|
|
strncpy (expression, env[0], size);
|
|
expression[size - 1] = 0;
|
|
__gnat_unsetenv (expression);
|
|
}
|
|
}
|
|
#else
|
|
clearenv ();
|
|
#endif
|
|
}
|