#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的更多相关文章

  1. [APUE]进程控制(上)

    一.进程标识 进程ID 0是调度进程,常常被称为交换进程(swapper).该进程并不执行任何磁盘上的程序--它是内核的一部分,因此也被称为系统进程.进程ID 1是init进程,在自举(bootstr ...

  2. [APUE]UNIX进程的环境(下)

    一.共享库 共享库使得可执行文件中不再需要包含常用的库函数,而只需在所有进程都可存取的存储区中保存这种库例程的一个副本.程序第一次执行的时候或第一次调用某个库函数的时候,用动态链接方法将程序与共享库函 ...

  3. [APUE]标准IO库(下)

    一.标准IO的效率 对比以下四个程序的用户CPU.系统CPU与时钟时间对比 程序1:系统IO 程序2:标准IO getc版本 程序3:标准IO fgets版本 结果: [注:该表截取自APUE,上表中 ...

  4. APUE中fcntl.h的使用及O_SYNC在Mac与Ubuntu下的测试

    此部分测试涉及到APUE V3中,第三章的图3-12到图3-14. 通过fcntl.h提供的功能,修改fd的文件属性,本处增加O_SYNC功能,并测试其效果. 本文涉及代码: tree ch3 ch3 ...

  5. APUE fig 1.10示例代码的完善--对提示符及输入回车的优化

    APUE 第3版第15页的shell2.c示例程序,运行效果如下: gcc ol.shell.c -o origin_shell ./origin_shell % date 2015年12月13日 星 ...

  6. 关于apue.3e中apue.h的使用

    关于apue.3e中apue.h的使用 近来要学一遍APUE第三版,并于此开博做为记录. 先下载源文件: # url: http://http//www.apuebook.com/code3e.htm ...

  7. APUE学习之多线程编程(三):线程属性、同步属性

    一.线程属性      可以使用pthread_attr_t结构修改线程默认属性,并这些属性和创建的线程练习起来,可以使用pthread_att_init函数初始化pthread_attr_t结构,调 ...

  8. APUE学习之多线程编程(二):线程同步

         为了保证临界资源的安全性和可靠性,线程不得不使用锁,同一时间只允许一个或几个线程访问变量.常用的锁有互斥量,读写锁,条件变量           一.互斥量      互斥量是用pthrea ...

  9. APUE学习之多线程编程(一):线程的创建和销毁

    一.线程标识      和每个进程都有一个进程ID一样,每个线程也有一个线程ID,线程ID是以pthread_t数据类型来表示的,在Linux中,用无符号长整型表示pthread_t,Solaris ...

  10. APUE学习之出错处理

         当UNIX函数发生错误时,通常会返回一个负值,而且整形变量errno通常被设置为具有特定信息的值.        errno是全局变量,仅当函数出错才有被改变.对待errno,应注意两条规则 ...

随机推荐

  1. jquery实现图片切换和js实现图片切换

    jquery实现图片切换: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  2. TCP_DEFER_ACCEPT的坑

    我实现了一个server,支持HTTP协议和内部私有协议,为了简化部署,我设计成一个端口同时兼容两种协议的客户端.根据连接后到达的消息头自动识别客户端协议.这种事情的传统做法是,accept后加入ep ...

  3. C#获取显示器宽度高度,桌面宽度高度等

    1.C#获取显示器宽度高度,桌面宽度高度等 //获取当前显示器的宽度和高度 int width = Screen.PrimaryScreen.Bounds.Width; int height = Sc ...

  4. HTML 控件和web控件 OnClientClick和OnClick OnServerClick区别

      ^_^ 本来对html控件,服务器控件的知识模模糊糊的.今天特地查了相关的知识. 下面是我写代码总结的. 这些事件   主要用于在客户端执行验证,然后决定是否执行服务端事件   (没接触之前就为此 ...

  5. require(),include(),require_once()和include_once()之间的区别

    引用文件的方法有两种:require 及 include. require 的使用方法如 require("file.php"); .这个函数通常放在 PHP 程序的最前面,PHP ...

  6. python记录

    1. 序列的分片操作:需要提供两个索引作为边界,第1个索引的元素包含在分片内,第2个索引的元素不包含在分片内. 为了能让分片部分能够包含列表的最后一个元素,必需提供最后一个元素的下一个元素所对应的索引 ...

  7. centos 安装php

    1.yum安装 yum install php php-fpm php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash ph ...

  8. mysql中的JOIN用法总结

    join是mysql中一个基础的关键词,一般在多表连接查询中使用,这里做一下总结 1.JOIN的语法格式 table_references: table_reference [, table_refe ...

  9. ubuntu 第一次安装时 默认root 密码设置

    Ubuntu刚安装后,不能在terminal中运行su命令,因为root没有默认密码,需要手动设定. 以安装ubuntu时输入的用户名登陆,该用户在admin组中,有权限给root设定密码. 给roo ...

  10. 11061160顾泽鹏homework-01

    我的Github地址是buaa11061160 教材:中文版 代码大全 (第二版) 斯蒂夫·迈克康奈尔 设计思路: 输入了一串数组a[0].a[1]..... 从a[0]开始向后扫,在以数字a[i]结 ...