[comp.sources.atari.st] v02i074: gcclib2 -- Patches to GCC library part03/07

koreth%panarthea.ebay@sun.com (Steven Grimm) (08/20/89)

Submitted-by: uunet.UU.NET!unido!sbsvax!roeder (Edgar Roeder)
Posting-number: Volume 2, Issue 74
Archive-name: gcclib2/part03



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 7)."
# Contents:  alrm_nas.s include/errno.h include/signal.h include/stat.h
#   include/stdio.h include/stdlib.h ioctl.c.cdiff open.c
#   opendir.c.cdiff st-error.c std-init.c time.c trap-1.c trap-13.c
#   write.c.cdiff
# Wrapped by roeder@sbsvax on Wed Aug 16 22:03:00 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'alrm_nas.s' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'alrm_nas.s'\"
else
echo shar: Extracting \"'alrm_nas.s'\" \(1840 characters\)
sed "s/^X//" >'alrm_nas.s' <<'END_OF_FILE'
X|
X|		Cross Development System for Atari ST 
X|      Copyright (c) 1988, Memorial University of Newfoundland
X|
X|   At this point we take over from dos - we know (think?) that the stack
X| looks like this now:
X|	0	long	pc
X|	4	long	arg (pointer to d7 below)
X|		(stuff - unknown size - depends on compiler - could be size 0)
X|		long	pc
X|	*4	long	d7
X|	*4+0x4	long	a0
X|	*4+0x8	long	d0
X|	*4+0xc	long	d1
X|		.
X|		.
X|	*4+0x24	long	d7
X|	*4+0x28	long	a0
X|		.
X|		.
X|	*4+0x40	long	a6
X|	*4+0x44	word	sr	status register from exception
X|	*4+0x46	long	pc	pc from exception
X|		stuff
X|  The stratagy at this point consists of saving the exception sr/pc and puting
X| out own address in place of the pc.  When the system does it's rte we get
X| called and we call raise (which can call some routine which can do a 
X| longjmp).  If raise returns then we restore the sr/pc and do a rte.
X|
X| $Header: alrm_nasty.s,v 1.1 88/02/03 22:37:55 m68k Exp $
X|
X| $Log:	alrm_nasty.s,v $
X| Revision 1.1  88/02/03  22:37:55  m68k
X| Initial revision
X| 
X
X.globl	__in_trap			| extern
X.globl	_raise				| extern
X.globl	__alrm_nasty
X.globl	__received_signal
X
X.comm	alrm_sr, 2			| static
X.comm	alrm_pc, 4			| static
X.comm	__received_signal, 4
X
X__alrm_nasty:
X	movel	sp@(0x4), a0
X	movew	a0@(0x44), alrm_sr	| save sr/pc at static locations, it's
X	movel	a0@(0x46), alrm_pc	| safe now because we are blocking sigs
X	movew	#0x2300, a0@(0x44)	| fake sr (with super bit on)
X	movel	#alrm_fake, a0@(0x46)	| our fake return routine
X	rts
X
Xalrm_fake:
X	movel	alrm_pc, sp@-		| push original sr/pc on stack so we
X	movew	alrm_sr, sp@-		| can handle other signals during raise
X	moveml	d0-d2/a0-a2, sp@-	| save registers
X	movel	__received_signal, sp@-	| raise(SIG..)
X	clrl	__received_signal	| unblock other signals
X	jsr	_raise			|
X	addql	#0x4, sp		| pop signum
X	moveml	sp@+, d0-d2/a0-a2	| pop registers
X	rte
END_OF_FILE
if test 1840 -ne `wc -c <'alrm_nas.s'`; then
    echo shar: \"'alrm_nas.s'\" unpacked with wrong size!
fi
# end of 'alrm_nas.s'
fi
if test -f 'include/errno.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'include/errno.h'\"
else
echo shar: Extracting \"'include/errno.h'\" \(2191 characters\)
sed "s/^X//" >'include/errno.h' <<'END_OF_FILE'
X/*
X *		Cross Development System for Atari ST 
X *     Copyright (c) 1988, Memorial University of Newfoundland
X *
X * $Header: errno.h,v 1.2 88/02/03 20:07:07 m68k Exp $
X *
X * $Log:	errno.h,v $
X * Revision 1.2  88/02/03  20:07:07  m68k
X * Added ENOTTY for ioctl()
X * 
X * Revision 1.1  88/01/29  17:18:36  m68k
X * Initial revision
X * 
X */
X#define	ENOERR		  0		/* no error */
X#define	EERROR		  1		/* generic error */
X#define	EDRNRDY		  2		/* drive not ready */
X#define	EUKCMD		  3		/* unknown command */
X#define	ECRC		  4		/* crc error */
X#define	EBADREQ		  5		/* bad request */
X#define	ESEEK		  6		/* seek error */
X#define	EUKMEDIA	  7		/* unknown media */
X#define	ESECTOR		  8		/* sector not found */
X#define	EPAPER		  9		/* no paper */
X#define	EWRITE		 10		/* write fault */
X#define	EREAD		 11		/* read fault */
X#define	EGENERIC	 12		/* general mishap */
X#define	EROFS		 13		/* write protect */
X#define	ECHMEDIA	 14		/* media change */
X#define	EUKDEV		 15		/* unknown device */
X#define	EBADSEC		 16		/* bad sectors */
X#define	EIDISK		 17		/* insert disk */
X					/* (gap) */
X#define	EINVAL		 32		/* invalid function number */
X#define	ENOENT		 33		/* file not found */
X#define	EPATH		 34		/* path not found */
X#define	ENOTDIR		 34		/* path not found */
X#define	EMFILE		 35		/* too many open files */
X#define	EACCESS		 36		/* access denied */
X#define	EACCES		 36		/* access denied */
X#define	EBADF		 37		/* invalid handle */
X#define	ENOMEM		 39		/* insufficient memory */
X#define	EFAULT		 40		/* invalid memory block request */
X#define	ENXIO		 46		/* invalid drive */
X#define	EXDEV		 48		/* cross device rename */
X#define	ENMFILES	 49		/* no more files (fnext) */
X#define EDOM		 62
X#define ERANGE		 63
X#define	EBADARG		 64		/* range error/context unknown */
X#define	EINTERNAL	 65		/* internal error */
X#define	ENOEXEC		 66		/* invalid program load format */
X#define	ESBLOCK		 67		/* set block failed/growth restraints */
X					/* (gap) */
X#define	EEXIST		 80		/* file exists (open) */
X#define	ENAMETOOLONG	 81		/* file exists (open) */
X#define	ENOTTY		 82		/* not a tty (ioctl) */
X#define EAGAIN		EDRNRDY		/* try again later */
X
Xextern	int	errno;
Xextern	int	sys_nerr;
Xextern	char *	sys_errlist[];
END_OF_FILE
if test 2191 -ne `wc -c <'include/errno.h'`; then
    echo shar: \"'include/errno.h'\" unpacked with wrong size!
