static int fdmap PARAMS ((host_callback *, int));
static int fdbad PARAMS ((host_callback *, int));
static int wrap PARAMS ((host_callback *, int));
-static int enosys PARAMS ((host_callback *, int));
/* Set the callback copy of errno from what we see now. */
return val;
}
-/* Return a value indicating the system call isn't present. */
-
-static int
-enosys (p, result)
- host_callback *p;
- int result;
-{
-#ifdef ENOSYS
- p->last_errno = ENOSYS;
-#else
- p->last_errno = EINVAL;
-#endif
- return result;
-}
-
/* Make sure the FD provided is ok. If not, return non-zero
and set errno. */
if (result)
return result;
result = wrap (p, close (fdmap (p, fd)));
- if(result == 0 && !p->alwaysopen[fd])
+ if (result == 0 && !p->alwaysopen[fd])
p->fdopen[fd] = 0;
return result;
static int
os_write_stdout (p, buf, len)
- host_callback *p;
+ host_callback *p ATTRIBUTE_UNUSED;
const char *buf;
int len;
{
- return fwrite(buf, 1, len, stdout);
+ return fwrite (buf, 1, len, stdout);
}
static void
os_flush_stdout (p)
- host_callback *p;
+ host_callback *p ATTRIBUTE_UNUSED;
{
fflush (stdout);
}
static int
os_write_stderr (p, buf, len)
- host_callback *p;
+ host_callback *p ATTRIBUTE_UNUSED;
const char *buf;
int len;
{
- return fwrite(buf, 1, len, stderr);
+ return fwrite (buf, 1, len, stderr);
}
static void
os_flush_stderr (p)
- host_callback *p;
+ host_callback *p ATTRIBUTE_UNUSED;
{
fflush (stderr);
}
os_stat (p, file, buf)
host_callback *p;
const char *file;
- PTR buf;
+ struct stat *buf;
{
+ /* ??? There is an issue of when to translate to the target layout.
+ One could do that inside this function, or one could have the
+ caller do it. It's more flexible to let the caller do it, though
+ I'm not sure the flexibility will ever be useful. */
return wrap (p, stat (file, buf));
}
os_fstat (p, fd, buf)
host_callback *p;
int fd;
- PTR buf;
+ struct stat *buf;
{
- return wrap (p, fstat (fd, buf));
+ if (fdbad (p, fd))
+ return -1;
+ /* ??? There is an issue of when to translate to the target layout.
+ One could do that inside this function, or one could have the
+ caller do it. It's more flexible to let the caller do it, though
+ I'm not sure the flexibility will ever be useful. */
+ return wrap (p, fstat (fdmap (p, fd), buf));
}
static int
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
-os_printf_filtered (host_callback *p, const char *format, ...)
+os_printf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
#else
os_printf_filtered (p, va_alist)
host_callback *p;
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
-os_vprintf_filtered (host_callback *p, const char *format, va_list args)
+os_vprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
#else
os_vprintf_filtered (p, format, args)
host_callback *p;
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
-os_evprintf_filtered (host_callback *p, const char *format, va_list args)
+os_evprintf_filtered (host_callback *p ATTRIBUTE_UNUSED, const char *format, va_list args)
#else
os_evprintf_filtered (p, format, args)
host_callback *p;
/* VARARGS */
static void
#ifdef ANSI_PROTOTYPES
-os_error (host_callback *p, const char *format, ...)
+os_error (host_callback *p ATTRIBUTE_UNUSED, const char *format, ...)
#else
os_error (p, va_alist)
host_callback *p;
};
\f
/* Read in a file describing the target's system call values.
- This allows simulators, etc. to support arbitrary libraries
- without having to be recompiled.
E.g. maybe someone will want to use something other than newlib.
+ This assumes that the basic system call recognition and value passing/
+ returning is supported. So maybe some coding/recompilation will be
+ necessary, but not as much.
If an error occurs, the existing mapping is not changed. */
}
/* Translate a host's stat struct into a target's.
+ If HS is NULL, just compute the length of the buffer required,
+ TS is ignored.
- BIG_P is non-zero if the target is big-endian.
- The result is the size of the target's stat struct. */
+ The result is the size of the target's stat struct,
+ or zero if an error occured during the translation. */
int
-cb_host_to_target_stat (cb, hs, ts, big_p)
+cb_host_to_target_stat (cb, hs, ts)
host_callback *cb;
const struct stat *hs;
PTR ts;
- int big_p;
{
const char *m = cb->stat_map;
- char *p = ts;
+ char *p;
+ int big_p = 0;
+
+ if (hs == NULL)
+ ts = NULL;
+ p = ts;
while (m)
{
if (q == NULL)
{
/* FIXME: print error message */
- return;
+ return 0;
}
size = atoi (q + 1);
if (size == 0)
{
/* FIXME: print error message */
- return;
+ return 0;
}
- if (strncmp (m, "st_dev", q - m) == 0)
- store (p, size, hs->st_dev, big_p);
- else if (strncmp (m, "st_ino", q - m) == 0)
- store (p, size, hs->st_ino, big_p);
- /* FIXME:wip */
- else
- store (p, size, 0, big_p); /* unsupported field, store 0 */
+ if (hs != NULL)
+ {
+ if (strncmp (m, "st_dev", q - m) == 0)
+ store (p, size, hs->st_dev, big_p);
+ else if (strncmp (m, "st_ino", q - m) == 0)
+ store (p, size, hs->st_ino, big_p);
+ /* FIXME:wip */
+ else
+ store (p, size, 0, big_p); /* unsupported field, store 0 */
+ }
p += size;
m = strchr (q, ':');
if (m)
++m;
}
+
+ return p - (char *) ts;
}
\f
/* Cover functions to the vfprintf callbacks.