//在学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. 【Linux命令】命令行查找文件并进行操作

    查找: #找./下的所有txt文件,输出个数 find ./ -name "*.txt" | wc -l #查找并删除 find ./ -name "*.txt" ...

  2. mysql自动备份(windows)

    许多时候,为了数据安全,我们的mysql数据库需要定期进行备份,下面介绍两种在windows下自动备份方法: 1.复制date文件夹备份 ============================ 例子 ...

  3. win32下利用python操作printer

    在win32下操作printer:   1)import win32print   2) 获得默认打印机名:          >>> win32print.GetDefaultPr ...

  4. Oauth1.0认证过程

    现今,已经有了Oauth2.0,写篇博客了解Oauth1.0的过程以及与2.0的区别. 在Oauth官网  关于1.0的介绍: 一.简介 OAuth authentication is the pro ...

  5. emoji表情键盘 回退删除方法

  6. 杭电--1862--EXCEL排序--结构体排序

    EXCEL排序 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  7. muduo 与 libevent2 吞吐量对照

    libevent 是一款很好用的 C 语言网络库,它也採用 Reactor 模型,正好能够与 muduo 做一对照. 本文用 ping pong 測试来对照 muduo 和 libevent2 的吞吐 ...

  8. android 4.0后不允许屏蔽掉home键

    屏蔽home键的方法 // 屏蔽掉Home键 public void onAttachedToWindow() { this.getWindow().setType(WindowManager.Lay ...

  9. hdu 1282回文数猜想

    http://acm.hdu.edu.cn/showproblem.php?pid=1282 Problem Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序 ...

  10. 用C语言怎么实现复制自己

    #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char str[80]; ...