fi
# end of 'include/errno.h'
fi
if test -f 'include/signal.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'include/signal.h'\"
else
echo shar: Extracting \"'include/signal.h'\" \(2052 characters\)
sed "s/^X//" >'include/signal.h' <<'END_OF_FILE'
X#ifndef _SIGNAL_H
X#define _SIGNAL_H
X/*
X *		Cross Development System for Atari ST 
X *     Copyright (c) 1988, Memorial University of Newfoundland
X *
X *  Beware the SIGINT/SIGQUIT - right now they only work when you are read()ing
X *
X * $Header: signal.h,v 1.1 88/02/03 20:06:23 m68k Exp $
X *
X * cleaned up for ANSI C (er) [13.8.1989]:
X * added typedefs, SIG_ERR and a few signal values
X *
X * $Log:	signal.h,v $
X * Revision 1.1  88/02/03  20:06:23  m68k
X * Initial revision
X * 
X */
X#ifdef __GNUC__
X#pragma once
X#endif
X
Xtypedef long	sig_atomic_t;	/* the integral type of an object that can  */
X				/* be accessed as an atomic entity, even in */
X				/* the presence of asynchronous interrupts. */
Xtypedef int	sig_handler_t(int);	/* type for signal handlers */
X
X#define	SIG_DFL		((sig_handler_t *)  0)
X#define	SIG_ERR		((sig_handler_t *) -1)
X#define	SIG_IGN		((sig_handler_t *)  1)
X
X#define	NSIG		19
X
X#define	SIGNULL		0		/* The null signal */
X#define	SIGALRM		1		/* If SIGALRM changes, change the value
X					 * in lib/libc/atari/alrm_nasty.s too!
X					 */
X/* this block are just trap numbers.  I made up most of these names... */
X#define SIGBUS		2
X#define	SIGODD		3
X#define SIGILL		4
X#define SIGZDIV		5
X#define SIGCHK		6
X#define SIGTRAP		7
X#define SIGPRIV		8
X#define SIGTRACE	9
X
X
X#define	SIGINT		10		/* ^C (struct tchars t_intc) */
X#define	SIGQUIT		11		/* ^\ (struct tchars t_quitc) */
X#define SIGTSTP		12		/* ^Z (struct tchars t_suspc) */
X#define SIGFPE		13		/* floating point exception */
X#define SIGHUP		14		/* hangup */
X#define SIGABRT		15		/* abnormal termination */
X#define SIGTERM		16		/* termination request */
X#define SIGUSR1		17		/* user defined signal #1 */
X#define SIGUSR2		18		/* user defined signal #2 */
X
X/* ANSI C requires the following */
X#define SIGSEGV		SIGBUS		/* invalid access to storage */
X
X/* some values that Eunuchs programs seem to want */
X#define SIGIOT	SIGNULL
X#define SIGEMT	SIGNULL
X#define SIGSYS	SIGNULL
X#define SIGSTOP	SIGTSTP
X
Xsig_handler_t	*signal(int sig, sig_handler_t *func);
Xint		raise(int sig);
X#endif	/* _SIGNAL_H */
END_OF_FILE
if test 2052 -ne `wc -c <'include/signal.h'`; then
    echo shar: \"'include/signal.h'\" unpacked with wrong size!
