//lib/unpipc.h
/*   . */

#ifndef	__unpipc_h
#define	__unpipc_h

#include	"../config.h"	/*    */
							/* "../config.h"   configure */

/*    #include,   
   ../aclocal.m4  ../configure.in,    configure */

#include	<sys/types.h>	/*    */
#include	<sys/time.h>	/*  timeval{}  select() */
#include	<time.h>		/* timespec{}  pselect() */
#include	<errno.h>
#include	<fcntl.h>		/*   */
#include	<limits.h>		/* PIPE_BUF */
#include	<signal.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<sys/stat.h>	/*      S_xxx */
#include	<unistd.h>
#include	<sys/wait.h>

#ifdef	HAVE_MQUEUE_H
# include	<mqueue.h>		/*   Posix */
#endif

#ifdef	HAVE_SEMAPHORE_H
# include	<semaphore.h>	/*  Posix */

#ifndef	SEM_FAILED
#define	SEM_FAILED	((sem_t *)(-1))
#endif

#endif

#ifdef	HAVE_SYS_MMAN_H
# include	<sys/mman.h>	/*   Posix */
#endif

#ifndef	MAP_FAILED
#define	MAP_FAILED	((void *)(-1))
#endif

#ifdef	HAVE_SYS_IPC_H
# include	<sys/ipc.h>		/* System V IPC */
#endif

#ifdef	HAVE_SYS_MSG_H
# include	<sys/msg.h>		/*   System V */
#endif

#ifdef	HAVE_SYS_SEM_H
#ifdef	__bsdi__
#undef	HAVE_SYS_SEM_H		/*  :  semctl()  BSDI's  */
#else
# include	<sys/sem.h>		/*  System V */
#endif

#ifndef	HAVE_SEMUN_UNION
/* $$.It semun$$ */
union semun {				/*    semctl() */
  int              val;
  struct semid_ds *buf;
  unsigned short  *array;
};
#endif
#endif	/* HAVE_SYS_SEM_H */

#ifdef	HAVE_SYS_SHM_H
# include	<sys/shm.h>		/*   System V */
#endif

#ifdef	HAVE_SYS_SELECT_H
# include	<sys/select.h>	/*   */
#endif

#ifdef	HAVE_POLL_H
# include	<poll.h>		/*   */
#endif

#ifdef	HAVE_STROPTS_H
# include	<stropts.h>		/*   */
#endif

#ifdef	HAVE_STRINGS_H
# include	<strings.h>		/*   */
#endif

/*       ioctl   :
 * <sys/ioctl.h>, <sys/filio.h>,  <sys/sockio.h>.
 */
#ifdef	HAVE_SYS_IOCTL_H
# include	<sys/ioctl.h>
#endif
#ifdef	HAVE_SYS_FILIO_H
# include	<sys/filio.h>
#endif

#ifdef	HAVE_PTHREAD_H
# include	<pthread.h>
#endif

#ifdef	HAVE_DOOR_H
# include	<door.h>		/*   Solaris */
#endif

#ifdef	HAVE_RPC_RPC_H
#ifdef _PSX4_NSPACE_H_TS	/*  Digital Unix 4.0b */
#undef	SUCCESS
#endif
# include	<rpc/rpc.h>		/* Sun RPC */
#endif

/*  bzero()          */
#ifndef	HAVE_BZERO
#define	bzero(ptr,n)		memset(ptr, 0, n)
#endif

/* Posix.1g ,  INFTIM   <poll.h>,           <sys/stropts.h>.          ,    INFTM .   ,   ,    -1 */
#ifndef INFTIM
#define INFTIM          (-1)    /*    */
#ifdef	HAVE_POLL_H
#define	INFTIM_UNPH				/*    unpxti.h ,    */
#endif
#endif

/*   */
#ifndef	PATH_MAX			/*    <limits.h> */
#define	PATH_MAX	1024	/*        */
#endif

#define	MAX_PATH	1024
#define	MAXLINE		4096	/*    */
#define	BUFFSIZE	8192	/*      */

#define	FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
					/*       */
#define	DIR_MODE	(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
					/*       */
#define	SVMSG_MODE	(MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
					/*        System V */
#define	SVSEM_MODE	(SEM_R | SEM_A | SEM_R>>3 | SEM_R>>6)
					/*       System V */
#define	SVSHM_MODE	(SHM_R | SHM_W | SHM_R>>3 | SHM_R>>6)
					/*        System V */

typedef	void	Sigfunc(int);	/*    */

#ifdef	HAVE_SIGINFO_T_STRUCT
typedef	void	Sigfunc_rt(int, siginfo_t *, void *);
#endif

#define	min(a,b)	((a) < (b) ? (a) : (b))
#define	max(a,b)	((a) > (b) ? (a) : (b))

#ifndef	HAVE_TIMESPEC_STRUCT
struct timespec {
  time_t	tv_sec;		/*  */
  long		tv_nsec;	/*   */
};
#endif

/*
 - open(), mq_open(), sem_open()        va_XXX().      mode_t,      BSD/OS,      16- .      16-   32-.    ,   .
 */

#ifdef	__bsdi__
#define	va_mode_t	int
#else
#define	va_mode_t	mode_t
#endif

		/*    */
#define	read_lock(fd, offset, whence, len) \
			lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
#define	readw_lock(fd, offset, whence, len) \
			lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
#define	write_lock(fd, offset, whence, len) \
			lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
#define	writew_lock(fd, offset, whence, len) \
			lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
#define	un_lock(fd, offset, whence, len) \
			lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
#define	is_read_lockable(fd, offset, whence, len) \
			lock_test(fd, F_RDLCK, offset, whence, len)
#define	is_write_lockable(fd, offset, whence, len) \
			lock_test(fd, F_WRLCK, offset, whence, len)
