/* 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.
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,
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. */
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));
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. */
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
}
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;
}
const char *file;
long len;
{
+#ifdef HAVE_TRUNCATE
return wrap (p, truncate (file, len));
+#else
+ p->last_errno = EINVAL;
+ return -1;
+#endif
}
static int
/* 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);
/* 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");
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;
+}