fi
# end of 'include/signal.h'
fi
if test -f 'include/stat.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'include/stat.h'\"
else
echo shar: Extracting \"'include/stat.h'\" \(1664 characters\)
sed "s/^X//" >'include/stat.h' <<'END_OF_FILE'
X/*
X *		Cross Development System for Atari ST 
X *     Copyright (c) 1988, Memorial University of Newfoundland
X *
X *  Fake stat the best we can.  The only field that isn't filled in half-way
X * sensibly in st_ino.  Also put dta struct here for lack of a better place.
X *
X * $Header: stat.h,v 1.1 88/01/29 17:22:33 m68k Exp $
X *
X * $Log:	stat.h,v $
X * Revision 1.1  88/01/29  17:22:33  m68k
X * Initial revision
X * 
X */
X#ifndef _STAT_H
X#define _STAT_H
X
X#ifndef _TYPES_H
X#include <types.h>
X#endif /* _TYPES_H */
X
Xstruct stat {
X	u_short	st_mode;
X	ino_t	st_ino;
X	dev_t	st_dev;
X	short	st_rdev;
X	short	st_nlink;
X	short	st_uid;
X	short	st_gid;
X	off_t	st_size;
X	long	st_blksize;
X	long	st_blocks;
X	time_t	st_mtime;
X	time_t	st_atime;
X	time_t	st_ctime;
X	short	st_attr;
X};
X
X#define	S_IFMT	0170000		/* type of file */
X#define		S_IFDIR	0040000	/* directory */
X#define		S_IFCHR	0020000	/* character special */
X#define		S_IFBLK	0060000	/* block special */
X#define		S_IFREG	0100000	/* regular */
X#define		S_IFIFO	0010000	/* fifo */
X#define	S_ISUID	04000		/* set user id on execution */
X#define	S_ISGID	02000		/* set group id on execution */
X#define	S_ISVTX	01000		/* save swapped text even after use */
X#define	S_IREAD	00400		/* read permission, owner */
X#define	S_IWRITE	00200		/* write permission, owner */
X#define	S_IEXEC	00100		/* execute/search permission, owner */
X
Xstruct _dta {
X	char		dta_buf[21];
X	char		dta_attribute;
X	unsigned short	dta_time;
X	unsigned short	dta_date;
X	long		dta_size;
X	char		dta_name[14];
X};
X
X#define	FA_RDONLY		0x01
X#define	FA_HIDDEN		0x02
X#define	FA_SYSTEM		0x04
X#define	FA_LABEL		0x08
X#define	FA_DIR			0x10
X#define	FA_CHANGED		0x20
X#endif /* _STAT_H */
END_OF_FILE
if test 1664 -ne `wc -c <'include/stat.h'`; then
    echo shar: \"'include/stat.h'\" unpacked with wrong size!
fi
# end of 'include/stat.h'
fi
if test -f 'include/stdio.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'include/stdio.h'\"
else
echo shar: Extracting \"'include/stdio.h'\" \(1990 characters\)
sed "s/^X//" >'include/stdio.h' <<'END_OF_FILE'
X#ifndef STDIO_H
X#define STDIO_H
X/*
X * stdio.h
X *
X * this version kludged up by jrd
X */
X
X/* files are really pointers to something, but that isn't visible to standard
X   code */
X#define	FILE	long
X#define	EOF	-1
X
X#ifndef NULL
X#define NULL	(void *)0
X#endif
X
X/* internal structure defs for FILE structs and the code that hacks on them */
X
X#define BUFSIZE 1024
X
Xstruct file
X	{
X	unsigned char 	open_p;		/* 1-> this one's open */
X	unsigned char	eof_p;		/* 1-> at eof */
X	unsigned char	flags;		/* read and write mode bits */
X	unsigned char	slush;
X	unsigned short	handle;		/* the file_handle GEMDOS gave us */
X	short		buf_index;	/* idx into buf; signed cause it can be
X					   -1 when somebody ungetcs something */
X	short		buf_max;	/* end of valid data in buf */
X	unsigned long	file_position;	/* nbytes into file of buf */
X	int		last_file_error; /* last error encountered */
X	short		unchar_slush;	/* in case we unchar at begin buf */
X	char		buf[BUFSIZE];	/* and the buffer */
X	};
X
X#define file_output_p(f)	\
X	(((f->mode & 0x03) == O_WRONLY) || ((f->mode & 0x03) == O_RDWR))
X
X#define file_input_p(f)	\
X	(((f->mode & 0x03) == O_RDONLY) || ((f->mode & 0x03) == O_RDWR))
X
X#undef BUFSIZE
X
X/* standard files */
Xextern struct file _std_in_out_err[3];
X#define stdin	(FILE *) &_std_in_out_err[0]
X#define stdout	(FILE *) &_std_in_out_err[1]
X#define stderr	(FILE *) &_std_in_out_err[2]
X
X/* and code to hack them */
Xextern FILE * fopen(), * freopen(), * fdopen();
X
Xextern int fileno(FILE *fp);
Xextern int fgetc();
Xextern char * fgets();
Xextern char * gets();
X
X/* more eunuchs compatibility brain damage... */
X#define putc	fputc
X#define	getc	fgetc
X#define putchar(c)	fputc(c, stdout)
X#define getchar()	fgetc(stdin)
X
X/* this is so unbelievably brain-dead I can't think of an epithet
X   that accurately describes it.  No, it has no use at all, other
X   than to support eunuchs code that doesn't believe in modularity
X   or functional boundaries.  That is, most of it.... */
X#define BUFSIZ	512
X#endif /* STDIO_H */
END_OF_FILE
if test 1990 -ne `wc -c <'include/stdio.h'`; then
    echo shar: \"'include/stdio.h'\" unpacked with wrong size!
