/*	:ts=4
 *	This is an Amiga version of the Unix system calls that need
 *	to be implemented in order to link the C-News package...
 *
 *	$Id: syscalls.c,v 1.2 90/12/15 12:47:10 crash Exp Locker: crash $
 *
 *	$Log:	syscalls.c,v $
 * Revision 1.2  90/12/15  12:47:10  crash
 * played with the output messaging a little
 * 
 * Revision 1.1  90/05/21  23:51:04  crash
 * Initial revision
 * 
 */

#include <stdio.h>				/* For file_i/o stuff */
#include <stdlib.h>				/* Declarations of ctime(), etc */
#include <time.h>				/* For time_t */

#ifdef __STDC__
# include <stdarg.h>
#else
# include <varargs.h>
#endif

#include <exec/types.h>
#include <dos/dos.h>				/* For TICKS */
#include <clib/exec_protos.h>		/* For FindTask() */
#include <clib/dos_protos.h>		/* For MakeLink() */

#if INCLUDE_VERSION >= 36
# include <pragma/dos.h>
#endif

static FILE *syslogf = 0;
extern int errno;

sysfile(char *fmt, ...)
{
	if (syslogf) {
		va_list args;

		va_start(fmt, args);
		vfprintf(syslogf, fmt, args);
		va_end(args);
		fflush(syslogf);
	}
	return( 0 );
}

short getpid(void)
{
	return( (short) ((long) FindTask(0L) & 0x7FFFL) );
}

static short	old_uid  = 0, old_gid  = 0;
static short	old_euid = 0, old_egid = 0;

short getuid(void)
{
	return( old_uid );
}

short getgid(void)
{
	return( old_gid );
}

short geteuid(void)
{
	return( old_euid );
}

short getegid(void)
{
	return( old_egid );
}

short setuid(short new_uid)
{
	short xxx;

	xxx = old_uid;
	old_uid = new_uid;
	return( xxx );
}

short setgid(short new_gid)
{
	short xxx;

	xxx = old_gid;
	old_gid = new_gid;
	return( xxx );
}

chown(char *fname, short uid)
{
	sysfile("Supposed to chown on `%s' to `%hd'\n", fname, uid);
	return( 0 );
}

#ifndef unix		/* If not on Manx, ... */
sleep(long sec)
{
	Delay( sec * TICKS_PER_SECOND );
	return( 0 );
}
#endif /* unix */

short umask(short msk)
{
	static short old_msk = 0;
	short xxx;

	xxx = old_msk;
	old_msk = msk;
	return( xxx );
}

int alarm(int secs)
{
	return( 0 );
}

#if defined(AZTEC_C) && !defined(__VERSION)
void mktemp(char *p)
{
	register char *tmp;
	register int count = 0;
	FILE *fp;

	tmp = p + strlen(p);
	while (*--tmp == 'X')
		count++;
	sprintf(tmp+1, "%0*.*ld", count, count, (long) getpid());
	if (fp = fopen( p, "w" ))
		fclose(fp);
}
#endif
