Add org.gnu.gdb.i386.avx.
[deliverable/binutils-gdb.git] / sim / common / callback.c
index 6e789a2674ed7e6fabc96cb969ef2671a1cb2a18..d034bca451214a8ed6bef98bf4e8afa0baa78884 100644 (file)
@@ -1,5 +1,5 @@
 /* Remote target callback routines.
-   Copyright 1995, 1996, 1997, 2000, 2002, 2003, 2004
+   Copyright 1995, 1996, 1997, 2000, 2002, 2003, 2004, 2007, 2008, 2009, 2010
    Free Software Foundation, Inc.
    Contributed by Cygnus Solutions.
 
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with GAS; see the file COPYING.  If not, write to the Free Software
-   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* This file provides a standard way for targets to talk to the host OS
    level.  */
 #include "cconfig.h"
 #endif
 #include "ansidecl.h"
-#ifdef ANSI_PROTOTYPES
 #include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
 #include <stdio.h>
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #include <unistd.h>
 #endif
 
+#ifndef PIPE_BUF
+#define PIPE_BUF 512
+#endif
+
 /* ??? sim_cb_printf should be cb_printf, but until the callback support is
    broken out of the simulator directory, these are here to not require
    sim-utils.h.  */
@@ -92,7 +91,11 @@ static int os_get_errno PARAMS ((host_callback *));
 static int os_close PARAMS ((host_callback *, int));
 static void os_vprintf_filtered PARAMS ((host_callback *, const char *, va_list));
 static void os_evprintf_filtered PARAMS ((host_callback *, const char *, va_list));
-static void os_error PARAMS ((host_callback *, const char *, ...));
+static void os_error PARAMS ((host_callback *, const char *, ...))
+#ifdef __GNUC__
+  __attribute__ ((__noreturn__))
+#endif
+  ;
 static int fdmap PARAMS ((host_callback *, int));
 static int fdbad PARAMS ((host_callback *, int));
 static int wrap PARAMS ((host_callback *, int));
@@ -534,7 +537,9 @@ os_fstat (p, fd, buf)
 
   if (p->ispipe[fd])
     {
+#if defined (HAVE_STRUCT_STAT_ST_ATIME) || defined (HAVE_STRUCT_STAT_ST_CTIME) || defined (HAVE_STRUCT_STAT_ST_MTIME)
       time_t t = (*p->time) (p, NULL);
+#endif
 
       /* We have to fake the struct stat contents, since the pipe is
         made up in the simulator.  */
@@ -575,7 +580,11 @@ os_lstat (p, file, buf)
      struct stat *buf;
 {
   /* NOTE: hpn/2004-12-12: Same issue here as with os_fstat.  */
+#ifdef HAVE_LSTAT
   return wrap (p, lstat (file, buf));
+#else
+  return wrap (p, stat (file, buf));
+#endif
 }
 
 static int 
@@ -594,7 +603,12 @@ os_ftruncate (p, fd, len)
     }
   if (result)
     return result;
+#ifdef HAVE_FTRUNCATE
   result = wrap (p, ftruncate (fdmap (p, fd), len));
+#else
+  p->last_errno = EINVAL;
+  result = -1;
+#endif
   return result;
 }
 
@@ -604,7 +618,12 @@ os_truncate (p, file, len)
      const char *file;
      long len;
 {
+#ifdef HAVE_TRUNCATE
   return wrap (p, truncate (file, len));
+#else
+  p->last_errno = EINVAL;
+  return -1;
+#endif
 }
 
 static int
@@ -735,23 +754,10 @@ os_init (p)
 
 /* VARARGS */
 static void
-#ifdef ANSI_PROTOTYPES
 os_printf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
-#else
-os_printf_filtered (p, va_alist)
-     host_callback *p;
-     va_dcl
-#endif
 {
   va_list args;
-#ifdef ANSI_PROTOTYPES
   va_start (args, format);
-#else
-  char *format;
-
-  va_start (args);
-  format = va_arg (args, char *);
-#endif
 
   vfprintf (stdout, format, args);
   va_end (args);
@@ -759,51 +765,24 @@ os_printf_filtered (p, va_alist)
 
 /* VARARGS */
 static void
-#ifdef ANSI_PROTOTYPES
 os_vprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
-#else
-os_vprintf_filtered (p, format, args)
-     host_callback *p;
-     const char *format;
-     va_list args;
-#endif
 {
   vprintf (format, args);
 }
 
 /* VARARGS */
 static void
-#ifdef ANSI_PROTOTYPES
 os_evprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
-#else
-os_evprintf_filtered (p, format, args)
-     host_callback *p;
-     const char *format;
-     va_list args;
-#endif
 {
   vfprintf (stderr, format, args);
 }
 
 /* VARARGS */
 static void
-#ifdef ANSI_PROTOTYPES
 os_error (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
-#else
-os_error (p, va_alist)
-     host_callback *p;
-     va_dcl
-#endif
 {
   va_list args;
-#ifdef ANSI_PROTOTYPES
   va_start (args, format);
-#else
-  char *format;
-
-  va_start (args);
-  format = va_arg (args, char *);
-#endif
 
   vfprintf (stderr, format, args);
   fprintf (stderr, "\n");
@@ -1161,3 +1140,21 @@ sim_cb_eprintf (host_callback *p, const char *fmt, ...)
   p->evprintf_filtered (p, fmt, ap);
   va_end (ap);
 }
+
+int
+cb_is_stdin (host_callback *cb, int fd)
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 0;
+}
+
+int
+cb_is_stdout (host_callback *cb, int fd)
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 1;
+}
+
+int
+cb_is_stderr (host_callback *cb, int fd)
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 2;
+}
This page took 0.024919 seconds and 4 git commands to generate.