fi
# end of 'include/stdio.h'
fi
if test -f 'include/stdlib.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'include/stdlib.h'\"
else
echo shar: Extracting \"'include/stdlib.h'\" \(1705 characters\)
sed "s/^X//" >'include/stdlib.h' <<'END_OF_FILE'
X#ifndef _STDLIB_H
X#define _STDLIB_H
X
Xtypedef unsigned long	size_t;
Xtypedef char		wchar_t;
Xtypedef struct {
X		int	quot;
X		int	rem;
X	} div_t;
Xtypedef struct {
X		long	quot;
X		long	rem;
X	} ldiv_t;
X
X#define NULL		(void *) 0
X#define EXIT_FAILURE	1
X#define EXIT_SUCCESS	0
X#define RAND_MAX	0x7FFF
X#define	MB_CUR_MAX	1
X
Xextern double	atof(const char *nptr);
Xextern int	atoi(const char *nptr);
Xextern long int	atol(const char *nptr);
Xextern double	strtod(const char *nptr, char **endptr);
Xextern long int	strtol(const char *nptr, char **endptr, int base);
Xextern unsigned long int strtoul(const char *nptr, char **endptr, int base);
Xextern int	rand(void);
Xextern void	srand(unsigned int seed);
Xextern void	*calloc(size_t nmemb, size_t size);
Xextern void	free(void *ptr);
Xextern void	*malloc(size_t size);
Xextern void	*realloc(void *ptr, size_t size);
Xextern void	abort(void);
Xextern int	atexit(void (*func)(void));
Xextern void	exit(int status);
Xextern char	*getenv(const char *name);
Xextern int	system(const char *string);
X/* bsearch */
X/* qsort */
Xextern int	abs(int j);
X/* div */
Xextern long int	labs(long int j);
X/* ldiv */
X/* mblen */
X/* mbtowc */
X/* wctomb */
X/* mbstowcs */
X/* wcstombs */
Xextern void	*memcpy(void *s1, const void *s2, size_t n);
Xextern void	*memmove(void *s1, const void *s2, size_t n);
Xextern char	*strcpy(char *s1, const char *s2);
Xextern char	*strncpy(char *s1, const char *s2, size_t n);
Xextern char	*strcat(char *s1, const char *s2);
Xextern char	*strncat(char *s1, const char *s2, size_t n);
X/* ... */
Xextern size_t	strlen(const char *s);
X
X/* this was the standard ansi header - and now the gnu cc version of this */
X#ifdef __GNUC__
X#pragma once
X
X#define abs	__builtin_abs
X#endif
X#endif
END_OF_FILE
if test 1705 -ne `wc -c <'include/stdlib.h'`; then
    echo shar: \"'include/stdlib.h'\" unpacked with wrong size!
fi
# end of 'include/stdlib.h'
fi
if test -f 'ioctl.c.cdiff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ioctl.c.cdiff'\"
else
echo shar: Extracting \"'ioctl.c.cdiff'\" \(1934 characters\)
sed "s/^X//" >'ioctl.c.cdiff' <<'END_OF_FILE'
X*** terminator/ioctl.c	Fri Aug 11 18:52:27 1989
X--- new-lib/ioctl.c	Fri Jul 14 20:09:48 1989
X***************
X*** 14,15 ****
X--- 14,16 ----
X   */
X+ #include	<fcntl.h>
X  #include	<ioctl.h>
X***************
X*** 17,19 ****
X--- 18,34 ----
X  #include	"tchars.h"
X+ #include	<osbind.h>
X+ #include	<sysvars.h>
X  
X+ static int
X+ meta_on()
X+ {
X+ 	*conterm |= 8;
X+ }
X+ 
X+ static int
X+ meta_off()
X+ {
X+ 	*conterm &= ~8;
X+ }
X+ 
X  int
X***************
X*** 27,28 ****
X--- 42,44 ----
X  	struct ltchars	*ltc;
X+ 	long	ssp;
X  
X***************
X*** 41,43 ****
X  
X! 	case TIOCSETP:
X  		sg = (struct sgttyb *) arg;
X--- 57,68 ----
X  
X! 	case TIOCSETP:	/* discard input */
X! 		{
X! 			int	old_delay_mode;
X! 			char	ch;
X! 
X! 			old_delay_mode = fcntl(0, F_SETFL, O_NDELAY);
X! 			while (read(0, &ch, 1) == 1);
X! 			fcntl(0, F_SETFL, old_delay_mode);
X! 		}
X! 	case TIOCSETN:
X  		sg = (struct sgttyb *) arg;
X***************
X*** 45,46 ****
X--- 70,78 ----
X  		__tchars[TC_KILL] = sg->sg_kill;
X+ 		if (sg->sg_flags & META)
X+ 			__keytab = (KEYTAB *) Keytbl(-1,-1,-1);
X+ 		if (sg->sg_flags & META) {
X+ 			Supexec(meta_on);
X+ 		} else {
X+ 			Supexec(meta_off);
X+ 		}
X  		__ttymode = sg->sg_flags;
X***************
X*** 68,73 ****
X  		ltc = (struct ltchars *) arg;
X! 		ltc->t_suspc = TC_UNDEF;
X! 		ltc->t_dsuspc = TC_UNDEF;
X  		ltc->t_rprntc = __tchars[TC_RPRNTC];
X! 		ltc->t_flushc = TC_UNDEF;
X  		ltc->t_werasc = __tchars[TC_WERASC];
X--- 100,105 ----
X  		ltc = (struct ltchars *) arg;
X! 		ltc->t_suspc = __tchars[TC_SUSPC];
X! 		ltc->t_dsuspc = __tchars[TC_DSUSPC];
X  		ltc->t_rprntc = __tchars[TC_RPRNTC];
X! 		ltc->t_flushc = __tchars[TC_FLUSHC];
X  		ltc->t_werasc = __tchars[TC_WERASC];
X***************
X*** 78,80 ****
X--- 110,115 ----
X  		ltc = (struct ltchars *) arg;
X+ 		__tchars[TC_SUSPC] = ltc->t_suspc;
X+ 		__tchars[TC_DSUSPC] = ltc->t_dsuspc;
X  		__tchars[TC_RPRNTC] = ltc->t_rprntc;
X+ 		__tchars[TC_FLUSHC] = ltc->t_flushc;
X  		__tchars[TC_WERASC] = ltc->t_werasc;
END_OF_FILE
if test 1934 -ne `wc -c <'ioctl.c.cdiff'`; then
    echo shar: \"'ioctl.c.cdiff'\" unpacked with wrong size!
