adaint.c (__gnat_get_libraries_from_registry): Call explicitly the ASCII version...
authorPascal Obry <obry@adacore.com>
Tue, 31 Oct 2006 17:47:20 +0000 (18:47 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Tue, 31 Oct 2006 17:47:20 +0000 (18:47 +0100)
2006-10-31  Pascal Obry  <obry@adacore.com>
    Eric Botcazou  <ebotcazou@adacore.com>
    Vincent Celier  <celier@adacore.com>

* adaint.c (__gnat_get_libraries_from_registry): Call explicitly the
ASCII version of the registry API. This is needed as the GNAT runtime
is now UNICODE by default.
Include version.h.
(get_gcc_version): Do not hardcode the return value.
(__gnat_file_time_name): On Windows properly set the default returned
value to -1 which corresponds to Invalid_Time.
(__gnat_fopen): New routine. A simple wrapper on all plateforms
 except on Windows where it does conversion for unicode support.
(__gnat_freopen): Idem.
(__gnat_locate_exec_on_path): If environment variable PATH does not
exist, return a NULL pointer

* adaint.h: (__gnat_fopen): Declare.
(__gnat_freopen): Likewise.

* mingw32.h (_tfreopen): Define this macro here for older MingW
version.
Activate the unicode support on platforms using a MingW runtime
version 3.9 or newer.

* s-crtl.ads (fopen): Is now an import to the wrapper __gnat_freopen.
This is needed for proper unicode support on Windows.
(freopen): Idem.

From-SVN: r118240

gcc/ada/adaint.c
gcc/ada/adaint.h
gcc/ada/mingw32.h
gcc/ada/s-crtl.ads

index 674df69..8705a93 100644 (file)
@@ -73,6 +73,7 @@
 #else
 #include "config.h"
 #include "system.h"
+#include "version.h"
 #endif
 
 #ifdef __MINGW32__
@@ -610,6 +611,37 @@ __gnat_get_debuggable_suffix_ptr (int *len, const char **value)
   return;
 }
 
+FILE *
+__gnat_fopen (char *path, char *mode)
+{
+#if defined (_WIN32) && ! defined (__vxworks) && ! defined (CROSS_COMPILE)
+  TCHAR wpath[GNAT_MAX_PATH_LEN];
+  TCHAR wmode[10];
+
+  S2WS (wpath, path, GNAT_MAX_PATH_LEN);
+  S2WS (wmode, mode, 10);
+  return _tfopen (wpath, wmode);
+#else
+  return fopen (path, mode);
+#endif
+}
+
+
+FILE *
+__gnat_freopen (char *path, char *mode, FILE *stream)
+{
+#if defined (_WIN32) && ! defined (__vxworks) && ! defined (CROSS_COMPILE)
+  TCHAR wpath[GNAT_MAX_PATH_LEN];
+  TCHAR wmode[10];
+
+  S2WS (wpath, path, GNAT_MAX_PATH_LEN);
+  S2WS (wmode, mode, 10);
+  return _tfreopen (wpath, wmode, stream);
+#else
+  return freopen (path, mode, stream);
+#endif
+}
+
 int
 __gnat_open_read (char *path, int fmode)
 {
@@ -1023,7 +1055,7 @@ __gnat_file_time_name (char *name)
   return (OS_Time)ret;
 
 #elif defined (_WIN32)
-  time_t ret = 0;
+  time_t ret = -1;
   TCHAR wname[GNAT_MAX_PATH_LEN];
 
   S2WS (wname, name, GNAT_MAX_PATH_LEN);
@@ -1398,8 +1430,8 @@ __gnat_get_libraries_from_registry (void)
   for (index = 0; res == ERROR_SUCCESS; index++)
     {
       value_size = name_size = 256;
-      res = RegEnumValue (reg_key, index, (TCHAR*)name, &name_size, 0,
-                          &type, (LPBYTE)value, &value_size);
+      res = RegEnumValueA (reg_key, index, (TCHAR*)name, &name_size, 0,
+                           &type, (LPBYTE)value, &value_size);
 
       if (res == ERROR_SUCCESS && type == REG_SZ)
         {
@@ -2123,6 +2155,7 @@ __gnat_locate_exec_on_path (char *exec_name)
 #else
   char *path_val = getenv ("PATH");
 #endif
+  if (path_val == NULL) return NULL;
   apath_val = alloca (strlen (path_val) + 1);
   strcpy (apath_val, path_val);
   return __gnat_locate_exec (exec_name, apath_val);
@@ -2675,11 +2708,15 @@ __gnat_lseek (int fd, long offset, int whence)
   return (int) lseek (fd, offset, whence);
 }
 
-/* This function returns the version of GCC being used.  Here it's GCC 3.  */
+/* This function returns the major version number of GCC being used.  */
 int
 get_gcc_version (void)
 {
-  return 3;
+#ifdef IN_RTS
+  return __GNUC__;
+#else
+  return (int) (version_string[0] - '0');
+#endif
 }
 
 int
index 9bcf058..3dbc9a4 100644 (file)
@@ -66,6 +66,8 @@ extern int    __gnat_open_new_temp               (char *, int);
 extern int    __gnat_mkdir                        (char *);
 extern int    __gnat_stat                         (char *,
                                                    struct stat *);
+extern FILE  *__gnat_fopen                        (char *, char *);
+extern FILE  *__gnat_freopen                      (char *, char *, FILE *);
 extern int    __gnat_open_read                     (char *, int);
 extern int    __gnat_open_rw                       (char *, int);
 extern int    __gnat_open_create                   (char *, int);
index 79d70d7..1f5a711 100644 (file)
  ****************************************************************************/
 
 /*  This file provides some macros used for the MINGW32 platform. The main
-    goal is to be able to build GNAT with a standard MINGW32 C header set */
+    goal is to be able to build GNAT with a standard MINGW32 C header
+    set. This files contains also the circuitry for the unicode support.   */
 
 #ifndef _MINGW32_H
 #define _MINGW32_H
 
+/* The unicode support is activated by default starting with the 3.9 MingW
+   version. It is not possible to use it with previous version due to a bug
+   in the MingW runtime.  */
 
+#if ((__MINGW32_MAJOR_VERSION == 3 \
+                  && __MINGW32_MINOR_VERSION >= 9) \
+     || (__MINGW32_MAJOR_VERSION >= 4))
+#define GNAT_UNICODE_SUPPORT
 
