zoukankan      html  css  js  c++  java
  • code相关头文件

    unpipc.h

    /* include unpipch */
    /* Our own header.  Tabs are set for 4 spaces, not 8 */
    
    #ifndef	__unpipc_h
    #define	__unpipc_h
    
    #include	"../config.h"	/* configuration options for current OS */
    							/* "../config.h" is generated by configure */
    
    /* If anything changes in the following list of #includes, must change
       ../aclocal.m4 and ../configure.in also, for configure's tests. */
    
    #include	<sys/types.h>	/* basic system data types */
    #include	<sys/time.h>	/* timeval{} for select() */
    #include	<time.h>		/* timespec{} for pselect() */
    #include	<errno.h>
    #include	<fcntl.h>		/* for nonblocking */
    #include	<limits.h>		/* PIPE_BUF */
    #include	<signal.h>
    #include	<stdio.h>
    #include	<stdlib.h>
    #include	<string.h>
    #include	<sys/stat.h>	/* for S_xxx file mode constants */
    #include	<unistd.h>
    #include	<sys/wait.h>
    
    #ifdef	HAVE_MQUEUE_H
    # include	<mqueue.h>		/* Posix message queues */
    #endif
    
    #ifdef	HAVE_SEMAPHORE_H
    # include	<semaphore.h>	/* Posix semaphores */
    
    #ifndef	SEM_FAILED
    #define	SEM_FAILED	((sem_t *)(-1))
    #endif
    
    #endif
    
    #ifdef	HAVE_SYS_MMAN_H
    # include	<sys/mman.h>	/* Posix shared memory */
    #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 message queues */
    #endif
    
    #ifdef	HAVE_SYS_SEM_H
    #ifdef	__bsdi__
    #undef	HAVE_SYS_SEM_H		/* hack: BSDI's semctl() prototype is wrong */
    #else
    # include	<sys/sem.h>		/* System V semaphores */
    #endif
    
    #ifndef	HAVE_SEMUN_UNION
    /* $$.It semun$$ */
    union semun {				/* define union for 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 shared memory */
    #endif
    
    #ifdef	HAVE_SYS_SELECT_H
    # include	<sys/select.h>	/* for convenience */
    #endif
    
    #ifdef	HAVE_POLL_H
    # include	<poll.h>		/* for convenience */
    #endif
    
    #ifdef	HAVE_STROPTS_H
    # include	<stropts.h>		/* for convenience */
    #endif
    
    #ifdef	HAVE_STRINGS_H
    # include	<strings.h>		/* for convenience */
    #endif
    
    /* Next three headers are normally needed for socket/file ioctl's:
     * <sys/ioctl.h>, <sys/filio.h>, and <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 doors API */
    #endif
    
    #ifdef	HAVE_RPC_RPC_H
    #ifdef _PSX4_NSPACE_H_TS	/* Digital Unix 4.0b hack, hack, hack */
    #undef	SUCCESS
    #endif
    # include	<rpc/rpc.h>		/* Sun RPC */
    #endif
    
    /* Define bzero() as a macro if it's not in standard C library. */
    #ifndef	HAVE_BZERO
    #define	bzero(ptr,n)		memset(ptr, 0, n)
    #endif
    
    /* Posix.1g requires that an #include of <poll.h> DefinE INFTIM, but many
       systems still DefinE it in <sys/stropts.h>.  We don't want to include
       all the streams stuff if it's not needed, so we just DefinE INFTIM here.
       This is the standard value, but there's no guarantee it is -1. */
    #ifndef INFTIM
    #define INFTIM          (-1)    /* infinite poll timeout */
    #ifdef	HAVE_POLL_H
    #define	INFTIM_UNPH				/* tell unpxti.h we defined it */
    #endif
    #endif
    
    /* Miscellaneous constants */
    #ifndef	PATH_MAX			/* should be in <limits.h> */
    #define	PATH_MAX	1024	/* max # of characters in a pathname */
    #endif
    
    #define	MAX_PATH	1024
    /* $$.ix [MAX_PATH]~constant,~definition~of$$ */
    #define	MAXLINE		4096	/* max text line length */
    /* $$.ix [MAXLINE]~constant,~definition~of$$ */
    /* $$.ix [BUFFSIZE]~constant,~definition~of$$ */
    #define	BUFFSIZE	8192	/* buffer size for reads and writes */
    
    #define	FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
    					/* default permissions for new files */
    /* $$.ix [FILE_MODE]~constant,~definition~of$$ */
    #define	DIR_MODE	(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
    					/* default permissions for new directories */
    /* $$.ix [DIR_MODE]~constant,~definition~of$$ */
    
    #define	SVMSG_MODE	(MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
    					/* default permissions for new SV message queues */
    /* $$.ix [SVMSG_MODE]~constant,~definition~of$$ */
    #define	SVSEM_MODE	(SEM_R | SEM_A | SEM_R>>3 | SEM_R>>6)
    					/* default permissions for new SV semaphores */
    /* $$.ix [SVSEM_MODE]~constant,~definition~of$$ */
    #define	SVSHM_MODE	(SHM_R | SHM_W | SHM_R>>3 | SHM_R>>6)
    					/* default permissions for new SV shared memory */
    /* $$.ix [SVSHM_MODE]~constant,~definition~of$$ */
    
    typedef	void	Sigfunc(int);	/* for signal handlers */
    
    #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;		/* seconds */
      long		tv_nsec;	/* and nanoseconds */
    };
    /* $$.It timespec$$ */
    /* $$.Ib tv_sec$$ */
    /* $$.Ib tv_nsec$$ */
    #endif
    
    /*
     * In our wrappers for open(), mq_open(), and sem_open() we handle the
     * optional arguments using the va_XXX() macros.  But one of the optional
     * arguments is of type "mode_t" and this breaks under BSD/OS because it
     * uses a 16-bit integer for this datatype.  But when our wrapper function
     * is called, the compiler expands the 16-bit short integer to a 32-bit
     * integer.  This breaks our call to va_arg().  All we can do is the
     * following hack.  Other systems in addition to BSD/OS might have this
     * problem too ...
     */
    
    #ifdef	__bsdi__
    #define	va_mode_t	int
    #else
    #define	va_mode_t	mode_t
    #endif
    /* $$.ix [va_mode_t]~datatype,~definition~of$$ */
    
    		/* our record locking macros */
    #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)
    /* end unpipch */
    
    #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)
    
    			/* prototypes for our own library functions */
    void	 daemon_init(const char *, int);
    void	 daemon_inetd(const char *, int);
    char	*gf_time(void);
    int		 lock_reg(int, int, int, off_t, int, off_t);
    pid_t	 lock_test(int, int, off_t, int, off_t);
    void	*my_shm(size_t);
    char	*px_ipc_name(const char *);
    int		 readable_timeo(int, int);
    ssize_t	 readline(int, void *, size_t);
    ssize_t	 readn(int, void *, size_t);
    int		 set_concurrency(int);
    Sigfunc *signal_intr(int, Sigfunc *);
    int	 	 sleep_us(unsigned int);
    int		 start_time(void);
    double	 stop_time(void);
    int		 touch(void *, int);
    void	 tv_sub(struct timeval *, struct timeval *);
    int		 writable_timeo(int, int);
    ssize_t	 writen(int, const void *, size_t);
    
    #ifndef	HAVE_GETHOSTNAME_PROTO
    int		 gethostname(char *, int);
    #endif
    
    #ifndef	HAVE_ISFDTYPE_PROTO
    int		 isfdtype(int, int);
    #endif
    
    #ifndef	HAVE_PSELECT_PROTO
    int		 pselect(int, fd_set *, fd_set *, fd_set *,
    				 const struct timespec *, const sigset_t *);
    #endif
    
    #ifndef	HAVE_SNPRINTF_PROTO
    int		 snprintf(char *, size_t, const char *, ...);
    #endif
    
    			/* prototypes for our own library wrapper functions */
    char	*Gf_time(void);
    void	 Lock_reg(int, int, int, off_t, int, off_t);
    pid_t	 Lock_test(int, int, off_t, int, off_t);
    void	*My_shm(size_t);
    char	*Px_ipc_name(const char *);
    int		 Readable_timeo(int, int);
    ssize_t	 Readline(int, void *, size_t);
    ssize_t	 Readn(int, void *, size_t);
    void	 Set_concurrency(int);
    Sigfunc *Signal(int, Sigfunc *);
    Sigfunc *Signal_intr(int, Sigfunc *);
    
    #ifdef	HAVE_SIGINFO_T_STRUCT
    Sigfunc_rt *Signal_rt(int, Sigfunc_rt *);
    Sigfunc_rt *Signal_rt_intr(int, Sigfunc_rt *);
    #endif
    
    void	 Sleep_us(unsigned int);
    void	 Start_time(void);
    double	 Stop_time(void);
    void	 Touch(void *, int);
    int		 Writable_timeo(int, int);
    void	 Writen(int, void *, size_t);
    
    			/* prototypes for our Unix wrapper functions */
    void	*Calloc(size_t, size_t);
    void	 Close(int);
    void	 Dup2(int, int);
    int		 Fcntl(int, int, void *);
    pid_t	 Fork(void);
    long	 Fpathconf(int, int);
    void	 Fstat(int, struct stat *);
    key_t	 Ftok(const char *, int);
    void	 Ftruncate(int, off_t);
    int		 Getopt(int, char *const *, const char *);
    void	 Gettimeofday(struct timeval *, void *);
    int		 Ioctl(int, int, void *);
    void	 Kill(pid_t, int);
    off_t	 Lseek(int, off_t, int);
    void	*Malloc(size_t);
    void	 Mkfifo(const char *, mode_t);
    void	 Mktemp(char *);
    void	*Mmap(void *, size_t, int, int, int, off_t);
    void	 Munmap(void *, size_t);
    int		 Open(const char *, int, ...);
    long	 Pathconf(const char *, int);
    void	 Pipe(int *fds);
    ssize_t	 Read(int, void *, size_t);
    int		 Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    void	 Sigaddset(sigset_t *, int);
    void	 Sigdelset(sigset_t *, int);
    void	 Sigemptyset(sigset_t *);
    void	 Sigfillset(sigset_t *);
    int		 Sigismember(const sigset_t *, int);
    void	 Sigpending(sigset_t *);
    void	 Sigprocmask(int, const sigset_t *, sigset_t *);
    #ifdef	HAVE_SIGINFO_T_STRUCT
    void	 Sigqueue(pid_t, int, const union sigval);
    #endif
    #ifdef	HAVE_SIGWAIT
    void	 Sigwait(const sigset_t *, int *);
    #endif
    void	 Stat(const char *, struct stat *);
    char	*Strdup(const char *);
    long	 Sysconf(int);
    void	 Sysctl(int *, u_int, void *, size_t *, void *, size_t);
    void	 Unlink(const char *);
    void	*Valloc(size_t);
    pid_t	 Wait(int *);
    pid_t	 Waitpid(pid_t, int *, int);
    void	 Write(int, void *, size_t);
    
    #ifdef	HAVE_MQUEUE_H
    			/* 4Posix message queues */
    mqd_t	 Mq_open(const char *, int, ...);
    void	 Mq_close(mqd_t);
    void	 Mq_unlink(const char *pathname);
    void	 Mq_send(mqd_t, const char *, size_t, unsigned int);
    ssize_t	 Mq_receive(mqd_t, char *, size_t, unsigned int *);
    void	 Mq_notify(mqd_t, const struct sigevent *);
    void	 Mq_getattr(mqd_t, struct mq_attr *);
    void	 Mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *);
    #endif	/* HAVE_MQUEUE_H */
    
    #ifdef	HAVE_SEMAPHORE_H
    			/* 4Posix semaphores */
    sem_t	*Sem_open(const char *, int, ...);
    void	 Sem_close(sem_t *);
    void	 Sem_unlink(const char *);
    void	 Sem_init(sem_t *, int, unsigned int);
    void	 Sem_destroy(sem_t *);
    void	 Sem_wait(sem_t *);
    int		 Sem_trywait(sem_t *);
    void	 Sem_post(sem_t *);
    void	 Sem_getvalue(sem_t *, int *);
    #endif	/* HAVE_SEMAPHORE_H */
    
    /* Note that <sys/mman.h> is defined on some systems that do not support
     * Posix shared memory (e.g., 4.4BSD), because this header predates Posix
     * and appears on any system that supports mmap().  Therefore we cannot
     * use this to determine whether the implementation supports Posix shared
     * memory or not.  We use our own HAVE_SHM_OPEN_PROTO symbol.
     */
    
    #ifdef	HAVE_SHM_OPEN_PROTO
    			/* 4Posix shared memory */
    int		 Shm_open(const char *, int, mode_t);
    void	 Shm_unlink(const char *);
    #endif
    
    #ifdef	HAVE_SYS_MSG_H
    			/* 4System V message queues */
    int		 Msgget(key_t key, int flag);
    void	 Msgctl(int, int, struct msqid_ds *);
    void	 Msgsnd(int, const void *, size_t, int);
    ssize_t	 Msgrcv(int, void *, size_t, int, int);
    #endif	/* HAVE_SYS_MSG_H */
    
    #ifdef	HAVE_SYS_SEM_H
    			/* 4System V semaphores */
    int		 Semget(key_t, int, int);
    int		 Semctl(int, int, int, ...);
    void	 Semop(int, struct sembuf *, size_t);
    #endif	/* HAVE_SYS_SEM_H */
    
    #ifdef	HAVE_SYS_SHM_H
    			/* 4System V shared memory */
    int		 Shmget(key_t, size_t, int);
    void	*Shmat(int, const void *, int);
    void	 Shmdt(const void *);
    void	 Shmctl(int, int, struct shmid_ds *);
    #endif	/* HAVE_SYS_SHM_H */
    
    			/* prototypes for our stdio wrapper functions */
    void	 Fclose(FILE *);
    FILE	*Fdopen(int, const char *);
    char	*Fgets(char *, int, FILE *);
    FILE	*Fopen(const char *, const char *);
    void	 Fputs(const char *, FILE *);
    FILE	*Popen(const char *, const char *);
    int		 Pclose(FILE *);
    
    #ifdef	HAVE_FATTACH
    void	 Fattach(int, const char *);
    #endif
    #ifdef	HAVE_POLL
    int		 Poll(struct pollfd *, unsigned long, int);
    #endif
    
    void	 err_dump(const char *, ...);
    void	 err_msg(const char *, ...);
    void	 err_quit(const char *, ...);
    void	 err_ret(const char *, ...);
    void	 err_sys(const char *, ...);
    
    			/* prototypes for our pthread wrapper functions */
    void	 Pthread_attr_init(pthread_attr_t *);
    void	 Pthread_attr_destroy(pthread_attr_t *);
    void	 Pthread_attr_setdetachstate(pthread_attr_t *, int);
    void	 Pthread_attr_setscope(pthread_attr_t *, int);
    void	 Pthread_create(pthread_t *, const pthread_attr_t *,
    					    void * (*)(void *), void *);
    void	 Pthread_join(pthread_t, void **);
    void	 Pthread_detach(pthread_t);
    void	 Pthread_kill(pthread_t, int);
    void	 Pthread_setcancelstate(int, int *);
    
    void	 Pthread_mutexattr_init(pthread_mutexattr_t *);
    void	 Pthread_mutexattr_destroy(pthread_mutexattr_t *);
    void	 Pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
    void	 Pthread_mutex_init(pthread_mutex_t *, pthread_mutexattr_t *);
    void	 Pthread_mutex_destroy(pthread_mutex_t *);
    void	 Pthread_mutex_lock(pthread_mutex_t *);
    void	 Pthread_mutex_unlock(pthread_mutex_t *);
    
    void	 Pthread_condattr_init(pthread_condattr_t *);
    void	 Pthread_condattr_destroy(pthread_condattr_t *);
    void	 Pthread_condattr_setpshared(pthread_condattr_t *, int);
    void	 Pthread_cond_broadcast(pthread_cond_t *);
    void	 Pthread_cond_signal(pthread_cond_t *);
    void	 Pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
    void	 Pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *,
    							    const struct timespec *);
    
    void	 Pthread_key_create(pthread_key_t *, void (*)(void *));
    void	 Pthread_setspecific(pthread_key_t, const void *);
    void	 Pthread_once(pthread_once_t *, void (*)(void));
    long	 pr_thread_id(pthread_t *);
    
    #ifdef	HAVE_DOOR_H
    			/* typedefs to simplify declarations */
    typedef	void  Door_server_proc(void *, char *, size_t, door_desc_t *, size_t);
    typedef	void  Door_create_proc(door_info_t *);
    
    			/* prototypes for our doors wrapper functions */
    
    void	 Door_bind(int);
    void	 Door_call(int, door_arg_t *);
    int		 Door_create(Door_server_proc *, void *, u_int);
    void	 Door_cred(door_cred_t *);
    void	 Door_info(int, door_info_t *);
    void	 Door_return(char *, size_t, door_desc_t *, size_t);
    void	 Door_revoke(int);
    void	 Door_unbind(void);
    Door_create_proc	*Door_server_create(Door_create_proc *);
    #endif	/* HAVE_DOOR_H */
    
    #ifdef	HAVE_RPC_RPC_H
    CLIENT	*Clnt_create(const char *, u_long, u_long, const char *);
    void	 Clnt_control(CLIENT *, u_int, char *);
    #endif
    
    #endif	/* __unpipc_h */
    

     unp.h

    /* include unph */
    /* Our own header.  Tabs are set for 4 spaces, not 8 */
    
    #ifndef	__unp_h
    #define	__unp_h
    
    #include	"../config.h"	/* configuration options for current OS */
    							/* "../config.h" is generated by configure */
    
    /* If anything changes in the following list of #includes, must change
       acsite.m4 also, for configure's tests. */
    
    #include	<sys/types.h>	/* basic system data types */
    #include	<sys/socket.h>	/* basic socket definitions */
    #include	<sys/time.h>	/* timeval{} for select() */
    #include	<time.h>		/* timespec{} for pselect() */
    #include	<netinet/in.h>	/* sockaddr_in{} and other Internet defns */
    #include	<arpa/inet.h>	/* inet(3) functions */
    #include	<errno.h>
    #include	<fcntl.h>		/* for nonblocking */
    #include	<netdb.h>
    #include	<signal.h>
    #include	<stdio.h>
    #include	<stdlib.h>
    #include	<string.h>
    #include	<sys/stat.h>	/* for S_xxx file mode constants */
    #include	<sys/uio.h>		/* for iovec{} and readv/writev */
    #include	<unistd.h>
    #include	<sys/wait.h>
    #include	<sys/un.h>		/* for Unix domain sockets */
    
    #ifdef	HAVE_SYS_SELECT_H
    # include	<sys/select.h>	/* for convenience */
    #endif
    
    #ifdef	HAVE_SYS_SYSCTL_H
    # include	<sys/sysctl.h>
    #endif
    
    #ifdef	HAVE_POLL_H
    # include	<poll.h>		/* for convenience */
    #endif
    
    #ifdef	HAVE_STRINGS_H
    # include	<strings.h>		/* for convenience */
    #endif
    
    /* Three headers are normally needed for socket/file ioctl's:
     * <sys/ioctl.h>, <sys/filio.h>, and <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_SYS_SOCKIO_H
    # include	<sys/sockio.h>
    #endif
    
    #ifdef	HAVE_PTHREAD_H
    # include	<pthread.h>
    #endif
    
    #ifdef HAVE_NET_IF_DL_H
    # include	<net/if_dl.h>
    #endif
    
    /* OSF/1 actually disables recv() and send() in <sys/socket.h> */
    #ifdef	__osf__
    #undef	recv
    #undef	send
    #define	recv(a,b,c,d)	recvfrom(a,b,c,d,0,0)
    #define	send(a,b,c,d)	sendto(a,b,c,d,0,0)
    #endif
    
    #ifndef	INADDR_NONE
    /* $$.Ic INADDR_NONE$$ */
    #define	INADDR_NONE	0xffffffff	/* should have been in <netinet/in.h> */
    #endif
    
    #ifndef	SHUT_RD				/* these three Posix.1g names are quite new */
    #define	SHUT_RD		0	/* shutdown for reading */
    #define	SHUT_WR		1	/* shutdown for writing */
    #define	SHUT_RDWR	2	/* shutdown for reading and writing */
    /* $$.Ic SHUT_RD$$ */
    /* $$.Ic SHUT_WR$$ */
    /* $$.Ic SHUT_RDWR$$ */
    #endif
    
    /* *INDENT-OFF* */
    #ifndef INET_ADDRSTRLEN
    /* $$.Ic INET_ADDRSTRLEN$$ */
    #define	INET_ADDRSTRLEN		16	/* "ddd.ddd.ddd.ddd\0"
    								    1234567890123456 */
    #endif
    
    /* Define following even if IPv6 not supported, so we can always allocate
       an adequately-sized buffer, without #ifdefs in the code. */
    #ifndef INET6_ADDRSTRLEN
    /* $$.Ic INET6_ADDRSTRLEN$$ */
    #define	INET6_ADDRSTRLEN	46	/* max size of IPv6 address string:
    				   "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx" or
    				   "xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:ddd.ddd.ddd.ddd\0"
    				    1234567890123456789012345678901234567890123456 */
    #endif
    /* *INDENT-ON* */
    
    /* Define bzero() as a macro if it's not in standard C library. */
    #ifndef	HAVE_BZERO
    #define	bzero(ptr,n)		memset(ptr, 0, n)
    /* $$.If bzero$$ */
    /* $$.If memset$$ */
    #endif
    
    /* Older resolvers do not have gethostbyname2() */
    #ifndef	HAVE_GETHOSTBYNAME2
    #define	gethostbyname2(host,family)		gethostbyname((host))
    #endif
    
    /* The structure returned by recvfrom_flags() */
    struct in_pktinfo {
      struct in_addr	ipi_addr;	/* dst IPv4 address */
      int				ipi_ifindex;/* received interface index */
    };
    /* $$.It in_pktinfo$$ */
    /* $$.Ib ipi_addr$$ */
    /* $$.Ib ipi_ifindex$$ */
    
    /* We need the newer CMSG_LEN() and CMSG_SPACE() macros, but few
       implementations support them today.  These two macros really need
        an ALIGN() macro, but each implementation does this differently. */
    #ifndef	CMSG_LEN
    /* $$.Ic CMSG_LEN$$ */
    #define	CMSG_LEN(size)		(sizeof(struct cmsghdr) + (size))
    #endif
    #ifndef	CMSG_SPACE
    /* $$.Ic CMSG_SPACE$$ */
    #define	CMSG_SPACE(size)	(sizeof(struct cmsghdr) + (size))
    #endif
    
    /* Posix.1g requires the SUN_LEN() macro but not all implementations DefinE
       it (yet).  Note that this 4.4BSD macro works regardless whether there is
       a length field or not. */
    #ifndef	SUN_LEN
    /* $$.Im SUN_LEN$$ */
    # define	SUN_LEN(su) \
    	(sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
    #endif
    
    /* Posix.1g renames "Unix domain" as "local IPC".
       But not all systems DefinE AF_LOCAL and PF_LOCAL (yet). */
    #ifndef	AF_LOCAL
    #define AF_LOCAL	AF_UNIX
    #endif
    #ifndef	PF_LOCAL
    #define PF_LOCAL	PF_UNIX
    #endif
    
    /* Posix.1g requires that an #include of <poll.h> DefinE INFTIM, but many
       systems still DefinE it in <sys/stropts.h>.  We don't want to include
       all the streams stuff if it's not needed, so we just DefinE INFTIM here.
       This is the standard value, but there's no guarantee it is -1. */
    #ifndef INFTIM
    #define INFTIM          (-1)    /* infinite poll timeout */
    /* $$.Ic INFTIM$$ */
    #ifdef	HAVE_POLL_H
    #define	INFTIM_UNPH				/* tell unpxti.h we defined it */
    #endif
    #endif
    
    /* Following could be derived from SOMAXCONN in <sys/socket.h>, but many
       kernels still #define it as 5, while actually supporting many more */
    #define	LISTENQ		1024	/* 2nd argument to listen() */
    
    /* Miscellaneous constants */
    #define	MAXLINE		4096	/* max text line length */
    #define	MAXSOCKADDR  128	/* max socket address structure size */
    #define	BUFFSIZE	8192	/* buffer size for reads and writes */
    
    /* Define some port number that can be used for client-servers */
    #define	SERV_PORT		 9877			/* TCP and UDP client-servers */
    #define	SERV_PORT_STR	"9877"			/* TCP and UDP client-servers */
    #define	UNIXSTR_PATH	"/tmp/unix.str"	/* Unix domain stream cli-serv */
    #define	UNIXDG_PATH		"/tmp/unix.dg"	/* Unix domain datagram cli-serv */
    /* $$.ix [LISTENQ]~constant,~definition~of$$ */
    /* $$.ix [MAXLINE]~constant,~definition~of$$ */
    /* $$.ix [MAXSOCKADDR]~constant,~definition~of$$ */
    /* $$.ix [BUFFSIZE]~constant,~definition~of$$ */
    /* $$.ix [SERV_PORT]~constant,~definition~of$$ */
    /* $$.ix [UNIXSTR_PATH]~constant,~definition~of$$ */
    /* $$.ix [UNIXDG_PATH]~constant,~definition~of$$ */
    
    /* Following shortens all the type casts of pointer arguments */
    #define	SA	struct sockaddr
    
    #define	FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
    					/* default file access permissions for new files */
    #define	DIR_MODE	(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
    					/* default permissions for new directories */
    
    typedef	void	Sigfunc(int);	/* for signal handlers */
    
    #define	min(a,b)	((a) < (b) ? (a) : (b))
    #define	max(a,b)	((a) > (b) ? (a) : (b))
    
    #ifndef	HAVE_ADDRINFO_STRUCT
    # include	"../lib/addrinfo.h"
    #endif
    
    #ifndef	HAVE_IF_NAMEINDEX_STRUCT
    struct if_nameindex {
      unsigned int   if_index;  /* 1, 2, ... */
      char          *if_name;   /* null terminated name: "le0", ... */
    };
    /* $$.It if_nameindex$$ */
    /* $$.Ib if_index$$ */
    /* $$.Ib if_name$$ */
    #endif
    
    #ifndef	HAVE_TIMESPEC_STRUCT
    struct timespec {
      time_t	tv_sec;		/* seconds */
      long		tv_nsec;	/* and nanoseconds */
    };
    /* $$.It timespec$$ */
    /* $$.Ib tv_sec$$ */
    /* $$.Ib tv_nsec$$ */
    #endif
    /* end unph */
    
    			/* prototypes for our own library functions */
    int		 connect_nonb(int, const SA *, socklen_t, int);
    int		 connect_timeo(int, const SA *, socklen_t, int);
    void	 daemon_init(const char *, int);
    void	 daemon_inetd(const char *, int);
    void	 dg_cli(FILE *, int, const SA *, socklen_t);
    void	 dg_echo(int, SA *, socklen_t);
    int		 family_to_level(int);
    char	*gf_time(void);
    void	 heartbeat_cli(int, int, int);
    void	 heartbeat_serv(int, int, int);
    struct addrinfo *host_serv(const char *, const char *, int, int);
    int		 inet_srcrt_add(char *, int);
    u_char  *inet_srcrt_init(void);
    void	 inet_srcrt_print(u_char *, int);
    char   **my_addrs(int *);
    int		 readable_timeo(int, int);
    ssize_t	 readline(int, void *, size_t);
    ssize_t	 readn(int, void *, size_t);
    ssize_t	 read_fd(int, void *, size_t, int *);
    ssize_t	 recvfrom_flags(int, void *, size_t, int *, SA *, socklen_t *,
    		 struct in_pktinfo *);
    Sigfunc *signal_intr(int, Sigfunc *);
    int		 sock_bind_wild(int, int);
    int		 sock_cmp_addr(const SA *, const SA *, socklen_t);
    int		 sock_cmp_port(const SA *, const SA *, socklen_t);
    int		 sock_get_port(const SA *, socklen_t);
    void	 sock_set_addr(SA *, socklen_t, const void *);
    void	 sock_set_port(SA *, socklen_t, int);
    void	 sock_set_wild(SA *, socklen_t);
    char	*sock_ntop(const SA *, socklen_t);
    char	*sock_ntop_host(const SA *, socklen_t);
    int		 sockfd_to_family(int);
    void	 str_echo(int);
    void	 str_cli(FILE *, int);
    int		 tcp_connect(const char *, const char *);
    int		 tcp_listen(const char *, const char *, socklen_t *);
    void	 tv_sub(struct timeval *, struct timeval *);
    int		 udp_client(const char *, const char *, void **, socklen_t *);
    int		 udp_connect(const char *, const char *);
    int		 udp_server(const char *, const char *, socklen_t *);
    int		 writable_timeo(int, int);
    ssize_t	 writen(int, const void *, size_t);
    ssize_t	 write_fd(int, void *, size_t, int);
    
    #ifdef	MCAST
    int		 mcast_leave(int, const SA *, socklen_t);
    int		 mcast_join(int, const SA *, socklen_t, const char *, u_int);
    int		 mcast_leave_source_group(int sockfd, const SA *src, socklen_t srclen,
    								  const SA *grp, socklen_t grplen);
    int		 mcast_join_source_group(int sockfd, const SA *src, socklen_t srclen,
    								 const SA *grp, socklen_t grplen,
    								 const char *ifname, u_int ifindex);
    int		 mcast_block_source(int sockfd, const SA *src, socklen_t srclen,
    							const SA *grp, socklen_t grplen);
    int		 mcast_unblock_source(int sockfd, const SA *src, socklen_t srclen,
    							  const SA *grp, socklen_t grplen);
    int		 mcast_get_if(int);
    int		 mcast_get_loop(int);
    int		 mcast_get_ttl(int);
    int		 mcast_set_if(int, const char *, u_int);
    int		 mcast_set_loop(int, int);
    int		 mcast_set_ttl(int, int);
    
    void	 Mcast_leave(int, const SA *, socklen_t);
    void	 Mcast_join(int, const SA *, socklen_t, const char *, u_int);
    void	 Mcast_leave_source_group(int sockfd, const SA *src, socklen_t srclen,
    								  const SA *grp, socklen_t grplen);
    void	 Mcast_join_source_group(int sockfd, const SA *src, socklen_t srclen,
    								 const SA *grp, socklen_t grplen,
    								 const char *ifname, u_int ifindex);
    void	 Mcast_block_source(int sockfd, const SA *src, socklen_t srclen,
    							const SA *grp, socklen_t grplen);
    void	 Mcast_unblock_source(int sockfd, const SA *src, socklen_t srclen,
    							  const SA *grp, socklen_t grplen);
    int		 Mcast_get_if(int);
    int		 Mcast_get_loop(int);
    int		 Mcast_get_ttl(int);
    void	 Mcast_set_if(int, const char *, u_int);
    void	 Mcast_set_loop(int, int);
    void	 Mcast_set_ttl(int, int);
    #endif
    
    unsigned short	in_cksum(unsigned short *, int);
    
    #ifndef	HAVE_GETADDRINFO_PROTO
    int		 getaddrinfo(const char *, const char *, const struct addrinfo *,
    					 struct addrinfo **);
    void	 freeaddrinfo(struct addrinfo *);
    char	*gai_strerror(int);
    #endif
    
    #ifndef	HAVE_GETNAMEINFO_PROTO
    int		 getnameinfo(const SA *, socklen_t, char *, size_t, char *, size_t, int);
    #endif
    
    #ifndef	HAVE_GETHOSTNAME_PROTO
    int		 gethostname(char *, int);
    #endif
    
    #ifndef	HAVE_HSTRERROR_PROTO
    const char	*hstrerror(int);
    #endif
    
    #ifndef	HAVE_IF_NAMETOINDEX_PROTO
    unsigned int	 if_nametoindex(const char *);
    char			*if_indextoname(unsigned int, char *);
    void			 if_freenameindex(struct if_nameindex *);
    struct if_nameindex *if_nameindex(void);
    #endif
    
    #ifndef	HAVE_INET_PTON_PROTO
    int			 inet_pton(int, const char *, void *);
    const char	*inet_ntop(int, const void *, char *, size_t);
    #endif
    
    #ifndef	HAVE_INET_ATON_PROTO
    int		 inet_aton(const char *, struct in_addr *);
    #endif
    
    #ifndef	HAVE_ISFDTYPE_PROTO
    int		 isfdtype(int, int);
    #endif
    
    #ifndef	HAVE_PSELECT_PROTO
    int		 pselect(int, fd_set *, fd_set *, fd_set *,
    				 const struct timespec *, const sigset_t *);
    #endif
    
    #ifndef	HAVE_SOCKATMARK_PROTO
    int		 sockatmark(int);
    #endif
    
    #ifndef	HAVE_SNPRINTF_PROTO
    int		 snprintf(char *, size_t, const char *, ...);
    #endif
    
    			/* prototypes for our own library wrapper functions */
    void	 Connect_timeo(int, const SA *, socklen_t, int);
    int		 Family_to_level(int);
    struct addrinfo *Host_serv(const char *, const char *, int, int);
    const char		*Inet_ntop(int, const void *, char *, size_t);
    void			 Inet_pton(int, const char *, void *);
    char			*If_indextoname(unsigned int, char *);
    unsigned int		 If_nametoindex(const char *);
    struct if_nameindex	*If_nameindex(void);
    char   **My_addrs(int *);
    ssize_t	 Read_fd(int, void *, size_t, int *);
    int		 Readable_timeo(int, int);
    ssize_t	 Recvfrom_flags(int, void *, size_t, int *, SA *, socklen_t *,
    		 struct in_pktinfo *);
    Sigfunc *Signal(int, Sigfunc *);
    Sigfunc *Signal_intr(int, Sigfunc *);
    int		 Sock_bind_wild(int, int);
    char	*Sock_ntop(const SA *, socklen_t);
    char	*Sock_ntop_host(const SA *, socklen_t);
    int		 Sockfd_to_family(int);
    int		 Tcp_connect(const char *, const char *);
    int		 Tcp_listen(const char *, const char *, socklen_t *);
    int		 Udp_client(const char *, const char *, void **, socklen_t *);
    int		 Udp_connect(const char *, const char *);
    int		 Udp_server(const char *, const char *, socklen_t *);
    ssize_t	 Write_fd(int, void *, size_t, int);
    int		 Writable_timeo(int, int);
    
    			/* prototypes for our Unix wrapper functions: see {Sec errors} */
    void	*Calloc(size_t, size_t);
    void	 Close(int);
    void	 Dup2(int, int);
    int		 Fcntl(int, int, int);
    void	 Gettimeofday(struct timeval *, void *);
    int		 Ioctl(int, int, void *);
    pid_t	 Fork(void);
    void	*Malloc(size_t);
    int	 Mkstemp(char *);
    void	*Mmap(void *, size_t, int, int, int, off_t);
    int		 Open(const char *, int, mode_t);
    void	 Pipe(int *fds);
    ssize_t	 Read(int, void *, size_t);
    void	 Sigaddset(sigset_t *, int);
    void	 Sigdelset(sigset_t *, int);
    void	 Sigemptyset(sigset_t *);
    void	 Sigfillset(sigset_t *);
    int		 Sigismember(const sigset_t *, int);
    void	 Sigpending(sigset_t *);
    void	 Sigprocmask(int, const sigset_t *, sigset_t *);
    char	*Strdup(const char *);
    long	 Sysconf(int);
    void	 Sysctl(int *, u_int, void *, size_t *, void *, size_t);
    void	 Unlink(const char *);
    pid_t	 Wait(int *);
    pid_t	 Waitpid(pid_t, int *, int);
    void	 Write(int, void *, size_t);
    
    			/* prototypes for our stdio wrapper functions: see {Sec errors} */
    void	 Fclose(FILE *);
    FILE	*Fdopen(int, const char *);
    char	*Fgets(char *, int, FILE *);
    FILE	*Fopen(const char *, const char *);
    void	 Fputs(const char *, FILE *);
    
    			/* prototypes for our socket wrapper functions: see {Sec errors} */
    int		 Accept(int, SA *, socklen_t *);
    void	 Bind(int, const SA *, socklen_t);
    void	 Connect(int, const SA *, socklen_t);
    void	 Getpeername(int, SA *, socklen_t *);
    void	 Getsockname(int, SA *, socklen_t *);
    void	 Getsockopt(int, int, int, void *, socklen_t *);
    int		 Isfdtype(int, int);
    void	 Listen(int, int);
    #ifdef	HAVE_POLL
    int		 Poll(struct pollfd *, unsigned long, int);
    #endif
    ssize_t	 Readline(int, void *, size_t);
    ssize_t	 Readn(int, void *, size_t);
    ssize_t	 Recv(int, void *, size_t, int);
    ssize_t	 Recvfrom(int, void *, size_t, int, SA *, socklen_t *);
    ssize_t	 Recvmsg(int, struct msghdr *, int);
    int		 Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    void	 Send(int, const void *, size_t, int);
    void	 Sendto(int, const void *, size_t, int, const SA *, socklen_t);
    void	 Sendmsg(int, const struct msghdr *, int);
    void	 Setsockopt(int, int, int, const void *, socklen_t);
    void	 Shutdown(int, int);
    int		 Sockatmark(int);
    int		 Socket(int, int, int);
    void	 Socketpair(int, int, int, int *);
    void	 Writen(int, void *, size_t);
    
    void	 err_dump(const char *, ...);
    void	 err_msg(const char *, ...);
    void	 err_quit(const char *, ...);
    void	 err_ret(const char *, ...);
    void	 err_sys(const char *, ...);
    
    #endif	/* __unp_h */
    
  • 相关阅读:
    BZOJ4008: [HNOI2015]亚瑟王
    BZOJ4260: Codechef REBXOR
    BZOJ4408: [Fj Winter Camp 2016]神秘数
    BZOJ4010: [HNOI2015]菜肴制作
    ccc2016
    BZOJ3884: 上帝与集合的正确用法
    BZOJ1017: [JSOI2008]魔兽地图DotR
    BZOJ1011: [HNOI2008]遥远的行星
    BestCoder Round #73
    hdu4035(概率dp)
  • 原文地址:https://www.cnblogs.com/jingzhishen/p/3027020.html
Copyright © 2011-2022 走看看