
/*
	poor BSD implementations of POSIX termios and wait calls
	good enough to get rc working on SunOS 3
*/

#ifdef _POSIX_SOURCE

/* POSIX doesn't grok VLNEXT */
#undef _POSIX_SOURCE
/* but AIX's idea of POSIX, well... */
#ifdef AIX
#define _POSIX_SOURCE
#endif

#include <sys/ioctl.h>

	#ifdef SOLARIS
	#define __EXTENSIONS__
	#endif
#include <termios.h>
	#ifdef SOLARIS
	#undef __EXTENSIONS__
	#endif

#undef _POSIX_SOURCE
#define _POSIX_SOURCE

#include <sys/types.h>
#include <sys/wait.h>

#elif defined (USE_TERMIO)

#include <sys/ioctl.h>
#include <termio.h>

#define termios termio

#define TCIFLUSH 0
#define TCOFLUSH 1
#define TCIOFLUSH 2

#define TCSANOW TCSETA
#define TCSADRAIN TCSETAW
#define TCSAFLUSH TCSETAF

#else

#include <sys/ioctl.h>
#include <sgtty.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/resource.h>
#include <signal.h>
#include "posix_wait.h"

#define SIG_BLOCK 0
#define SIG_UNBLOCK 1
#define SIG_SETMASK 2

extern int wait3 (union wait *, int, struct rusage *);
extern int sigvec(int sig, struct sigvec *vec, struct sigvec *ovec);
extern int sigsetmask (int mask);


#define NCCS 16

struct termios {
	struct sgttyb sgttyb;
	struct tchars tchars;
	int lmode;
	struct ltchars ltchars;
	unsigned    long    c_iflag;/* input modes */
	unsigned    long    c_oflag;/* output modes */
	unsigned    long    c_cflag;/* control modes */
	unsigned    long    c_lflag;/* local modes */
	unsigned    char    c_line;/* line discipline */
	unsigned    char    c_cc[NCCS];/* control chars */
};

#define OPOST	0x01
#define ONLCR	0x04
#define ISIG	0x01
#define ISTRIP 0x20
#define ICANON 0x02
#define ICRNL	0x100
#define ECHOK	0x20

#define VINTR	0
#define VQUIT	1
#define VERASE	2
#define VKILL	3
#define VEOF	4
#define VEOL	5
#define VSTART	7
#define VSTOP	8
#define VSUSP	9
#define VMIN	4
#define VTIME	5
#define VDSUSP	10
#define VREPRINT	11
#define VDISCRD	12
#define VWERSE	13
#define VLNEXT	14

#include <sys/file.h>

#define TCIOFLUSH 0
#define TCIFLUSH FREAD
#define TCOFLUSH FWRITE

#define TCSANOW TIOCSETN
#define TCSADRAIN TIOCSETP		/* this flushes too - no proper implementation possible */
#define TCSAFLUSH TIOCSETP

#endif


#ifndef _POSIX_SOURCE

extern int tcdrain (int fildes);

extern int tcflush (int fildes, int queue_selector);

extern int tcgetattr (int fildes, struct termios *termios_p);
extern int tcsetattr (int fildes, int opt_actions, struct termios *termios_p);

extern pid_t tcgetpgrp (int fildes);
extern int tcsetpgrp (int fildes, pid_t pgrp_id);

extern pid_t waitpid (pid_t pid, int *statptr, int options);

struct sigaction {
	void	(*sv_handler) (int);		/* signal handler */
	int	sv_mask;						/* signal mask to apply */
	int	sv_flags;					/* see signal options below */
};
#define sa_handler sv_handler
#define sa_mask sv_mask
#define sa_flags sv_flags
#define sigset_t int

extern int sigaction (int sig, struct sigaction *act, struct sigaction *oact);
extern int sigprocmask (int operation, sigset_t *set, sigset_t *oset);
extern int sigemptyset (sigset_t *set);
extern int sigaddset (sigset_t *set, int signo);

#endif

