Ejemplo n.º 1
0
/* fd, is a user file descriptor. */
PRIVILEGED_FUNCTION int _close_r(struct _reent *ptr, int fd) 
{
	int res;
	struct fdent *pfd;

	pfd = findslot(fd);
	if (pfd == NULL)
	{
		ptr->_errno = EBADF;
		return -1;
	}

	/* Handle stderr == stdout. */
	if ((fd == 1 || fd == 2)
			&& (openfiles[1].handle == openfiles[2].handle))
	{
		pfd->handle = -1;
		return 0;
	}

	/* Attempt to close the handle. */
	res = checkerror(do_AngelSWI (AngelSWI_Reason_Close, &f(pfd->handle)));

	/* Reclaim handle? */
	if (res == 0)
		pfd->handle = -1;

	return res;
}
Ejemplo n.º 2
0
PRIVILEGED_FUNCTION int _kill_r(struct _reent *ptr, int pid, int sig) 
{
	(void) pid;
	(void) sig;

	/* 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);
	}
}
Ejemplo n.º 3
0
PRIVILEGED_FUNCTION int _gettimeofday_r(struct _reent *ptr, struct timeval * tp, void * tzvp) 
{
	struct timezone *tzp = (struct timezone *)tzvp;
	if (tp)
	{
		/* Ask the host for the seconds since the Unix epoch.  */
		tp->tv_sec = do_AngelSWI(AngelSWI_Reason_Time, NULL);
		tp->tv_usec = 0;
	}

	/* Return fixed data for the timezone.  */
	if (tzp)
	{
		tzp->tz_minuteswest = 0;
		tzp->tz_dsttime = 0;
	}

	return 0;
}
Ejemplo n.º 4
0
/* fd, is a user file descriptor. */
PRIVILEGED_FUNCTION _off_t _lseek_r(struct _reent *ptr, int fd, _off_t offs, int dir) 
{
	int res;
	struct fdent *pfd;

	/* Valid file descriptor? */
	pfd = findslot(fd);
	if (pfd == NULL)
	{
		ptr->_errno = EBADF;
		return -1;
	}

	/* Valid whence? */
	if ((dir != SEEK_CUR)
			&& (dir != SEEK_SET)
			&& (dir != SEEK_END))
	{
		ptr->_errno = EINVAL;
		return -1;
	}

	/* Convert SEEK_CUR to SEEK_SET */
	if (dir == SEEK_CUR)
	{
		offs = pfd->pos + offs;
		/* The resulting file offset would be negative. */
		if (offs < 0)
		{
			ptr->_errno = EINVAL;
			if ((pfd->pos > 0) && (offs > 0))
				ptr->_errno = EOVERFLOW;
			return -1;
		}
		dir = SEEK_SET;
	}

	int block[2];
	if (dir == SEEK_END)
	{
		block[0] = pfd->handle;
		res = checkerror(do_AngelSWI(AngelSWI_Reason_FLen, block));
		if (res == -1)
			return -1;
		offs += res;
	}

	/* This code only does absolute seeks.  */
	block[0] = pfd->handle;
	block[1] = offs;
	res = checkerror(do_AngelSWI(AngelSWI_Reason_Seek, block));

	/* At this point offs is the current file position. */
	if (res >= 0)
	{
		pfd->pos = offs;
		return offs;
	}
	else
		return -1;
}