newlib-cygwin/newlib/libc/sys/arm/syscalls.c

674 lines
14 KiB
C
Raw Normal View History

2000-02-18 03:39:52 +08:00
/* Support files for GNU libc. Files in the system namespace go here.
Files in the C namespace (ie those that do not start with an
underscore) go in .c. */
#include <_ansi.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>
#include <errno.h>
#include <reent.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
2000-02-18 03:39:52 +08:00
#include "swi.h"
/* Forward prototypes. */
int _system _PARAMS ((const char *));
int _rename _PARAMS ((const char *, const char *));
int _isatty _PARAMS ((int));
2000-02-18 03:39:52 +08:00
clock_t _times _PARAMS ((struct tms *));
int _gettimeofday _PARAMS ((struct timeval *, void *));
2000-02-18 03:39:52 +08:00
void _raise _PARAMS ((void));
int _unlink _PARAMS ((const char *));
2000-02-18 03:39:52 +08:00
int _link _PARAMS ((void));
int _stat _PARAMS ((const char *, struct stat *));
2000-02-18 03:39:52 +08:00
int _fstat _PARAMS ((int, struct stat *));
caddr_t _sbrk _PARAMS ((int));
int _getpid _PARAMS ((int));
int _kill _PARAMS ((int, int));
void _exit _PARAMS ((int));
int _close _PARAMS ((int));
int _swiclose _PARAMS ((int));
int _open _PARAMS ((const char *, int, ...));
int _swiopen _PARAMS ((const char *, int));
int _write _PARAMS ((int, char *, int));
int _swiwrite _PARAMS ((int, char *, int));
int _lseek _PARAMS ((int, int, int));
int _swilseek _PARAMS ((int, int, int));
int _read _PARAMS ((int, char *, int));
int _swiread _PARAMS ((int, char *, int));
void initialise_monitor_handles _PARAMS ((void));
static int wrap _PARAMS ((int));
static int error _PARAMS ((int));
static int get_errno _PARAMS ((void));
static int remap_handle _PARAMS ((int));
static int do_AngelSWI _PARAMS ((int, void *));
static int findslot _PARAMS ((int));
/* Register name faking - works in collusion with the linker. */
register char * stack_ptr asm ("sp");
/* following is copied from libc/stdio/local.h to check std streams */
extern void _EXFUN(__sinit,(struct _reent *));
2005-02-07 Antony King <antony.king@st.com> * libc/stdio/clearerr.c (clearerr): Ensure CHECK_INIT() is called before _flockfile to prevent lock object use before initialisation. _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/fclose.c (_fclose_r): Ditto. * libc/stdio/feof.c (feof): Ditto. * libc/stdio/ferror.c (ferror): Ditto. * libc/stdio/fflush.c (fflush): Ditto. * libc/stdio/fgetc.c (fgetc): Ditto. * libc/stdio/fgets.c (fgets): Ditto. * libc/stdio/fileno.c (fileno): Ditto. * libc/stdio/fputc.c (fputc): Ditto. * libc/stdio/fputs.c (fputs): Ditto. * libc/stdio/fread.c (fread): Ditto. * libc/stdio/freopen.c (_freopen_r): Ditto. * libc/stdio/fseek.c (_fseek_r): Ditto. * libc/stdio/ftell.c (_ftell_r): Ditto. * libc/stdio/fwrite.c (fwrite): Ditto. * libc/stdio/getc.c (getc): Ditto. * libc/stdio/getdelim.c (__getdelim): Ditto. * libc/stdio/putc.c (putc): Ditto. * libc/stdio/setvbuf.c (setvbuf): Ditto. * libc/stdio/ungetc.c (_ungetc_r): Ditto. * libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto. * libc/stdio64/freopen64.c (_freopen64_r): Ditto. * libc/stdio64/fseeko64.c (_fseeko64_r): Ditto. * libc/stdio64/ftello64.c (_ftello64_r): Ditto. * libc/stdio/local.h (CHECK_INIT): Argument is now a struct _reent * instead of a FILE * and so replace incorrect use of _REENT with argument. * libc/sys/arm/syscalls.c (CHECK_INIT): Ditto. * libc/stdio/getchar.c (getchar): _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/iprintf.c (iprintf, _iprintf_r): Ditto. * libc/stdio/iscanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/perror.c (perror): Ditto. * libc/stdio/printf.c (printf, _printf_r): Ditto. * libc/stdio/putchar.c (putchar): Ditto. * libc/stdio/puts.c (puts): Ditto. * libc/stdio/refill.c (__srefill): Ditto. * libc/stdio/scanf.c (scanf, _scanf_r): Ditto. * libc/stdio/vfscanf.c (VFSCANF, _VFSCANF_R): Ditto. * libc/stdio/viprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/viscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vprintf.c (vprintf, _vprintf_r): Ditto. * libc/stdio/vscanf.c (vscanf, _vscanf_r): Ditto. * libc/stdio/wbuf.c (__swbuf): Ditto. * libc/stdio/wsetup.c (__swsetup): Ditto. * libc/stdlib/mallocr.c (malloc_stats): Ditto. * libc/stdlib/mstats.c (_mstats_r): Ditto. * libc/include/sys/reent.h (_REENT_SMALL_CHECK_INIT): Ditto. * libc/machine/powerpc/vfscanf.c (vfscanf): Ditto. * libc/stdio/fgetpos.c (_fgetpos_r): Removed unnecessary calls to _flockfile and _funlockfile; rely on locking in _ftell_r. * libc/stdio64/fgetpos64.c (_fgetpos64_r): Ditto (_ftello64_r). * libc/machine/powerpc/vfprintf.c (__sbprintf): Removed unnecessary initialision of _data field in FILE structure. * libc/machine/powerpc/vfprintf.c (VFPRINTF): Added CHECK_INIT() call.
2005-02-08 09:33:19 +08:00
#define CHECK_INIT(ptr) \
do \
{ \
if ((ptr) && !(ptr)->__sdidinit) \
__sinit (ptr); \
} \
2000-02-18 03:39:52 +08:00
while (0)
/* Adjust our internal handles to stay away from std* handles. */
2000-02-18 03:39:52 +08:00
#define FILE_HANDLE_OFFSET (0x20)
static int monitor_stdin;
static int monitor_stdout;
static int monitor_stderr;
/* Struct used to keep track of the file position, just so we
can implement fseek(fh,x,SEEK_CUR). */
typedef struct
{
int handle;
int pos;
}
poslog;
#define MAX_OPEN_FILES 20
static poslog openfiles [MAX_OPEN_FILES];
static int
findslot (int fh)
{
int i;
for (i = 0; i < MAX_OPEN_FILES; i ++)
if (openfiles[i].handle == fh)
break;
return i;
}
#ifdef ARM_RDI_MONITOR
static inline int
do_AngelSWI (int reason, void * arg)
{
int value;
asm volatile ("mov r0, %1; mov r1, %2; " AngelSWIInsn " %a3; mov %0, r0"
2000-02-18 03:39:52 +08:00
: "=r" (value) /* Outputs */
: "r" (reason), "r" (arg), "i" (AngelSWI) /* Inputs */
: "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc"
2000-02-18 03:39:52 +08:00
/* Clobbers r0 and r1, and lr if in supervisor mode */);
/* Accordingly to page 13-77 of ARM DUI 0040D other registers
can also be clobbered. Some memory positions may also be
changed by a system call, so they should not be kept in
registers. Note: we are assuming the manual is right and
Angel is respecting the APCS. */
2000-02-18 03:39:52 +08:00
return value;
}
#endif /* ARM_RDI_MONITOR */
/* Function to convert std(in|out|err) handles to internal versions. */
2000-02-18 03:39:52 +08:00
static int
remap_handle (int fh)
{
2005-02-07 Antony King <antony.king@st.com> * libc/stdio/clearerr.c (clearerr): Ensure CHECK_INIT() is called before _flockfile to prevent lock object use before initialisation. _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/fclose.c (_fclose_r): Ditto. * libc/stdio/feof.c (feof): Ditto. * libc/stdio/ferror.c (ferror): Ditto. * libc/stdio/fflush.c (fflush): Ditto. * libc/stdio/fgetc.c (fgetc): Ditto. * libc/stdio/fgets.c (fgets): Ditto. * libc/stdio/fileno.c (fileno): Ditto. * libc/stdio/fputc.c (fputc): Ditto. * libc/stdio/fputs.c (fputs): Ditto. * libc/stdio/fread.c (fread): Ditto. * libc/stdio/freopen.c (_freopen_r): Ditto. * libc/stdio/fseek.c (_fseek_r): Ditto. * libc/stdio/ftell.c (_ftell_r): Ditto. * libc/stdio/fwrite.c (fwrite): Ditto. * libc/stdio/getc.c (getc): Ditto. * libc/stdio/getdelim.c (__getdelim): Ditto. * libc/stdio/putc.c (putc): Ditto. * libc/stdio/setvbuf.c (setvbuf): Ditto. * libc/stdio/ungetc.c (_ungetc_r): Ditto. * libc/stdio/vfprintf.c (_VFPRINTF_R): Ditto. * libc/stdio64/freopen64.c (_freopen64_r): Ditto. * libc/stdio64/fseeko64.c (_fseeko64_r): Ditto. * libc/stdio64/ftello64.c (_ftello64_r): Ditto. * libc/stdio/local.h (CHECK_INIT): Argument is now a struct _reent * instead of a FILE * and so replace incorrect use of _REENT with argument. * libc/sys/arm/syscalls.c (CHECK_INIT): Ditto. * libc/stdio/getchar.c (getchar): _REENT_SMALL_CHECK_INIT() and CHECK_INIT() take a struct _reent * instead of a FILE *. * libc/stdio/iprintf.c (iprintf, _iprintf_r): Ditto. * libc/stdio/iscanf.c (iscanf, _iscanf_r): Ditto. * libc/stdio/perror.c (perror): Ditto. * libc/stdio/printf.c (printf, _printf_r): Ditto. * libc/stdio/putchar.c (putchar): Ditto. * libc/stdio/puts.c (puts): Ditto. * libc/stdio/refill.c (__srefill): Ditto. * libc/stdio/scanf.c (scanf, _scanf_r): Ditto. * libc/stdio/vfscanf.c (VFSCANF, _VFSCANF_R): Ditto. * libc/stdio/viprintf.c (viprintf, _viprintf_r): Ditto. * libc/stdio/viscanf.c (viscanf, _viscanf_r): Ditto. * libc/stdio/vprintf.c (vprintf, _vprintf_r): Ditto. * libc/stdio/vscanf.c (vscanf, _vscanf_r): Ditto. * libc/stdio/wbuf.c (__swbuf): Ditto. * libc/stdio/wsetup.c (__swsetup): Ditto. * libc/stdlib/mallocr.c (malloc_stats): Ditto. * libc/stdlib/mstats.c (_mstats_r): Ditto. * libc/include/sys/reent.h (_REENT_SMALL_CHECK_INIT): Ditto. * libc/machine/powerpc/vfscanf.c (vfscanf): Ditto. * libc/stdio/fgetpos.c (_fgetpos_r): Removed unnecessary calls to _flockfile and _funlockfile; rely on locking in _ftell_r. * libc/stdio64/fgetpos64.c (_fgetpos64_r): Ditto (_ftello64_r). * libc/machine/powerpc/vfprintf.c (__sbprintf): Removed unnecessary initialision of _data field in FILE structure. * libc/machine/powerpc/vfprintf.c (VFPRINTF): Added CHECK_INIT() call.
2005-02-08 09:33:19 +08:00
CHECK_INIT(_REENT);
if (fh == STDIN_FILENO)
2000-02-18 03:39:52 +08:00
return monitor_stdin;
if (fh == STDOUT_FILENO)
2000-02-18 03:39:52 +08:00
return monitor_stdout;
if (fh == STDERR_FILENO)
2000-02-18 03:39:52 +08:00
return monitor_stderr;
return fh - FILE_HANDLE_OFFSET;
}
void
initialise_monitor_handles (void)
{
int i;
#ifdef ARM_RDI_MONITOR
int volatile block[3];
block[0] = (int) ":tt";
block[2] = 3; /* length of filename */
block[1] = 0; /* mode "r" */
monitor_stdin = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
block[0] = (int) ":tt";
block[2] = 3; /* length of filename */
block[1] = 4; /* mode "w" */
monitor_stdout = monitor_stderr = do_AngelSWI (AngelSWI_Reason_Open, (void *) block);
#else
int fh;
const char * name;
name = ":tt";
asm ("mov r0,%2; mov r1, #0; swi %a1; mov %0, r0"
: "=r"(fh)
: "i" (SWI_Open),"r"(name)
: "r0","r1");
monitor_stdin = fh;
name = ":tt";
asm ("mov r0,%2; mov r1, #4; swi %a1; mov %0, r0"
: "=r"(fh)
: "i" (SWI_Open),"r"(name)
: "r0","r1");
monitor_stdout = monitor_stderr = fh;
#endif
for (i = 0; i < MAX_OPEN_FILES; i ++)
openfiles[i].handle = -1;
openfiles[0].handle = monitor_stdin;
openfiles[0].pos = 0;
openfiles[1].handle = monitor_stdout;
openfiles[1].pos = 0;
}
static int
get_errno (void)
{
#ifdef ARM_RDI_MONITOR
return do_AngelSWI (AngelSWI_Reason_Errno, NULL);
#else
asm ("swi %a0" :: "i" (SWI_GetErrno));
#endif
}
static int
error (int result)
{
errno = get_errno ();
return result;
}
static int
wrap (int result)
{
if (result == -1)
return error (-1);
return result;
}
/* Returns # chars not! written. */
2000-02-18 03:39:52 +08:00
int
_swiread (int file,
char * ptr,
int len)
{
int fh = remap_handle (file);
#ifdef ARM_RDI_MONITOR
int block[3];
block[0] = fh;
block[1] = (int) ptr;
block[2] = len;
return do_AngelSWI (AngelSWI_Reason_Read, block);
#else
asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0"
: /* No outputs */
: "i"(SWI_Read), "r"(fh), "r"(ptr), "r"(len)
: "r0","r1","r2");
#endif
}
int
_read (int file,
char * ptr,
int len)
{
int slot = findslot (remap_handle (file));
int x = _swiread (file, ptr, len);
if (x < 0)
return error (-1);
if (slot != MAX_OPEN_FILES)
openfiles [slot].pos += len - x;
/* x == len is not an error, at least if we want feof() to work. */
2000-02-18 03:39:52 +08:00
return len - x;
}
int
_swilseek (int file,
int ptr,
int dir)
{
int res;
int fh = remap_handle (file);
int slot = findslot (fh);
#ifdef ARM_RDI_MONITOR
int block[2];
#endif
if (dir == SEEK_CUR)
{
if (slot == MAX_OPEN_FILES)
return -1;
ptr = openfiles[slot].pos + ptr;
dir = SEEK_SET;
}
#ifdef ARM_RDI_MONITOR
if (dir == SEEK_END)
{
block[0] = fh;
ptr += do_AngelSWI (AngelSWI_Reason_FLen, block);
}
/* This code only does absolute seeks. */
2000-02-18 03:39:52 +08:00
block[0] = remap_handle (file);
block[1] = ptr;
res = do_AngelSWI (AngelSWI_Reason_Seek, block);
#else
if (dir == SEEK_END)
{
asm ("mov r0, %2; swi %a1; mov %0, r0"
: "=r" (res)
: "i" (SWI_Flen), "r" (fh)
: "r0");
ptr += res;
}
/* This code only does absolute seeks. */
2000-02-18 03:39:52 +08:00
asm ("mov r0, %2; mov r1, %3; swi %a1; mov %0, r0"
: "=r" (res)
: "i" (SWI_Seek), "r" (fh), "r" (ptr)
: "r0", "r1");
#endif
if (slot != MAX_OPEN_FILES && res == 0)
openfiles[slot].pos = ptr;
/* This is expected to return the position in the file. */
2000-02-18 03:39:52 +08:00
return res == 0 ? ptr : -1;
}
int
_lseek (int file,
int ptr,
int dir)
{
return wrap (_swilseek (file, ptr, dir));
}
/* Returns #chars not! written. */
2000-02-18 03:39:52 +08:00
int
_swiwrite (
int file,
char * ptr,
int len)
{
int fh = remap_handle (file);
#ifdef ARM_RDI_MONITOR
int block[3];
block[0] = fh;
block[1] = (int) ptr;
block[2] = len;
return do_AngelSWI (AngelSWI_Reason_Write, block);
#else
asm ("mov r0, %1; mov r1, %2;mov r2, %3; swi %a0"
: /* No outputs */
: "i"(SWI_Write), "r"(fh), "r"(ptr), "r"(len)
: "r0","r1","r2");
#endif
}
int
_write (int file,
char * ptr,
int len)
{
int slot = findslot (remap_handle (file));
int x = _swiwrite (file, ptr,len);
if (x == -1 || x == len)
return error (-1);
if (slot != MAX_OPEN_FILES)
openfiles[slot].pos += len - x;
return len - x;
}
extern int strlen (const char *);
2000-02-18 03:39:52 +08:00
int
_swiopen (const char * path,
int flags)
{
int aflags = 0, fh;
#ifdef ARM_RDI_MONITOR
int block[3];
#endif
int i = findslot (-1);
if (i == MAX_OPEN_FILES)
return -1;
/* The flags are Unix-style, so we need to convert them. */
2000-02-18 03:39:52 +08:00
#ifdef O_BINARY
if (flags & O_BINARY)
aflags |= 1;
#endif
if (flags & O_RDWR)
aflags |= 2;
if (flags & O_CREAT)
aflags |= 4;
if (flags & O_TRUNC)
aflags |= 4;
if (flags & O_APPEND)
{
aflags &= ~4; /* Can't ask for w AND a; means just 'a'. */
2000-02-18 03:39:52 +08:00
aflags |= 8;
}
#ifdef ARM_RDI_MONITOR
block[0] = (int) path;
block[2] = strlen (path);
block[1] = aflags;
fh = do_AngelSWI (AngelSWI_Reason_Open, block);
#else
asm ("mov r0,%2; mov r1, %3; swi %a1; mov %0, r0"
: "=r"(fh)
: "i" (SWI_Open),"r"(path),"r"(aflags)
: "r0","r1");
#endif
if (fh >= 0)
{
openfiles[i].handle = fh;
openfiles[i].pos = 0;
}
return fh >= 0 ? fh + FILE_HANDLE_OFFSET : error (fh);
}
int
_open (const char * path,
int flags,
...)
{
return wrap (_swiopen (path, flags));
}
int
_swiclose (int file)
{
int myhan = remap_handle (file);
int slot = findslot (myhan);
if (slot != MAX_OPEN_FILES)
openfiles[slot].handle = -1;
#ifdef ARM_RDI_MONITOR
return do_AngelSWI (AngelSWI_Reason_Close, & myhan);
#else
asm ("mov r0, %1; swi %a0" :: "i" (SWI_Close),"r"(myhan):"r0");
#endif
}
int
_close (int file)
{
return wrap (_swiclose (file));
}
int
_kill (int pid, int sig)
2000-02-18 03:39:52 +08:00
{
(void)pid; (void)sig;
2000-02-18 03:39:52 +08:00
#ifdef ARM_RDI_MONITOR
/* Note: The pid argument is thrown away. */
switch (sig) {
case SIGABRT:
return do_AngelSWI (AngelSWI_Reason_ReportException,
(void *) ADP_Stopped_RunTimeError);
default:
return do_AngelSWI (AngelSWI_Reason_ReportException,
(void *) ADP_Stopped_ApplicationExit);
}
2000-02-18 03:39:52 +08:00
#else
asm ("swi %a0" :: "i" (SWI_Exit));
#endif
}
void
_exit (int status)
2000-02-18 03:39:52 +08:00
{
/* There is only one SWI for both _exit and _kill. For _exit, call
the SWI with the second argument set to -1, an invalid value for
signum, so that the SWI handler can distinguish the two calls.
Note: The RDI implementation of _kill throws away both its
arguments. */
_kill(status, -1);
2000-02-18 03:39:52 +08:00
}
int
_getpid (int n)
{
return 1;
n = n;
2000-02-18 03:39:52 +08:00
}
caddr_t
_sbrk (int incr)
{
extern char end asm ("end"); /* Defined by the linker. */
2000-02-18 03:39:52 +08:00
static char * heap_end;
char * prev_heap_end;
if (heap_end == NULL)
heap_end = & end;
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr)
{
/* Some of the libstdc++-v3 tests rely upon detecting
out of memory errors, so do not abort here. */
#if 0
extern void abort (void);
2000-02-18 03:39:52 +08:00
_write (1, "_sbrk: Heap and stack collision\n", 32);
2000-02-18 03:39:52 +08:00
abort ();
#else
errno = ENOMEM;
return (caddr_t) -1;
#endif
2000-02-18 03:39:52 +08:00
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
extern void memset (struct stat *, int, unsigned int);
2000-02-18 03:39:52 +08:00
int
_fstat (int file, struct stat * st)
{
memset (st, 0, sizeof (* st));
st->st_mode = S_IFCHR;
st->st_blksize = 1024;
return 0;
file = file;
2000-02-18 03:39:52 +08:00
}
int _stat (const char *fname, struct stat *st)
{
int file;
/* The best we can do is try to open the file readonly. If it exists,
then we can guess a few things about it. */
if ((file = _open (fname, O_RDONLY)) < 0)
return -1;
memset (st, 0, sizeof (* st));
st->st_mode = S_IFREG | S_IREAD;
st->st_blksize = 1024;
_swiclose (file); /* Not interested in the error. */
return 0;
}
2000-02-18 03:39:52 +08:00
int
_link (void)
{
return -1;
}
int
_unlink (const char *path)
2000-02-18 03:39:52 +08:00
{
#ifdef ARM_RDI_MONITOR
int block[2];
block[0] = path;
block[1] = strlen(path);
return wrap (do_AngelSWI (AngelSWI_Reason_Remove, block)) ? -1 : 0;
#else
2000-02-18 03:39:52 +08:00
return -1;
#endif
2000-02-18 03:39:52 +08:00
}
void
_raise (void)
{
return;
}
int
_gettimeofday (struct timeval * tp, void * tzvp)
2000-02-18 03:39:52 +08:00
{
struct timezone *tzp = tzvp;
2000-02-18 03:39:52 +08:00
if (tp)
{
/* Ask the host for the seconds since the Unix epoch. */
2000-02-18 03:39:52 +08:00
#ifdef ARM_RDI_MONITOR
tp->tv_sec = do_AngelSWI (AngelSWI_Reason_Time,NULL);
#else
{
int value;
asm ("swi %a1; mov %0, r0" : "=r" (value): "i" (SWI_Time) : "r0");
tp->tv_sec = value;
}
#endif
tp->tv_usec = 0;
}
/* Return fixed data for the timezone. */
2000-02-18 03:39:52 +08:00
if (tzp)
{
tzp->tz_minuteswest = 0;
tzp->tz_dsttime = 0;
}
return 0;
}
/* Return a clock that ticks at 100Hz. */
2000-02-18 03:39:52 +08:00
clock_t
_times (struct tms * tp)
{
clock_t timeval;
#ifdef ARM_RDI_MONITOR
timeval = do_AngelSWI (AngelSWI_Reason_Clock,NULL);
#else
asm ("swi %a1; mov %0, r0" : "=r" (timeval): "i" (SWI_Clock) : "r0");
#endif
if (tp)
{
tp->tms_utime = timeval; /* user time */
tp->tms_stime = 0; /* system time */
tp->tms_cutime = 0; /* user time, children */
tp->tms_cstime = 0; /* system time, children */
}
return timeval;
};
int
_isatty (int fd)
2000-02-18 03:39:52 +08:00
{
#ifdef ARM_RDI_MONITOR
int fh = remap_handle (fd);
return wrap (do_AngelSWI (AngelSWI_Reason_IsTTY, &fh));
#else
return (fd <= 2) ? 1 : 0; /* one of stdin, stdout, stderr */
#endif
2000-02-18 03:39:52 +08:00
}
int
_system (const char *s)
{
#ifdef ARM_RDI_MONITOR
int block[2];
int e;
/* Hmmm. The ARM debug interface specification doesn't say whether
SYS_SYSTEM does the right thing with a null argument, or assign any
meaning to its return value. Try to do something reasonable.... */
if (!s)
return 1; /* maybe there is a shell available? we can hope. :-P */
block[0] = s;
block[1] = strlen (s);
e = wrap (do_AngelSWI (AngelSWI_Reason_System, block));
if ((e >= 0) && (e < 256))
{
/* We have to convert e, an exit status to the encoded status of
the command. To avoid hard coding the exit status, we simply
loop until we find the right position. */
int exit_code;
for (exit_code = e; e && WEXITSTATUS (e) != exit_code; e <<= 1)
continue;
}
return e;
#else
if (s == NULL)
return 0;
errno = ENOSYS;
return -1;
#endif
}
int
_rename (const char * oldpath, const char * newpath)
{
#ifdef ARM_RDI_MONITOR
int block[4];
block[0] = oldpath;
block[1] = strlen(oldpath);
block[2] = newpath;
block[3] = strlen(newpath);
return wrap (do_AngelSWI (AngelSWI_Reason_Rename, block)) ? -1 : 0;
#else
errno = ENOSYS;
return -1;
#endif
}