apue
#ifndef apue_h #define apue_h #define _POSIX_C_SOURCE 200809L #if defined(SOLARIS) /* Solaris 10 */ #define _XOPEN_SOURCE 600 #else #define _XOPEN_SOURCE 700 #endif #include <sys/types.h> /* some systems still require this */ #include <sys/stat.h> #include <sys/termios.h> /*for winsize */ #if defined(MACOS) || !defined(TIOCGWINSZ) #include <sys/ioctl.h> #endif #include <stdio.h> /* for convenience */ #include <stdlib.h> /* for convenience */ #include <stddef.h> /* for offsetof */ #include <string.h> /* for convenience */ #include <unistd.h> /* for convenience */ #include <signal.h> /* for SIG_ERR */ #define MAXLINE 4096 /* max line length */ /* Default file access permissions for new files. */ #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) /* Default permissions for new directories.*/ #define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH) typedef void Sigfunc(int); /*for signal handlers */ #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) > (b) ? (a) : (b)) /* Prototypes for our own functions. */ char *path_alloc(size_t *); long open_max(void); int set_cloexec(int); void clr_fl(int,int); void set_fl(int,int); void pr_exit(int); void pr_mask(const char *); Sigfunc *signal_intr(int,Sigfunc *); void daemonize(const char *); void sleep_us(unsigned int); ssize_t readn(int,void *,size_t); ssize_t writen(int,const void *,size_t); int fd_pipe(int *); int recv_fd(int,ssize_t (*func)(int,const void*,size_t)); int send_fd(int,int); int send_err(int,int,const char *); int serv_listen(const char *); int serv_accept(int,uid_t *); int cli_conn(const char *); int buf_args(char *,int (*func)(int,char **)); int tty_cbreak(int); int tty_raw(int); int tty_reset(int); void tty_atexit(void); struct termios *tty_termios(void); int ptym_open(char *,int); int ptys_open(char *); #ifdef TIOCGWINSZ pid_t pty_fork(int *,char *,int,const struct termios *,const struct winsize *); #endif int lock_reg(int,int,int,off_t,int,off_t); #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)) pid_t lock_test(int,int,off_t,int,off_t); #define is_read_lockable(fd,offset,whence,len) (lock_test((fd),F_RDLCK,(offset),(whence),(len)) == 0) #define is_write_lockable(fd,offset,whence,len) (lock_test((fd),F_WRLCK,(offset),(whence),(len)) == 0) void err_msg(const char *,...); void err_dump(const char *,...) __attribute__((noreturn)); void err_quit(const char *,...) __attribute__((noreturn)); void err_cont(int,const char *,...); void err_exit(int,const char *,...) __attribute__((noreturn)); void err_ret(const char *,...); void err_sys(const char *,...) __attribute__((noreturn)); void log_msg(const char *,...); void log_open(const char *,int ,int); void log_quit(const char *,...) __attribute__((noreturn)); void log_ret(const char *,...); void log_sys(const char *,...) __attribute__((noreturn)); void log_exit(int,const char *,...) __attribute__((noreturn)); void TELL_WAIT(void); void TELL_PARENT(pid_t); void TELL_CHILD(pid_t); void WAIT_PARENT(void); void WAIT_CHILD(void); #endif /* apue_h */
apue的更多相关文章
- [APUE]进程控制(上)
一.进程标识 进程ID 0是调度进程,常常被称为交换进程(swapper).该进程并不执行任何磁盘上的程序--它是内核的一部分,因此也被称为系统进程.进程ID 1是init进程,在自举(bootstr ...
- [APUE]UNIX进程的环境(下)
一.共享库 共享库使得可执行文件中不再需要包含常用的库函数,而只需在所有进程都可存取的存储区中保存这种库例程的一个副本.程序第一次执行的时候或第一次调用某个库函数的时候,用动态链接方法将程序与共享库函 ...
- [APUE]标准IO库(下)
一.标准IO的效率 对比以下四个程序的用户CPU.系统CPU与时钟时间对比 程序1:系统IO 程序2:标准IO getc版本 程序3:标准IO fgets版本 结果: [注:该表截取自APUE,上表中 ...
- APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试
此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...
- APUE fig 1.10示例代码的完善--对提示符及输入回车的优化
APUE 第3版第15页的shell2.c示例程序,运行效果如下: gcc ol.shell.c -o origin_shell ./origin_shell % date 2015年12月13日 星 ...
- 关于apue.3e中apue.h的使用
关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...
- APUE学习之多线程编程(三):线程属性、同步属性
一.线程属性 可以使用pthread_attr_t结构修改线程默认属性,并这些属性和创建的线程练习起来,可以使用pthread_att_init函数初始化pthread_attr_t结构,调 ...
- APUE学习之多线程编程(二):线程同步
为了保证临界资源的安全性和可靠性,线程不得不使用锁,同一时间只允许一个或几个线程访问变量.常用的锁有互斥量,读写锁,条件变量 一.互斥量 互斥量是用pthrea ...
- APUE学习之多线程编程(一):线程的创建和销毁
一.线程标识 和每个进程都有一个进程ID一样,每个线程也有一个线程ID,线程ID是以pthread_t数据类型来表示的,在Linux中,用无符号长整型表示pthread_t,Solaris ...
- APUE学习之出错处理
当UNIX函数发生错误时,通常会返回一个负值,而且整形变量errno通常被设置为具有特定信息的值. errno是全局变量,仅当函数出错才有被改变.对待errno,应注意两条规则 ...
随机推荐
- Java基础知识强化87:BigInteger类之BigInteger加减乘除法的使用
1. BigInteger加减乘除法的使用 public BigInteger add(BigInteger val):加 public BigInteger subtract(BigInteger ...
- linux性能调优概述
- 什么是性能调优?(what) - 为什么需要性能调优?(why) - 什么时候需要性能调优?(when) - 什么地方需要性能调优?(where) - 什么人来进行性能调优?(who) - 怎么样 ...
- 窗口 对话框 Pop Dialog 示例
两者的区别 PopupWindow和AlertDialog最大的区别: AlertDialog是非阻塞线程的,AlertDialog弹出的时候,后台可以做其他事情(也即弹出对话框后程序会继续向下执行) ...
- css08盒子模型
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 10-利用com组件读取office
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Android Studio错误
晚上一直在折腾android studio这个东西,弄的蛋疼.. 之前是有用的,然后今天闲的没事干,更新了下,反正弄出了一大堆的错误.. 错误:failed to find Build Tools r ...
- PHP 单链表
<?php class Hero { public $no; public $name; public $nickname; public $next=null; public function ...
- 【转】Multithreaded Python Tutorial with the “Threadworms” Demo
The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works wi ...
- 让sublime支持gbk常用编码
Sublime Text 2是一个非常不错的源代码及文本编辑器,但是不支持GB2312和GBK编码在很多情况下会非常麻烦.不过Sublime Package Control所以供的插件可以让Subli ...
- MOOTOOLS和JQUERY如何同时存在,解决冲突
mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...