//在学UNIX环境高级编程时把下面两个头文件与源文件放在同一个文件下就可以正常编译了,我的是在ubuntu 12.04环境下,第一个程序编译和运行成功了,希望对大家有帮助(我已经根据网上的资料修改好两个头文件)

/* Our own header, to be included *after* all standard system headers */
//ourhdr.h

#ifndef__ourhdr_h
#define__ourhdr_h

#include<sys/types.h>/* required for some of our prototypes */
#include<stdio.h>/* for convenience */
#include<stdlib.h>/* for convenience */
#include<string.h>/* for convenience */
#include<unistd.h>/* for convenience */

#defineMAXLINE4096/* max line length */

#defineFILE_MODE(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
/* default file access permissions for new files */
#defineDIR_MODE(FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
/* default permissions for new directories */

typedefvoid Sigfunc(int);/* for signal handlers */

/* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */
#ifdefined(SIG_IGN) && !defined(SIG_ERR)
#defineSIG_ERR((Sigfunc *)-1)
#endif

#definemin(a,b)((a) < (b) ? (a) : (b))
#definemax(a,b)((a) > (b) ? (a) : (b))

/* prototypes for our own functions */
char*path_alloc(int *);/* {Prog pathalloc} */
intopen_max(void);/* {Prog openmax} */
voidclr_fl(int, int);/* {Prog setfl} */
voidset_fl(int, int);/* {Prog setfl} */
voidpr_exit(int);/* {Prog prexit} */
voidpr_mask(const char *);/* {Prog prmask} */
Sigfunc*signal_intr(int, Sigfunc *);/* {Prog signal_intr_function} */

inttty_cbreak(int);/* {Prog raw} */
inttty_raw(int);/* {Prog raw} */
inttty_reset(int);/* {Prog raw} */
voidtty_atexit(void);/* {Prog raw} */
#ifdefECHO /* only if <termios.h> has been included */
struct termios*tty_termios(void);/* {Prog raw} */
#endif

voidsleep_us(unsigned int);/* {Ex sleepus} */
ssize_treadn(int, void *, size_t);/* {Prog readn} */
ssize_twriten(int, const void *, size_t);/* {Prog writen} */
intdaemon_init(void);/* {Prog daemoninit} */

ints_pipe(int *);/* {Progs svr4_spipe bsd_spipe} */
intrecv_fd(int, ssize_t (*func)(int, const void *, size_t));
/* {Progs recvfd_svr4 recvfd_43bsd} */
intsend_fd(int, int);/* {Progs sendfd_svr4 sendfd_43bsd} */
intsend_err(int, int, const char *);/* {Prog senderr} */
intserv_listen(const char *);/* {Progs servlisten_svr4 servlisten_44bsd} */
intserv_accept(int, uid_t *);/* {Progs servaccept_svr4 servaccept_44bsd} */
intcli_conn(const char *);/* {Progs cliconn_svr4 cliconn_44bsd} */
intbuf_args(char *, int (*func)(int, char **));
/* {Prog bufargs} */

intptym_open(char *);/* {Progs ptyopen_svr4 ptyopen_44bsd} */
intptys_open(int, char *);/* {Progs ptyopen_svr4 ptyopen_44bsd} */
#ifdefTIOCGWINSZ
pid_tpty_fork(int *, char *, const struct termios *,
 const struct winsize *);/* {Prog ptyfork} */
#endif

intlock_reg(int, int, int, off_t, int, off_t);
/* {Prog lockreg} */
#defineread_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
#definereadw_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
#definewrite_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
#definewritew_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
#defineun_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)

pid_tlock_test(int, int, off_t, int, off_t);
/* {Prog locktest} */

#defineis_readlock(fd, offset, whence, len) \
lock_test(fd, F_RDLCK, offset, whence, len)
#defineis_writelock(fd, offset, whence, len) \
lock_test(fd, F_WRLCK, offset, whence, len)

voiderr_dump(const char *, ...);/* {App misc_source} */
voiderr_msg(const char *, ...);
voiderr_quit(const char *, ...);
voiderr_ret(const char *, ...);
voiderr_sys(const char *, ...);

voidlog_msg(const char *, ...);/* {App misc_source} */
voidlog_open(const char *, int, int);
voidlog_quit(const char *, ...);
voidlog_ret(const char *, ...);
voidlog_sys(const char *, ...);

voidTELL_WAIT(void);/* parent/child from {Sec race_conditions} */
voidTELL_PARENT(pid_t);
voidTELL_CHILD(pid_t);
voidWAIT_PARENT(void);
voidWAIT_CHILD(void);

#endif/* __ourhdr_h */

//myerr.h

#include "ourhdr.h"
#include <errno.h>/* for definition of errno */
#include <stdarg.h>/* ISO C variable aruments */

static voiderr_doit(int, int, const char *, va_list);

/*
 * Nonfatal error related to a system call.
 * Print a message and return.
 */
void
err_ret(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(1, errno, fmt, ap);
va_end(ap);
}

/*
 * Fatal error related to a system call.
 * Print a message and terminate.
 */
void
err_sys(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(1, errno, fmt, ap);
va_end(ap);
exit(1);
}

/*
 * Fatal error unrelated to a system call.
 * Error code passed as explict parameter.
 * Print a message and terminate.
 */
void
err_exit(int error, const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(1, error, fmt, ap);
va_end(ap);
exit(1);
}

/*
 * Fatal error related to a system call.
 * Print a message, dump core, and terminate.
 */
void
err_dump(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(1, errno, fmt, ap);
va_end(ap);
abort(); /* dump core and terminate */
exit(1); /* shouldn't get here */
}

/*
 * Nonfatal error unrelated to a system call.
 * Print a message and return.
 */
