#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ANSI C header file */
#include "ourhdr.h"
static void err_doit(int, const char *, va_list);
char *pname = NULL; /* caller can set this from argv[0] */
/* 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, fmt, ap);
va_end(ap);
return;
}
/* 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, fmt, ap);
va_end(ap);
exit(1);
}
/* Fatal error related to a system call.
Print a message and terminate. */
void
err_dump(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(1, 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, fmt, ap);
va_end(ap);
return;
}
/* 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, fmt, ap);
va_end(ap);
exit(1);
}
/* Print a message and return to caller.
Caller specifies "errnoflag". */
static void
err_doit(int errnoflag, const char *fmt, va_list ap)
{
int errno_save;
char buf[MAXLINE];
errno_save = errno; /* value caller might want printed */
vsprintf(buf, fmt, ap);
if (errnoflag)
sprintf (buf+strlen(buf), ": %s", strerror (errno_save));
strcat (buf, "\n");
fflush(stdout); /* in case stdout and stderr are the same */
fputs(buf, stderr);
fflush(NULL); /* flushes all stdio output streams */
return;
}
分享到:
相关推荐
ourhdr.h ourhdr.c apue.h error.c
C中的ourhdr.h C中的ourhdr.hC中的ourhdr.hC中的ourhdr.hC中的ourhdr.h
UNIX环境高级编程 里的 ourhdr.h!
本人在学习《unix高级编程》的实例练习时,发现例子程序无法编译(linux平台),其中提示“error: ourhdr.h: No such file or directory”找不到头文件“ourhdr.h”。 当追加了上面的头文件后,有可能还是编译不过,...
终于发现这个完整的文件然后把它全部打出来,已经调试没有错误,希望能对大家有帮助。
UNIX环境高级编程示例代码头文件 ourhdr.h。
骐哥在学习unix 高级环境编程时 用的ourheader 也就是ourhdr.h文件
unix环境高级编程2的apue.h头文件
unix网络编程 所需头文件 apue.h ourhdr.h myerr.h if_dl.h
ourhdr.h是学习UNIX环境高级编程必用到的一个头文件,几乎每个程序都必须加上这个头文件。
#include "ourhdr.h" int main(void) /* 44BSD version */ { struct passwd *ptr; if ( (ptr = getpwnam("stevens")) == NULL) err_sys("getpwnam error"); printf("pw_passwd = %s\n", ptr->pw_passwd...
LINUX的圣经,找个资源不容易,这里把英文版,中文文字版,ourhdr.h myerror.c以及课后习题都打包分享给大家
unix环境高级编程(第二版)附源代码.rar 第一版本的ourhdr.h 第二版改为upue.h 函数实现在error.c文件中
《unix环境高级编程》里面的几乎所有的程序都用到的ourhdr.h,亲测可以使用,需哟啊的下载