-/* Uncomment to activate the GNAT Unicode support. */
-/*#define GNAT_UNICODE_SUPPORT */
+#else
+
+/*  Older MingW versions have no defintion for _tfreopen, add it here to have a
+    proper build without unicode support.  */
+#ifndef _tfreopen
+#define _tfreopen   freopen
+#endif
+
+#endif
 
 #ifdef GNAT_UNICODE_SUPPORT
 #define _UNICODE /* For C runtime */
@@ -50,7 +65,7 @@
 
 /* After including this file it is possible to use the character t as prefix
    to routines. If GNAT_UNICODE_SUPPORT is defined then the unicode enabled
-   versions will be used. */
+   versions will be used.  */
 
 /* Copy to/from wide-string, if GNAT_UNICODE_SUPPORT activated this will do
    the proper translations using the UTF-8 encoding.  */
@@ -71,7 +86,7 @@
    version instead of the previous enhanced version to ease building GNAT on
    Windows platforms. By using STD_MINGW or OLD_MINGW it is possible to build
    GNAT using both MingW include files (Old MingW + ACT changes and standard
-   MingW starting with version 1.3. */
+   MingW starting with version 1.3.  */
 #define STD_MINGW ((__MINGW32_MAJOR_VERSION == 1 \
                   && __MINGW32_MINOR_VERSION >= 3) \
      || (__MINGW32_MAJOR_VERSION >= 2))
index 7ce99bc..5397776 100644 (file)
@@ -85,7 +85,7 @@ package System.CRTL is
    pragma Import (C, fgets, "fgets");
 
    function fopen (filename : chars; Mode : chars) return FILEs;
-   pragma Import (C, fopen, "fopen");
+   pragma Import (C, fopen, "__gnat_fopen");
 
    function fputc (C : int; stream : FILEs) return int;
    pragma Import (C, fputc, "fputc");
@@ -101,7 +101,7 @@ package System.CRTL is
       mode     : chars;
       stream   : FILEs)
       return     FILEs;
-   pragma Import (C, freopen, "freopen");
+   pragma Import (C, freopen, "__gnat_freopen");
 
    function fseek
      (stream : FILEs;