void
err_msg(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(0, 0, fmt, ap);
va_end(ap);
}

/*
 * Fatal error unrelated to a system call.
 * Print a message and terminate.
 */
void
err_quit(const char *fmt, ...)
{
va_list ap;

va_start(ap, fmt);
err_doit(0, 0, fmt, ap);
va_end(ap);
exit(1);
}

/*
 * Print a message and return to caller.
 * Caller specifies "errnoflag".
 */
static void
err_doit(int errnoflag, int error, const char *fmt, va_list ap)
{
charbuf[MAXLINE];

vsnprintf(buf, MAXLINE, fmt, ap);
if (errnoflag)
snprintf(buf+strlen(buf), MAXLINE-strlen(buf), ": %s",
 strerror(error));
strcat(buf, "\n");
fflush(stdout);/* in case stdout and stderr are the same */
fputs(buf, stderr);
fflush(NULL); /* flushes all stdio output streams */
}

unix ourhdr.h myerr.h的更多相关文章

  1. sys/types.h fcntl.h unistd.h sys/stat.h

    sys/types.h 是Unix/Linux系统的基本系统数据类型的头文件,含有size_t,time_t,pid_t等类型. 在应用程序源文件中包含 <sys/types.h> 以访问 ...

  2. Sed命令n,N,d,D,p,P,h,H,g,G,x解析3

    摘自:https://blog.csdn.net/WMSOK/article/details/78463199 Sed命令n,N,d,D,p,P,h,H,g,G,x解析 2017年11月06日 23: ...

  3. sed命令n,N,d,D,p,P,h,H,g,G,x解析2

    摘自: https://blog.csdn.net/xiexingshishu/article/details/50514132 sed命令n,N,d,D,p,P,h,H,g,G,x解析 2016年0 ...

  4. oc 与 swift 之间的桥接文件 (ProjectNmae-Bridging-Header.h) (ProjectNmae-Swift.h)

    oc 与 Swift 是2种不同的语言, oc代码只能写带oc文件里, Swift代码只能写在Swift文件里, 虽然2者不同语言, 但却能互相调用, 不过需要进行一下桥接, 就是下面的2个文件 (P ...

  5. jpeglib.h jerror.h No such file or directory 以及 SDL/SDL.h: 没有那个文件

    1. error: jpeglib.h jerror.h No such file or directory 没有那个文件或目录 jpeg.cc:19:21:error: jpeglib.h: 没有那 ...

  6. H.265 & H.264

    H.265 & H.264 HEVC (H.265) vs. AVC (H.264) https://en.wikipedia.org/wiki/High_Efficiency_Video_C ...

  7. stdlib.h stdio.h

    stdlib.h 即standard library标准库头文件.stdlib.h里面定义了五种类型.一些宏和通用工具函数. 类型例如size_t.wchar_t.div_t.ldiv_t和lldiv ...

  8. pod JONSKit.h MBProgress.h 找不到头文件,怎么办?

    这时你看项目pod部分,多了JSONKit库.好了,第三方库就这么神奇的加进来. 头文件路径 那试试看使用JONSKit.h,在ViewController.m里引用下.找不到头文件,怎么办?还没设置 ...

  9. 走进C标准库(1)——assert.h,ctype.h

    默默觉得原来的阅读笔记的名字太土了,改了个名字,叫做走进C标准库. 自己就是菜鸟一只,第一次具体看C标准库,文章参杂了对<the standard C library>的阅读和对源码的一些 ...

随机推荐

  1. [Swust OJ 1026]--Egg pain's hzf

      题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf ...

  2. 4.I/O复用以及基于I/O复用的回射客户端/服务器

    I/O复用:当一个或多个I/O条件满足时,我们就被通知到,这种能力被称为I/O复用. 1.I/O复用的相关系统调用 posix的实现提供了select.poll.epoll两类系统调用以及相关的函数来 ...

  3. MVC 扩展 Html.ImageFor

    Asp.Net MVC 扩展 Html.ImageFor 方法详解 背景: 在Asp.net MVC中定义模型的时候,DataType有DataType.ImageUrl这个类型,但htmlhelpe ...

  4. python 正则表达式汇总

    一. 正则表达式基础 1.1.概念介绍 正则表达式是用于处理字符串的强大工具,它并不是Python的一部分. 其他编程语言中也有正则表达式的概念,区别只在于不同的编程语言实现支持的语法数量不同. 它拥 ...

  5. svn修改log信息

    在linux下安装了SVN服务器来做版本控制. 有天提交文件忘记了填写SVN提交日志,于是在项目中使用右键,show log,找到我提交的无日志的那条记录,点击右健,选择了“Edit log mess ...

  6. 数据库中操作XML(openXML)

    最近公司项目需要在数据库中操作XML,因此系统的学习了一下 一.openxml的格式 OPENXML( idoc int [ in] , XPathnvarchar [ in ] , [ flags ...

  7. Net::OpenSSH 使用例子

    [root@dr-mysql01 mojo]# cat a1.pl use Net::OpenSSH; my $host = '121.4xx.xx1.41'; my $user = 'root'; ...

  8. cocos2dx进阶学习之CCEGLView

    继承关系 CCEGLView-> CCEGLViewProtocol CCEGLView是窗口,在不同平台上有不同的实现,而CCEGLViewProtocol是CCEGLView定义的接口,所以 ...

  9. paip.输入法编程---输入法ATIaN历史记录 c823

    paip.输入法编程---输入法ATIaN历史记录 c823 作者Attilax ,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csd ...

  10. linux eclipse中运行android AVD 错误

    当使用android的AVD时提示以下错误: Starting emulator for AVD 'NexusOne' ERROR: 32-bit Linux Android emulator bin ...