fi
# end of 'ioctl.c.cdiff'
fi
if test -f 'open.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'open.c'\"
else
echo shar: Extracting \"'open.c'\" \(2057 characters\)
sed "s/^X//" >'open.c' <<'END_OF_FILE'
X/*
X *		Cross Development System for Atari ST 
X *     Copyright (c) 1988, Memorial University of Newfoundland
X *
X * er: added O_NDELAY, /dev/null, fstat()-support
X *
X *  Tries to emulate unix open3.  The mode argument is ignored, and O_NDELAY
X * doesn't do anything.  Also O_APPEND does not garentee that things will
X * be written to the end - all we can do is seek to the end to start with.
X *
X * $Header: open.c,v 1.2 88/01/29 17:31:36 m68k Exp $
X *
X * $Log:	open.c,v $
X *
X * Modified by jrd for native gcc 1.2
X *
X * Revision 1.2  88/02/24  17:31:36  m68k
X * 
X */
X#include	<types.h>
X#include	<file.h>
X#include	<stat.h>
X#include	<errno.h>
X#include	<osbind.h>
X
X#ifdef DEBUG
Xextern int stderr;
X#endif
X
Xint open(p, flags, mode)
Xchar	* p;
Xshort	flags;
Xu_short	mode;
X{
X  char		path[strlen(p)+1];
X  int		fd;
X  int		exists;
X  extern char	*malloc();
X  u_short	create_mode = 0;
X  int	len;
X
X  if(!strcmp(p,"/dev/null")) return(1234);
X  len = strlen(p) + 1;
X  strcpy(path,p);
X  unix_to_tos(path);
X  switch (flags & 0x3) {
X  case O_RDONLY:
X    fd = Fopen(path, O_RDONLY);
X    break;
X  case O_WRONLY:
X  case O_RDWR:
X    fd = 0;
X    exists = Fattrib(path, 0, 0) >= 0;
X    if (flags & O_CREAT) {
X      if ((flags & O_EXCL) && exists)
X	fd = - EEXIST;
X    } else if (!exists) fd = - ENOENT;
X    if (!fd) {
X      if ((flags & O_TRUNC) || !exists) {
X	if (!(mode & S_IREAD))
X	  create_mode |= FA_HIDDEN;
X	if (!(mode & S_IWRITE))
X	  create_mode |= FA_RDONLY;
X	if ((fd = Fcreate(path, create_mode)) >= 0
X	    && (flags & 0x3) == O_RDWR) {
X	  (void) Fclose(fd);
X	  fd = Fopen(path, O_RDWR);
X	}
X      } else if ((fd = Fopen(path, flags & 0x3)) >= 0
X		 && (flags & O_APPEND))
X	(void) Fseek(0L, fd, L_XTND);
X    }
X    break;
X    
X  default:
X    fd = - EINVAL;
X  }
X  if (fd < 0) {
X    errno = -fd;
X    fd = -1;
X  } else if (fd < N_HANDLES) {
X    if(flags & O_NDELAY)
X      __handle_stat[fd] |= O_NDELAY;
X    if(__handle_to_name[fd] = malloc(len))
X      strcpy(__handle_to_name[fd],p);
X  }
X#ifdef DEBUG
X  fprintf(stderr, "open('%s', %X)->%d\n", path, flags, fd);
X#endif
X  return fd;
X}
END_OF_FILE
if test 2057 -ne `wc -c <'open.c'`; then
    echo shar: \"'open.c'\" unpacked with wrong size!
