OSDN Git Service

* gcc.dg/attr-weakref-1.c: Add exit (0) to avoid spurious
[pf3gnuchains/gcc-fork.git] / gcc / ada / cstreams.c
index 7dd5557..8f283d4 100644 (file)
@@ -6,9 +6,7 @@
  *                                                                          *
  *              Auxiliary C functions for Interfaces.C.Streams              *
  *                                                                          *
- *                              $Revision: 1.1 $
- *                                                                          *
- *          Copyright (C) 1992-2001 Free Software Foundation, Inc.          *
+ *          Copyright (C) 1992-2003 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- *
@@ -18,8 +16,8 @@
  * 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,  59 Temple Place - Suite 330,  Boston, *
- * MA 02111-1307, USA.                                                      *
+ * 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 *
@@ -28,7 +26,7 @@
  * file might be covered by the  GNU Public License.                        *
  *                                                                          *
  * GNAT was originally developed  by the GNAT team at  New York University. *
- * It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). *
+ * Extensive contributions were provided by Ada Core Technologies Inc.      *
  *                                                                          *
  ****************************************************************************/
 
 
 #include "adaint.h"
 
-#ifdef __EMX__
-int max_path_len = _MAX_PATH;
-#elif defined (VMS)
+#ifdef VMS
 #include <unixlib.h>
-int max_path_len = 255; /* PATH_MAX */
-
-#elif defined (__vxworks) || defined (__OPENNT)
-
-int max_path_len = PATH_MAX;
-
-#else
+#endif
 
 #ifdef linux
-
-/* Don't use macros on linux since they cause incompatible changes between
+/* Don't use macros on GNU/Linux since they cause incompatible changes between
    glibc 2.0 and 2.1 */
 
 #ifdef stderr
@@ -78,42 +67,34 @@ int max_path_len = PATH_MAX;
 
 #endif
 
-#include <sys/param.h>
-
-int max_path_len = MAXPATHLEN;
-#endif
-
-/* The _IONBF value in CYGNUS or MINGW32 stdio.h is wrong.  */
+/* The _IONBF value in MINGW32 stdio.h is wrong.  */
 #if defined (WINNT) || defined (_WINNT)
+#if OLD_MINGW
 #undef _IONBF
 #define _IONBF 0004
 #endif
-
+#endif
 
 int
-__gnat_feof (stream)
-     FILE *stream;
+__gnat_feof (FILE *stream)
 {
   return (feof (stream));
 }
 
 int
-__gnat_ferror (stream)
-     FILE *stream;
+__gnat_ferror (FILE *stream)
 {
    return (ferror (stream));
 }
 
 int
-__gnat_fileno (stream)
-     FILE *stream;
+__gnat_fileno (FILE *stream)
 {
    return (fileno (stream));
 }
 
 int
-__gnat_is_regular_file_fd (fd)
-     int fd;
+__gnat_is_regular_file_fd (int fd)
 {
   int ret;
   struct stat statbuf;
@@ -155,38 +136,36 @@ int    __gnat_constant_seek_end = SEEK_END;
 int    __gnat_constant_seek_set = SEEK_SET;
 
 FILE *
-__gnat_constant_stderr ()
+__gnat_constant_stderr (void)
 {
   return stderr;
 }
 
 FILE *
-__gnat_constant_stdin ()
+__gnat_constant_stdin (void)
 {
   return stdin;
 }
 
 FILE *
-__gnat_constant_stdout ()
+__gnat_constant_stdout (void)
 {
   return stdout;
 }
 
 char *
-__gnat_full_name (nam, buffer)
-     char *nam;
-     char *buffer;
+__gnat_full_name (char *nam, char *buffer)
 {
-  char *p;
-
 #if defined(__EMX__) || defined (__MINGW32__)
   /* If this is a device file return it as is; under Windows NT and
      OS/2 a device file end with ":".  */
-  if (nam [strlen (nam) - 1] == ':')
+  if (nam[strlen (nam) - 1] == ':')
     strcpy (buffer, nam);
   else
     {
-      _fullpath (buffer, nam, max_path_len);
+      char *p;
+
+      _fullpath (buffer, nam, __gnat_max_path_len);
 
       for (p = buffer; *p; p++)
        if (*p == '/')
@@ -196,36 +175,36 @@ __gnat_full_name (nam, buffer)
 #elif defined (MSDOS)
   _fixpath (nam, buffer);
 
-#elif defined (sgi)
+#elif defined (sgi) || defined (__FreeBSD__)
 
-  /* Use realpath function which resolves links and references to .. and ..
-     on those Unix systems that support it. Note that linux provides it but
+  /* Use realpath function which resolves links and references to . and ..
+     on those Unix systems that support it. Note that GNU/Linux provides it but
      cannot handle more than 5 symbolic links in a full name, so we use the
      getcwd approach instead. */
   realpath (nam, buffer);
 
 #elif defined (VMS)
-  strcpy (buffer, __gnat_to_canonical_file_spec (nam));
+  strncpy (buffer, __gnat_to_canonical_file_spec (nam), __gnat_max_path_len);
 
-  if (buffer[0] == '/')
-    strcpy (buffer, __gnat_to_host_file_spec (buffer));
+  if (buffer[0] == '/' || strchr (buffer, '!'))  /* '!' means decnet node */
+    strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
   else
     {
-      char nambuffer [MAXPATHLEN];
-
-      strcpy (nambuffer, buffer);
-      strcpy (buffer, getcwd (buffer, max_path_len, 0));
-      strcat (buffer, "/");
-      strcat (buffer, nambuffer);
-      strcpy (buffer, __gnat_to_host_file_spec (buffer));
+      char *nambuffer = alloca (__gnat_max_path_len);
+
+      strncpy (nambuffer, buffer, __gnat_max_path_len);
+      strncpy
+       (buffer, getcwd (buffer, __gnat_max_path_len, 0), __gnat_max_path_len);
+      strncat (buffer, "/", __gnat_max_path_len);
+      strncat (buffer, nambuffer, __gnat_max_path_len);
+      strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
     }
 
-  return buffer;
-
 #else
   if (nam[0] != '/')
     {
-      p = getcwd (buffer, max_path_len);
+      char *p = getcwd (buffer, __gnat_max_path_len);
+
       if (p == 0)
        {
          buffer[0] = '\0';
@@ -241,7 +220,7 @@ __gnat_full_name (nam, buffer)
     }
   else
     strcpy (buffer, nam);
+#endif
 
   return buffer;
-#endif
 }