码迷,mamicode.com
首页 > 其他好文 > 详细

unpipc.h

时间:2014-08-07 12:03:50      阅读:1081      评论:0      收藏:0      [点我收藏+]

标签:des   os   io   for   art   ar   cti   line   

  1. /* include unpipch */
  2. /* Our own header.  Tabs are set for 4 spaces, not 8 */
  3. #ifndef __unpipc_h
  4. #define __unpipc_h
  5. #include "../config.h" /* configuration options for current OS */
  6. /* "../config.h" is generated by configure */
  7. /* If anything changes in the following list of #includes, must change
  8.    ../aclocal.m4 and ../configure.in also, for configure‘s tests. */
  9. #include <sys/types.h> /* basic system data types */
  10. #include <sys/time.h> /* timeval{} for select() */
  11. #include <time.h> /* timespec{} for pselect() */
  12. #include <errno.h>
  13. #include <fcntl.h> /* for nonblocking */
  14. #include <limits.h> /* PIPE_BUF */
  15. #include <signal.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <sys/stat.h> /* for S_xxx file mode constants */
  20. #include <unistd.h>
  21. #include <sys/wait.h>
  22. #ifdef HAVE_MQUEUE_H
  23. # include <mqueue.h> /* Posix message queues */
  24. #endif
  25. #ifdef HAVE_SEMAPHORE_H
  26. # include <semaphore.h> /* Posix semaphores */
  27. #ifndef SEM_FAILED
  28. #define SEM_FAILED ((sem_t *)(-1))
  29. #endif
  30. #endif
  31. #ifdef HAVE_SYS_MMAN_H
  32. # include <sys/mman.h> /* Posix shared memory */
  33. #endif
  34. #ifndef MAP_FAILED
  35. #define MAP_FAILED ((void *)(-1))
  36. #endif
  37. #ifdef HAVE_SYS_IPC_H
  38. # include <sys/ipc.h> /* System V IPC */
  39. #endif
  40. #ifdef HAVE_SYS_MSG_H
  41. # include <sys/msg.h> /* System V message queues */
  42. #endif
  43. #ifdef HAVE_SYS_SEM_H
  44. #ifdef __bsdi__
  45. #undef HAVE_SYS_SEM_H /* hack: BSDI‘s semctl() prototype is wrong */
  46. #else
  47. # include <sys/sem.h> /* System V semaphores */
  48. #endif
  49. #ifndef HAVE_SEMUN_UNION
  50. /* $$.It semun$$ */
  51. union semun { /* define union for semctl() */
  52.   int              val;
  53.   struct semid_ds *buf;
  54.   unsigned short  *array;
  55. };
  56. #endif
  57. #endif /* HAVE_SYS_SEM_H */
  58. #ifdef HAVE_SYS_SHM_H
  59. # include <sys/shm.h> /* System V shared memory */
  60. #endif
  61. #ifdef HAVE_SYS_SELECT_H
  62. # include <sys/select.h> /* for convenience */
  63. #endif
  64. #ifdef HAVE_POLL_H
  65. # include <poll.h> /* for convenience */
  66. #endif
  67. #ifdef HAVE_STROPTS_H
  68. # include <stropts.h> /* for convenience */
  69. #endif
  70. #ifdef HAVE_STRINGS_H
  71. # include <strings.h> /* for convenience */
  72. #endif
  73. /* Next three headers are normally needed for socket/file ioctl‘s:
  74.  * <sys/ioctl.h>, <sys/filio.h>, and <sys/sockio.h>.
  75.  */
  76. #ifdef HAVE_SYS_IOCTL_H
  77. # include <sys/ioctl.h>
  78. #endif
  79. #ifdef HAVE_SYS_FILIO_H
  80. # include <sys/filio.h>
  81. #endif
  82. #ifdef HAVE_PTHREAD_H
  83. # include <pthread.h>
  84. #endif
  85. #ifdef HAVE_DOOR_H
  86. # include <door.h> /* Solaris doors API */
  87. #endif
  88. #ifdef HAVE_RPC_RPC_H
  89. #ifdef _PSX4_NSPACE_H_TS /* Digital Unix 4.0b hack, hack, hack */
  90. #undef SUCCESS
  91. #endif
  92. # include <rpc/rpc.h> /* Sun RPC */
  93. #endif
  94. /* Define bzero() as a macro if it‘s not in standard C library. */
  95. #ifndef HAVE_BZERO
  96. #define bzero(ptr,n) memset(ptr, 0, n)
  97. #endif
  98. /* Posix.1g requires that an #include of <poll.h> DefinE INFTIM, but many
  99.    systems still DefinE it in <sys/stropts.h>.  We don‘t want to include
  100.    all the streams stuff if it‘s not needed, so we just DefinE INFTIM here.
  101.    This is the standard value, but there‘s no guarantee it is -1. */
  102. #ifndef INFTIM
  103. #define INFTIM          (-1)    /* infinite poll timeout */
  104. #ifdef HAVE_POLL_H
  105. #define INFTIM_UNPH /* tell unpxti.h we defined it */
  106. #endif
  107. #endif
  108. /* Miscellaneous constants */
  109. #ifndef PATH_MAX /* should be in <limits.h> */
  110. #define PATH_MAX 1024 /* max # of characters in a pathname */
  111. #endif
  112. #define MAX_PATH 1024
  113. /* $$.ix [MAX_PATH]~constant,~definition~of$$ */
  114. #define MAXLINE 4096 /* max text line length */
  115. /* $$.ix [MAXLINE]~constant,~definition~of$$ */
  116. /* $$.ix [BUFFSIZE]~constant,~definition~of$$ */
  117. #define BUFFSIZE 8192 /* buffer size for reads and writes */
  118. #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
  119. /* default permissions for new files */
  120. /* $$.ix [FILE_MODE]~constant,~definition~of$$ */
  121. #define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
  122. /* default permissions for new directories */
  123. /* $$.ix [DIR_MODE]~constant,~definition~of$$ */
  124. #define SVMSG_MODE (MSG_R | MSG_W | MSG_R>>3 | MSG_R>>6)
  125. /* default permissions for new SV message queues */
  126. /* $$.ix [SVMSG_MODE]~constant,~definition~of$$ */
  127. #define SVSEM_MODE (SEM_R | SEM_A | SEM_R>>3 | SEM_R>>6)
  128. /* default permissions for new SV semaphores */
  129. /* $$.ix [SVSEM_MODE]~constant,~definition~of$$ */
  130. #define SVSHM_MODE (SHM_R | SHM_W | SHM_R>>3 | SHM_R>>6)
  131. /* default permissions for new SV shared memory */
  132. /* $$.ix [SVSHM_MODE]~constant,~definition~of$$ */
  133. typedef void Sigfunc(int); /* for signal handlers */
  134. #ifdef HAVE_SIGINFO_T_STRUCT
  135. typedef void Sigfunc_rt(int, siginfo_t *, void *);
  136. #endif
  137. #define min(a,b) ((a) < (b) ? (a) : (b))
  138. #define max(a,b) ((a) > (b) ? (a) : (b))
  139. #ifndef HAVE_TIMESPEC_STRUCT
  140. struct timespec {
  141.   time_t tv_sec; /* seconds */
  142.   long tv_nsec; /* and nanoseconds */
  143. };
  144. /* $$.It timespec$$ */
  145. /* $$.Ib tv_sec$$ */
  146. /* $$.Ib tv_nsec$$ */
  147. #endif
  148. /*
  149.  * In our wrappers for open(), mq_open(), and sem_open() we handle the
  150.  * optional arguments using the va_XXX() macros.  But one of the optional
  151.  * arguments is of type "mode_t" and this breaks under BSD/OS because it
  152.  * uses a 16-bit integer for this datatype.  But when our wrapper function
  153.  * is called, the compiler expands the 16-bit short integer to a 32-bit
  154.  * integer.  This breaks our call to va_arg().  All we can do is the
  155.  * following hack.  Other systems in addition to BSD/OS might have this
  156.  * problem too ...
  157.  */
  158. #ifdef __bsdi__
  159. #define va_mode_t int
  160. #else
  161. #define va_mode_t mode_t
  162. #endif
  163. /* $$.ix [va_mode_t]~datatype,~definition~of$$ */
  164. /* our record locking macros */
  165. #define read_lock(fd, offset, whence, len) 
  166. lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
  167. #define readw_lock(fd, offset, whence, len) 
  168. lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
  169. #define write_lock(fd, offset, whence, len) 
  170. lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
  171. #define writew_lock(fd, offset, whence, len) 
  172. lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
  173. #define un_lock(fd, offset, whence, len) 
  174. lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
  175. #define is_read_lockable(fd, offset, whence, len) 
  176. lock_test(fd, F_RDLCK, offset, whence, len)
  177. #define is_write_lockable(fd, offset, whence, len) 
  178. lock_test(fd, F_WRLCK, offset, whence, len)
  179. /* end unpipch */
  180. #define Read_lock(fd, offset, whence, len) 
  181. Lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
  182. #define Readw_lock(fd, offset, whence, len) 
  183. Lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
  184. #define Write_lock(fd, offset, whence, len) 
  185. Lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
  186. #define Writew_lock(fd, offset, whence, len) 
  187. Lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
  188. #define Un_lock(fd, offset, whence, len) 
  189. Lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
  190. #define Is_read_lockable(fd, offset, whence, len) 
  191. Lock_test(fd, F_RDLCK, offset, whence, len)
  192. #define Is_write_lockable(fd, offset, whence, len) 
  193. Lock_test(fd, F_WRLCK, offset, whence, len)
  194. /* prototypes for our own library functions */
  195. void  daemon_init(const char *, int);
  196. void  daemon_inetd(const char *, int);
  197. char *gf_time(void);
  198. int  lock_reg(int, int, int, off_t, int, off_t);
  199. pid_t  lock_test(int, int, off_t, int, off_t);
  200. void *my_shm(size_t);
  201. char *px_ipc_name(const char *);
  202. int  readable_timeo(int, int);
  203. ssize_t  readline(int, void *, size_t);
  204. ssize_t  readn(int, void *, size_t);
  205. int  set_concurrency(int);
  206. Sigfunc *signal_intr(int, Sigfunc *);
  207. int    sleep_us(unsigned int);
  208. int  start_time(void);
  209. double  stop_time(void);
  210. int  touch(void *, int);
  211. void  tv_sub(struct timeval *, struct timeval *);
  212. int  writable_timeo(int, int);
  213. ssize_t  writen(int, const void *, size_t);
  214. #ifndef HAVE_GETHOSTNAME_PROTO
  215. int  gethostname(char *, int);
  216. #endif
  217. #ifndef HAVE_ISFDTYPE_PROTO
  218. int  isfdtype(int, int);
  219. #endif
  220. #ifndef HAVE_PSELECT_PROTO
  221. int  pselect(int, fd_set *, fd_set *, fd_set *,
  222.  const struct timespec *, const sigset_t *);
  223. #endif
  224. #ifndef HAVE_SNPRINTF_PROTO
  225. int  snprintf(char *, size_t, const char *, ...);
  226. #endif
  227. /* prototypes for our own library wrapper functions */
  228. char *Gf_time(void);
  229. void  Lock_reg(int, int, int, off_t, int, off_t);
  230. pid_t  Lock_test(int, int, off_t, int, off_t);
  231. void *My_shm(size_t);
  232. char *Px_ipc_name(const char *);
  233. int  Readable_timeo(int, int);
  234. ssize_t  Readline(int, void *, size_t);
  235. ssize_t  Readn(int, void *, size_t);
  236. void  Set_concurrency(int);
  237. Sigfunc *Signal(int, Sigfunc *);
  238. Sigfunc *Signal_intr(int, Sigfunc *);
  239. #ifdef HAVE_SIGINFO_T_STRUCT
  240. Sigfunc_rt *Signal_rt(int, Sigfunc_rt *);
  241. Sigfunc_rt *Signal_rt_intr(int, Sigfunc_rt *);
  242. #endif
  243. void  Sleep_us(unsigned int);
  244. void  Start_time(void);
  245. double  Stop_time(void);
  246. void  Touch(void *, int);
  247. int  Writable_timeo(int, int);
  248. void  Writen(int, void *, size_t);
  249. /* prototypes for our Unix wrapper functions */
  250. void *Calloc(size_t, size_t);
  251. void  Close(int);
  252. void  Dup2(int, int);
  253. int  Fcntl(int, int, void *);
  254. pid_t  Fork(void);
  255. long  Fpathconf(int, int);
  256. void  Fstat(int, struct stat *);
  257. key_t  Ftok(const char *, int);
  258. void  Ftruncate(int, off_t);
  259. int  Getopt(int, char *const *, const char *);
  260. void  Gettimeofday(struct timeval *, void *);
  261. int  Ioctl(int, int, void *);
  262. void  Kill(pid_t, int);
  263. off_t  Lseek(int, off_t, int);
  264. void *Malloc(size_t);
  265. void  Mkfifo(const char *, mode_t);
  266. void  Mktemp(char *);
  267. void *Mmap(void *, size_t, int, int, int, off_t);
  268. void  Munmap(void *, size_t);
  269. int  Open(const char *, int, ...);
  270. long  Pathconf(const char *, int);
  271. void  Pipe(int *fds);
  272. ssize_t  Read(int, void *, size_t);
  273. int  Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
  274. void  Sigaddset(sigset_t *, int);
  275. void  Sigdelset(sigset_t *, int);
  276. void  Sigemptyset(sigset_t *);
  277. void  Sigfillset(sigset_t *);
  278. int  Sigismember(const sigset_t *, int);
  279. void  Sigpending(sigset_t *);
  280. void  Sigprocmask(int, const sigset_t *, sigset_t *);
  281. #ifdef HAVE_SIGINFO_T_STRUCT
  282. void  Sigqueue(pid_t, int, const union sigval);
  283. #endif
  284. #ifdef HAVE_SIGWAIT
  285. void  Sigwait(const sigset_t *, int *);
  286. #endif
  287. void  Stat(const char *, struct stat *);
  288. char *Strdup(const char *);
  289. long  Sysconf(int);
  290. void  Sysctl(int *, u_int, void *, size_t *, void *, size_t);
  291. void  Unlink(const char *);
  292. void *Valloc(size_t);
  293. pid_t  Wait(int *);
  294. pid_t  Waitpid(pid_t, int *, int);
  295. void  Write(int, void *, size_t);
  296. #ifdef HAVE_MQUEUE_H
  297. /* 4Posix message queues */
  298. mqd_t  Mq_open(const char *, int, ...);
  299. void  Mq_close(mqd_t);
  300. void  Mq_unlink(const char *pathname);
  301. void  Mq_send(mqd_t, const char *, size_t, unsigned int);
  302. ssize_t  Mq_receive(mqd_t, char *, size_t, unsigned int *);
  303. void  Mq_notify(mqd_t, const struct sigevent *);
  304. void  Mq_getattr(mqd_t, struct mq_attr *);
  305. void  Mq_setattr(mqd_t, const struct mq_attr *, struct mq_attr *);
  306. #endif /* HAVE_MQUEUE_H */
  307. #ifdef HAVE_SEMAPHORE_H
  308. /* 4Posix semaphores */
  309. sem_t *Sem_open(const char *, int, ...);
  310. void  Sem_close(sem_t *);
  311. void  Sem_unlink(const char *);
  312. void  Sem_init(sem_t *, int, unsigned int);
  313. void  Sem_destroy(sem_t *);
  314. void  Sem_wait(sem_t *);
  315. int  Sem_trywait(sem_t *);
  316. void  Sem_post(sem_t *);
  317. void  Sem_getvalue(sem_t *, int *);
  318. #endif /* HAVE_SEMAPHORE_H */
  319. /* Note that <sys/mman.h> is defined on some systems that do not support
  320.  * Posix shared memory (e.g., 4.4BSD), because this header predates Posix
  321.  * and appears on any system that supports mmap().  Therefore we cannot
  322.  * use this to determine whether the implementation supports Posix shared
  323.  * memory or not.  We use our own HAVE_SHM_OPEN_PROTO symbol.
  324.  */
  325. #ifdef HAVE_SHM_OPEN_PROTO
  326. /* 4Posix shared memory */
  327. int  Shm_open(const char *, int, mode_t);
  328. void  Shm_unlink(const char *);
  329. #endif
  330. #ifdef HAVE_SYS_MSG_H
  331. /* 4System V message queues */
  332. int  Msgget(key_t key, int flag);
  333. void  Msgctl(int, int, struct msqid_ds *);
  334. void  Msgsnd(int, const void *, size_t, int);
  335. ssize_t  Msgrcv(int, void *, size_t, int, int);
  336. #endif /* HAVE_SYS_MSG_H */
  337. #ifdef HAVE_SYS_SEM_H
  338. /* 4System V semaphores */
  339. int  Semget(key_t, int, int);
  340. int  Semctl(int, int, int, ...);
  341. void  Semop(int, struct sembuf *, size_t);
  342. #endif /* HAVE_SYS_SEM_H */
  343. #ifdef HAVE_SYS_SHM_H
  344. /* 4System V shared memory */
  345. int  Shmget(key_t, size_t, int);
  346. void *Shmat(int, const void *, int);
  347. void  Shmdt(const void *);
  348. void  Shmctl(int, int, struct shmid_ds *);
  349. #endif /* HAVE_SYS_SHM_H */
  350. /* prototypes for our stdio wrapper functions */
  351. void  Fclose(FILE *);
  352. FILE *Fdopen(int, const char *);
  353. char *Fgets(char *, int, FILE *);
  354. FILE *Fopen(const char *, const char *);
  355. void  Fputs(const char *, FILE *);
  356. FILE *Popen(const char *, const char *);
  357. int  Pclose(FILE *);
  358. #ifdef HAVE_FATTACH
  359. void  Fattach(int, const char *);
  360. #endif
  361. #ifdef HAVE_POLL
  362. int  Poll(struct pollfd *, unsigned long, int);
  363. #endif
  364. void  err_dump(const char *, ...);
  365. void  err_msg(const char *, ...);
  366. void  err_quit(const char *, ...);
  367. void  err_ret(const char *, ...);
  368. void  err_sys(const char *, ...);
  369. /* prototypes for our pthread wrapper functions */
  370. void  Pthread_attr_init(pthread_attr_t *);
  371. void  Pthread_attr_destroy(pthread_attr_t *);
  372. void  Pthread_attr_setdetachstate(pthread_attr_t *, int);
  373. void  Pthread_attr_setscope(pthread_attr_t *, int);
  374. void  Pthread_create(pthread_t *, const pthread_attr_t *,
  375.     void * (*)(void *), void *);
  376. void  Pthread_join(pthread_t, void **);
  377. void  Pthread_detach(pthread_t);
  378. void  Pthread_kill(pthread_t, int);
  379. void  Pthread_setcancelstate(int, int *);
  380. void  Pthread_mutexattr_init(pthread_mutexattr_t *);
  381. void  Pthread_mutexattr_destroy(pthread_mutexattr_t *);
  382. void  Pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
  383. void  Pthread_mutex_init(pthread_mutex_t *, pthread_mutexattr_t *);
  384. void  Pthread_mutex_destroy(pthread_mutex_t *);
  385. void  Pthread_mutex_lock(pthread_mutex_t *);
  386. void  Pthread_mutex_unlock(pthread_mutex_t *);
  387. void  Pthread_condattr_init(pthread_condattr_t *);
  388. void  Pthread_condattr_destroy(pthread_condattr_t *);
  389. void  Pthread_condattr_setpshared(pthread_condattr_t *, int);
  390. void  Pthread_cond_broadcast(pthread_cond_t *);
  391. void  Pthread_cond_signal(pthread_cond_t *);
  392. void  Pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
  393. void  Pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *,
  394.     const struct timespec *);
  395. void  Pthread_key_create(pthread_key_t *, void (*)(void *));
  396. void  Pthread_setspecific(pthread_key_t, const void *);
  397. void  Pthread_once(pthread_once_t *, void (*)(void));
  398. long  pr_thread_id(pthread_t *);
  399. #ifdef HAVE_DOOR_H
  400. /* typedefs to simplify declarations */
  401. typedef void  Door_server_proc(void *, char *, size_t, door_desc_t *, size_t);
  402. typedef void  Door_create_proc(door_info_t *);
  403. /* prototypes for our doors wrapper functions */
  404. void  Door_bind(int);
  405. void  Door_call(int, door_arg_t *);
  406. int  Door_create(Door_server_proc *, void *, u_int);
  407. void  Door_cred(door_cred_t *);
  408. void  Door_info(int, door_info_t *);
  409. void  Door_return(char *, size_t, door_desc_t *, size_t);
  410. void  Door_revoke(int);
  411. void  Door_unbind(void);
  412. Door_create_proc *Door_server_create(Door_create_proc *);
  413. #endif /* HAVE_DOOR_H */
  414. #ifdef HAVE_RPC_RPC_H
  415. CLIENT *Clnt_create(const char *, u_long, u_long, const char *);
  416. void  Clnt_control(CLIENT *, u_int, char *);
  417. #endif
  418. #endif /* __unpipc_h */

unpipc.h,布布扣,bubuko.com

unpipc.h

标签:des   os   io   for   art   ar   cti   line   

原文地址:http://www.cnblogs.com/wzf365/p/3896374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!