fi
# end of 'open.c'
fi
if test -f 'opendir.c.cdiff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'opendir.c.cdiff'\"
else
echo shar: Extracting \"'opendir.c.cdiff'\" \(2772 characters\)
sed "s/^X//" >'opendir.c.cdiff' <<'END_OF_FILE'
X*** terminator/opendir.c	Fri Aug 11 18:52:45 1989
X--- new-lib/opendir.c	Tue Aug 15 17:40:08 1989
X***************
X*** 84,91 ****
X  
X  DIR	*
X! opendir(name)
X! 	char	*name;
X  {
X  	DIR			*dirp;
X- 	char			c;
X  	char			*s;
X--- 84,94 ----
X  
X+ extern DIR	*_current_open_directory; /* in stat.c */
X+ static int	dirnumber = 0;
X+ 
X  DIR	*
X! opendir(n)
X! 	char	*n;
X  {
X+ 	char			*name;
X  	DIR			*dirp;
X  	char			*s;
X***************
X*** 93,95 ****
X--- 96,101 ----
X  	char			nbuf[MAXPATHLEN + 1];
X+ 	int			len;
X  	
X+ 	name = malloc(strlen(n)+1);
X+ 	strcpy(name,n);
X  #ifdef	MSDOS
X***************
X*** 106,107 ****
X--- 112,115 ----
X  	{
X+ 		struct	stat		statb;
X+ 
X  		/* This bit of nastyness is due to the fact that Fattrib()
X***************
X*** 110,111 ****
X--- 118,120 ----
X  		 */
X+ 		unix_to_tos(name);
X  		if (index(name, '*') || index(name, '?'))
X***************
X*** 112,114 ****
X--- 121,128 ----
X  			return (DIR *) NULL;
X+ 		if (stat(name, &statb) < 0
X+ 			|| (statb.st_mode & S_IFMT) != S_IFDIR)
X+ 				return (DIR *) NULL;
X  		setdta();
X+ #ifdef old_code
X+ 		/* this old code could never deal with root directories */
X  		if (getdirent(name) == (char *) NULL ||
X***************
X*** 116,117 ****
X--- 130,132 ----
X  				return (DIR *) NULL;
X+ #endif
X  	}
X***************
X*** 120,125 ****
X  		return (DIR *) NULL;
X! 	if (*name && (c = name[strlen(name) - 1]) != '\\' && c != '/')
X! 		(void) strcat(strcpy(nbuf, name), "\\*.*");
X! 	else
X! 		(void) strcat(strcpy(nbuf, name), "*.*");
X  	dirp->dd_loc = 0;
X--- 135,140 ----
X  		return (DIR *) NULL;
X! 	len = strlen(name) - 1;
X! 	if (len >= 0 && name[len] == '\\')
X! 		name[len] = '\0';
X! 	(void) strcat(strcpy(nbuf, name), "\\*.*");
X  	dirp->dd_loc = 0;
X***************
X*** 126,127 ****
X--- 141,155 ----
X  	dirp->dd_contents = dirp->dd_cp = (struct _dircontents *) NULL;
X+ 	/* the following code helps optimization in stat() and fstat() */
X+ 	if(*name == '.' && !name[1]) {	/* directory is '.' */
X+ 		/* don't care about '..' or other strange variants */
X+ 		char	namebuf[MAXPATHLEN + 1];
X+ 		extern char	*realloc();
X+ 
X+ 		Dgetpath(namebuf, 0);
X+ 		name = realloc(name, strlen(namebuf)+1);
X+ 		strcpy(name,namebuf);
X+ 	}
X+ 	dirp->dd_name = name;
X+ 	dirp->dd_next = _current_open_directory;
X+ 	_current_open_directory = dirp;
X  	if ((s = getdirent(nbuf)) == (char *) NULL)
X***************
X*** 141,143 ****
X--- 169,176 ----
X  			dirp->dd_contents = dirp->dd_cp = dp;
X+ 		tos_to_unix(s);
X  		(void) strcpy(dp->_d_entry, s);
X+ 		dp->_d_attr = dtabuf.dta_attribute;
X+ 		dp->_d_date = dtabuf.dta_date;
X+ 		dp->_d_time = dtabuf.dta_time;
X+ 		dp->_d_size = dtabuf.dta_size;
X  		dp->_d_next = (struct _dircontents *) NULL;
X***************
X*** 145,146 ****
X--- 178,180 ----
X  	dirp->dd_cp = dirp->dd_contents;
X+ 	dirp->dd_id = ++dirnumber;
X  
END_OF_FILE
if test 2772 -ne `wc -c <'opendir.c.cdiff'`; then
    echo shar: \"'opendir.c.cdiff'\" unpacked with wrong size!
fi
# end of 'opendir.c.cdiff'
fi
if test -f 'st-error.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'st-error.c'\"
else
echo shar: Extracting \"'st-error.c'\" \(1745 characters\)
sed "s/^X//" >'st-error.c' <<'END_OF_FILE'
X
X/* does this replace some Eunuchs thing?  Who knows, in this kludge of a 
X * language.  In any event, input-scrub.c wants it; nobody else seems to use 
X * it.
X */
X
X/* apparently Eunuchs has a similar thing, but their error numbers
X   go up from 0.  We'll hack things a bit so as to allow negative offsets
X   from sys_errlist to get the right strings here */
X
X#include <errno.h>
X
Xint sys_nerr = 67;			/* max known error number */
Xint errno = 0;				/* current error num */
X
X/* this, of course, must follow the above immediately.  We rely
X   on GCC optimizing this into a reference to the duplicate string, above */
Xchar * sys_errlist[] = 
X	{
X	"No error",
X	"Generic bogosity",		/* -1 */
X	"Drive not ready",
X	"Unknown command",
X	"CRC error",
X	"Bad request",
X	"Seek error",
X	"Unknown media",
X	"Sector not found",
X	"Paper out",
X	"Write fault",
X	"Read fault",
X	"Random bogons",
X	"Write protected",
X	"Media change",
X	"Unknown device",
X	"Bad sectors",
X	"Insert disk",
X	"", "", "", "", "", "", 	/* -23 .. -18 */
X	"", "", "", "", "", "", "", "",	/* -31 .. -24 */
X	"Invalid function number",
X	"File not found",
X	"Path not found",
X	"Too many open files",
X	"Access denied",
X	"Invalid file handle",
X	"",				/* -38 */
X	"Not enough memory",
X	"Memory fault",
X	"", "", "", "", "",
X	"Invalid drive",
X	"",				/* -47 */
X	"Cross device rename",
X	"No more files",
X	"", "", "", "", "", "",		/* -55 .. -50 */
X	"", "", "", "", "", "",
X	"Math function argument error",
X	"Result out of range",	/* -63 .. -56 */
X	"Bad arg",			/* -64 */
X	"Internal error",
X	"Not an executable",
X	"Error setting block size",	/* -67 */
X	"System error",			/* min-error minus 1 */
X	};
X
Xchar * sys_error(num)
Xint num;
X{
X  if ((num > sys_nerr) || (num < 0))
X	num = 0;
X  return(sys_errlist[num]);
X}
END_OF_FILE
if test 1745 -ne `wc -c <'st-error.c'`; then
    echo shar: \"'st-error.c'\" unpacked with wrong size!
fi
# end of 'st-error.c'
fi
if test -f 'std-init.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'std-init.c'\"
else
echo shar: Extracting \"'std-init.c'\" \(1695 characters\)
sed "s/^X//" >'std-init.c' <<'END_OF_FILE'
X/* this is a sort of standard init frobule for general purpose
X   c programs.  You can replace it if you want something that 
X   doesn't drag in half the known universe at link time.
X*/
X
X#include <stdio.h>
X#include <file.h>
X#include <time.h>
X
X#undef stdin
X#undef stdout
X#undef stderr
X
X/* Some programs (like lex) think that they can use 'FILE *f = stdin' to */
X/* initialize f. If we collect these three file structures in an array - */
X/* we would need them anyway - these programs will not loose anymore.    */
Xstruct file _std_in_out_err[3];
Xstruct file * stdin = NULL;	/* these variables are for older programs */
Xstruct file * stdout = NULL;
Xstruct file * stderr = NULL;
X
Xstatic struct file * _fdopen(f, handle, mode)
Xstruct file * f;
Xint handle;
Xchar * mode;
X{
X  f->handle = handle;
X
X/* I guess we have to trust that the mode string passed in matches the
X   one the handle was opened with ?!?  What a crock... */
X  f->flags = _parse_open_options(mode); 
X  f->file_position = 0;
X/* should really check first... */
X  f->eof_p = 0;
X  f->buf_index = 0;
X  f->buf_max = 0;
X  f->open_p = 1;
X  f->last_file_error = 0;
X}
X
Xextern clock_t	_start_time;	/* defined in clock.c */
X
Xint _main (n_args, args, env)
Xint n_args;
Xchar ** args;
Xchar * env;		/* is this right? */
X{
X  int return_code;
X
X  _start_time = clock();
X  stdin = &_std_in_out_err[0];
X  stdout = &_std_in_out_err[1];
X  stderr = &_std_in_out_err[2];
X  _fdopen(stdin, 0, "r");
X  _fdopen(stdout, 1, "a");
X  _fdopen(stderr, 2, "w+");
X
X  return_code = main(n_args, args, env);
X
X  fflush(stdin);		/* just fflush, it's closed by the OS */
X  fflush(stdout);
X  fflush(stderr);
X
X  return(return_code);		/* some programs want to return a status */
X}
END_OF_FILE
if test 1695 -ne `wc -c <'std-init.c'`; then
    echo shar: \"'std-init.c'\" unpacked with wrong size!
fi
# end of 'std-init.c'
fi
if test -f 'time.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'time.c'\"
else
echo shar: Extracting \"'time.c'\" \(1617 characters\)
sed "s/^X//" >'time.c' <<'END_OF_FILE'
X
X/* julian date */
X/* 
X * time() - liefert die anzahl der sekunden seit 1.1.1970 0:00:00 GMT 
X *
X * stefan brueck 12/88
X * - korrektur 1980 -> 1970
X * - schaltjahre werden beruecksichtigt
X */
X
X#include <osbind.h>
X
X/* days in months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
X
Xshort month_days[] = {	0,
X			31, 
X			31 + 28,
X			31 + 28 + 31,
X			31 + 28 + 31 + 30,
X			31 + 28 + 31 + 30 + 31,
X			31 + 28 + 31 + 30 + 31 + 30,
X			31 + 28 + 31 + 30 + 31 + 30 + 31,
X			31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
X			31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
X			31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
X			31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30
X			};
X
Xlong _time(place, tostime)
Xlong * place;
Xlong tostime;
X{
X  int today, now;
X  int year, month, day, hour, min, sec;
X  int leap_years;
X  long result;
X
X  today = (tostime >> 16) & 0xFFFF;
X  now 	= tostime & 0xFFFF;
X  year 	= ((today >> 9) & 0x7F);	/* since 1980!! */
X  year 	+= 10;				/* since 1970 	*/
X  month = (today >> 5) & 0x0F;
X  if ((month < 1) || (month > 12))
X	month = 1;
X  day 	= today & 0x1F;
X  hour 	= (now >> 11) & 0x1F;
X  min 	= (now >> 5) & 0x3F;
X  sec 	= (now & 0x01F) << 1;
X
X  result = 	sec + 
X		(min * 60) + 
X		(hour * 3600) + 
X		((day-1 + month_days[month-1]) * 86400) +
X		year * 31536000;
X
X	/* schaltjahre hinzuaddieren */
X	leap_years = (year + 1) >> 2;		/* since 1970 */
X	if (!((year+2) & 3) && month > 2)	/* im schaltjahr */
X		leap_years++;
X	result += leap_years * 86400;
X
X  if (place)
X	*place = result;
X  return(result);
X}
X
Xlong time(place)
Xlong *place;
X{
X  return _time(place,Gettime());	/* XBIOS = hardwareclock/ikbd */
X}
END_OF_FILE
if test 1617 -ne `wc -c <'time.c'`; then
    echo shar: \"'time.c'\" unpacked with wrong size!
fi
# end of 'time.c'
fi
if test -f 'trap-1.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'trap-1.c'\"
else
echo shar: Extracting \"'trap-1.c'\" \(1609 characters\)
sed "s/^X//" >'trap-1.c' <<'END_OF_FILE'
Xextern char	_in_trap;
X
Xint trap_1_wwlll(args)
Xlong args;
X{
X/* arg[0] is at a6@(8) */
X
X  asm("movel a6@(24),sp@-");		/* copy l3 */
X  asm("movel a6@(20),sp@-");		/* copy l2 */
X  asm("movel a6@(16),sp@-");		/* copy l1 */
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #1");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #12,sp");			/* pop junk off stack */
X}
X
Xint trap_1_wlww(args)
Xlong args;
X{
X  asm("movel a6@(20),d0");		/* copy w3 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(16),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(12),sp@-");		/* copy l1 */
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #1");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #10,sp");			/* pop junk off stack */
X}
X
Xint trap_1_www(args)
Xlong args;
X{
X  asm("movel a6@(16),d0");		/* copy w3 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #1");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #6,sp");			/* pop junk off stack */
X}
X
Xint trap_1_wl(args)
Xlong args;
X{
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movel d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #1");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #6,sp");			/* pop junk off stack */
X}
END_OF_FILE
if test 1609 -ne `wc -c <'trap-1.c'`; then
    echo shar: \"'trap-1.c'\" unpacked with wrong size!
fi
# end of 'trap-1.c'
fi
if test -f 'trap-13.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'trap-13.c'\"
else
echo shar: Extracting \"'trap-13.c'\" \(1792 characters\)
sed "s/^X//" >'trap-13.c' <<'END_OF_FILE'
X
Xint trap_13_www(args)
Xlong args;
X{
X/* arg[0] is at a6@(8) */
X/* push w, w, w.  more later? */
X
X  asm("moveml #0x3FFC,sp@-");		/* save all regs... */
X  asm("movel a6@(16),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #13");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #6,sp");			/* pop junk off stack */
X  asm("moveml sp@+,#0x3FFC");		/* restore regs */
X}
X
Xint trap_13_wwl(args)
Xlong args;
X{
X/* arg[0] is at a6@(8) */
X/* push w, w, l.  more later? */
X
X  asm("moveml #0x3FFC,sp@-");		/* save all regs... */
X  asm("movel a6@(16),sp@-");		/* copy l1 */
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #13");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #8,sp");			/* pop junk off stack */
X  asm("moveml sp@+,#0x3FFC");		/* restore regs */
X}
X
X
Xint trap_13_wwlwww(args)
Xlong args;
X{
X/* arg[0] is at a6@(8) */
X/* push w, w, l.  more later? */
X
X  asm("moveml #0x3FFC,sp@-");		/* save all regs... */
X  asm("movel a6@(28),d0");		/* copy w5 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(24),d0");		/* copy w4 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(20),d0");		/* copy w3 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(16),sp@-");		/* copy l1 */
X  asm("movel a6@(12),d0");		/* copy w2 */
X  asm("movew d0,sp@-");
X  asm("movel a6@(8),d0");		/* copy w1 */
X  asm("movew d0,sp@-");
X  asm("bset #0, __in_trap");
X  asm("trap #13");			/* do the trap */
X  asm("bclr #0, __in_trap");
X  asm("addl #14,sp");			/* pop junk off stack */
X  asm("moveml sp@+,#0x3FFC");		/* restore regs */
X}
X
END_OF_FILE
if test 1792 -ne `wc -c <'trap-13.c'`; then
    echo shar: \"'trap-13.c'\" unpacked with wrong size!
fi
# end of 'trap-13.c'
fi
if test -f 'write.c.cdiff' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'write.c.cdiff'\"
else
echo shar: Extracting \"'write.c.cdiff'\" \(1631 characters\)
sed "s/^X//" >'write.c.cdiff' <<'END_OF_FILE'
X*** terminator/write.c	Fri Aug 11 18:53:23 1989
X--- new-lib/write.c	Wed Aug 16 19:11:15 1989
X***************
X*** 8,9 ****
X--- 8,14 ----
X   *
X+  * 1.4	er
X+  * Added /dev/null special case
X+  * Moved __col_pos from read.c to write.c because this code is always needed by
X+  * fflush in exit.c
X+  *
X   * 1.3	jrd
X***************
X*** 17,19 ****
X   */
X- /* #include	<gembios.h>	?? */
X  #include <osbind.h>
X--- 22,23 ----
X***************
X*** 27,32 ****
X  
X! int write(fd, buf, nbytes)
X! int fd;
X! char *buf;
X! unsigned int nbytes;
X  {
X--- 31,36 ----
X  
X! int	__col_pos = 0;
X! 
X! int
X! write(int fd, char *buf, unsigned int nbytes)
X  {
X***************
X*** 36,39 ****
X  
X- extern	int	__col_pos;
X- 
X  int _write_internal(fd, buf, nbytes, binary_p)
X--- 40,41 ----
X***************
X*** 45,47 ****
X--- 47,52 ----
X    char	*s;
X+   int	retval;
X  
X+   if (fd == 1234) return(nbytes);	/* /dev/null */
X+ 
X  #ifdef DEBUG
X***************
X*** 49,50 ****
X--- 54,56 ----
X  	fprintf(stderr, "write_internal(%d, %X, %d, %d)\n", fd, buf, nbytes, binary_p);
X+ 	return Fwrite(fd, nbytes, buf);
X  #endif
X***************
X*** 62,63 ****
X--- 68,71 ----
X  	}
X+ 
X+   retval = nbytes;
X    for (s = buf ; nbytes > 0 ; s++, nbytes-- )
X***************
X*** 82,84 ****
X  		    else
X! 		if (*s >= ' ' && *s < 0177)
X  			__col_pos++;
X--- 90,94 ----
X  		    else
X! 		if (*s >= ' ') 		    /* the ST *HAS* printable chars */
X! 		                            /* above 0177 (ever heard about */
X! 		                            /* non american users ???) */
X  			__col_pos++;
X***************
X*** 89,91 ****
X  		}
X!   return nbytes;
X  }
X--- 99,101 ----
X  		}
X!   return retval;
X  }
END_OF_FILE
if test 1631 -ne `wc -c <'write.c.cdiff'`; then
    echo shar: \"'write.c.cdiff'\" unpacked with wrong size!
fi
# end of 'write.c.cdiff'
fi
echo shar: End of archive 3 \(of 7\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0