error proc
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2014. *
* *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 or (at your option) *
* any later version. This program is distributed without any warranty. *
* See the files COPYING.lgpl-v3 and COPYING.gpl-v3 for details. *
\*************************************************************************/ /* error_functions.c Some standard error handling routines used by various programs.
*/
#include <stdarg.h>
#include "error_functions.h"
#include "tlpi_hdr.h"
#include "ename.c.inc" /* Defines ename and MAX_ENAME */ #ifdef __GNUC__ /* Prevent 'gcc -Wall' complaining */
__attribute__ ((__noreturn__)) /* if we call this function as last */
#endif /* statement in a non-void function */
static void
terminate(Boolean useExit3)
{
char *s; /* Dump core if EF_DUMPCORE environment variable is defined and
is a nonempty string; otherwise call exit(3) or _exit(2),
depending on the value of 'useExit3'. */ s = getenv("EF_DUMPCORE"); if (s != NULL && *s != '\0')
abort();
else if (useExit3)
exit(EXIT_FAILURE);
else
_exit(EXIT_FAILURE);
} /* Diagnose 'errno' error by: * outputting a string containing the error name (if available
in 'ename' array) corresponding to the value in 'err', along
with the corresponding error message from strerror(), and * outputting the caller-supplied error message specified in
'format' and 'ap'. */ static void
outputError(Boolean useErr, int err, Boolean flushStdout,
const char *format, va_list ap)
{
#define BUF_SIZE 500
char buf[BUF_SIZE], userMsg[BUF_SIZE], errText[BUF_SIZE]; vsnprintf(userMsg, BUF_SIZE, format, ap); if (useErr)
snprintf(errText, BUF_SIZE, " [%s %s]",
(err > && err <= MAX_ENAME) ?
ename[err] : "?UNKNOWN?", strerror(err));
else
snprintf(errText, BUF_SIZE, ":"); snprintf(buf, BUF_SIZE, "ERROR%s %s\n", errText, userMsg); if (flushStdout)
fflush(stdout); /* Flush any pending stdout */
fputs(buf, stderr);
fflush(stderr); /* In case stderr is not line-buffered */
} /* Display error message including 'errno' diagnostic, and
return to caller */ void
errMsg(const char *format, ...)
{
va_list argList;
int savedErrno; savedErrno = errno; /* In case we change it here */ va_start(argList, format);
outputError(TRUE, errno, TRUE, format, argList);
va_end(argList); errno = savedErrno;
} /* Display error message including 'errno' diagnostic, and
terminate the process */ void
errExit(const char *format, ...)
{
va_list argList; va_start(argList, format);
outputError(TRUE, errno, TRUE, format, argList);
va_end(argList); terminate(TRUE);
} /* Display error message including 'errno' diagnostic, and
terminate the process by calling _exit(). The relationship between this function and errExit() is analogous
to that between _exit(2) and exit(3): unlike errExit(), this
function does not flush stdout and calls _exit(2) to terminate the
process (rather than exit(3), which would cause exit handlers to be
invoked). These differences make this function especially useful in a library
function that creates a child process that must then terminate
because of an error: the child must terminate without flushing
stdio buffers that were partially filled by the caller and without
invoking exit handlers that were established by the caller. */ void
err_exit(const char *format, ...)
{
va_list argList; va_start(argList, format);
outputError(TRUE, errno, FALSE, format, argList);
va_end(argList); terminate(FALSE);
} /* The following function does the same as errExit(), but expects
the error number in 'errnum' */ void
errExitEN(int errnum, const char *format, ...)
{
va_list argList; va_start(argList, format);
outputError(TRUE, errnum, TRUE, format, argList);
va_end(argList); terminate(TRUE);
} /* Print an error message (without an 'errno' diagnostic) */ void
fatal(const char *format, ...)
{
va_list argList; va_start(argList, format);
outputError(FALSE, , TRUE, format, argList);
va_end(argList); terminate(TRUE);
} /* Print a command usage error message and terminate the process */ void
usageErr(const char *format, ...)
{
va_list argList; fflush(stdout); /* Flush any pending stdout */ fprintf(stderr, "Usage: ");
va_start(argList, format);
vfprintf(stderr, format, argList);
va_end(argList); fflush(stderr); /* In case stderr is not line-buffered */
exit(EXIT_FAILURE);
} /* Diagnose an error in command-line arguments and
terminate the process */ void
cmdLineErr(const char *format, ...)
{
va_list argList; fflush(stdout); /* Flush any pending stdout */ fprintf(stderr, "Command-line usage error: ");
va_start(argList, format);
vfprintf(stderr, format, argList);
va_end(argList); fflush(stderr); /* In case stderr is not line-buffered */
exit(EXIT_FAILURE);
}
/*************************************************************************\
* Copyright (C) Michael Kerrisk, 2014. *
* *
* This program is free software. You may use, modify, and redistribute it *
* under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation, either version 3 or (at your option) *
* any later version. This program is distributed without any warranty. *
* See the files COPYING.lgpl-v3 and COPYING.gpl-v3 for details. *
\*************************************************************************/ /* error_functions.h Header file for error_functions.c.
*/
#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H /* Error diagnostic routines */ void errMsg(const char *format, ...); #ifdef __GNUC__ /* This macro stops 'gcc -Wall' complaining that "control reaches
end of non-void function" if we use the following functions to
terminate main() or some other non-void function. */ #define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif void errExit(const char *format, ...) NORETURN ; void err_exit(const char *format, ...) NORETURN ; void errExitEN(int errnum, const char *format, ...) NORETURN ; void fatal(const char *format, ...) NORETURN ; void usageErr(const char *format, ...) NORETURN ; void cmdLineErr(const char *format, ...) NORETURN ; #endif
error proc的更多相关文章
- Ruby Proc 和 lambda的共同点和区别
Proc 和 lambda 的目的是把block {....} 变成类似方法一样的对象,使其不需要重复编写同样的block. Proc 和 lambda 的共同点: 语法类似Proc.new{|n| ...
- [python] python单元测试经验总结
python写单元大多数都会用到unittest和mock,测试代码覆盖率都会用到coverage,最后再用nose把所有的东西都串起来,这样每次出版本,都能把整个项目的单元测试都运行一遍. Unit ...
- iBatis --> MyBatis
从 Clinton Begin 到 Google(从 iBatis 到 MyBatis,从 Apache Software Foundation 到 Google Code),Apache 开源代码项 ...
- SQL异常捕获
直接上代码: GO BEGIN TRY DECLARE @res INT SET @res=1/0 PRINT 'no error' END TRY BEGIN CATCH PRINT 'Error ...
- check_mk检测插件 - raid监控
mk_raidstatus python版本 #!/usr/bin/env python # -*- encoding: utf-8; py-indent-offset: 4 -*- import s ...
- SQL Server2012 T-SQL基础教程--读书笔记(8 - 10章)
SQL Server2012 T-SQL基础教程--读书笔记(8 - 10章) 示例数据库:点我 CHAPTER 08 数据修改 8.1 插入数据 8.1.1 INSERT VALUES 语句 8.1 ...
- Java SPI机制:ServiceLoader实现原理及应用剖析
一.背景 SPI,全称Service Provider Interfaces,服务提供接口.是Java提供的一套供第三方实现或扩展使用的技术体系.主要通过解耦服务具体实现以及服务使用,使得程序的可扩展 ...
- c#项目调用Python模块的方法
将Python模块用pyinstaller打包成exe程序 下载安装UPX((http://upx.sourceforge.net/)) ,并把路径加到环境变量中. UPX是开源的加壳和压缩exe的程 ...
- ArcGIS Pro 二次开发
本文基于 Windows7 + VS2019 + .NET Framework 4.8 + ArcGIS Pro 2.5.22081 开发和撰写. 目录 开发环境配置 获取ArcGIS Pro 安装V ...
随机推荐
- MVC中一般为什么用IQueryable而不是用IList
IList(IList<T>)会立即在内存里创建持久数据,这就没有实现“延期执行(deferred execution)”,如果被加载的实体有关联实体(associations),此关联实 ...
- 经典SQL语句大全之数据开发
数据开发 1.按姓氏笔画排序:Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as //从少到多 ...
- ffprobe使用具体解释
夹 1. 语法 2. 描写叙述 3. 选项 3.1 流指示符 3.2 通用选项 3.3 音视频选项 3.4 主选项 4. 写入器 4.1 默认值 4.2 compact, csv 4.3 flat 4 ...
- mybatis06 增删改差 源码
user.java package cn.itcast.mybatis.po; import java.util.Date; public class User { private int id; p ...
- oracle9
约束 维护数据的完整性 数据的完整性用于确保数据库数据遵从一定的商业和逻辑规则(比如年纪不能为-,性别不能为非男女),在oracle中,数据完整性可以使用约束.触发器.应用程序(过程.函数)三种方法来 ...
- GO的跨平台数扰类型
基本数据类型的包装: 1.跨平台,用于移植 2.不同的框架类型包装的类型(MFC ,WIN32SDK,C) 3.基本数据类型的组装成的结构体 4.宏定义 数字类型 Go 也有基于架构的类型,例如:in ...
- Servlet中文乱码解决方法
程序中的输入输出都是以流的形式保存的,流中保存的实际上全都是字节文件. 字节流和字符流的区别: 在Java.io包中操作文件内容的主要有两大类:字节流.字符流,两类都分为输入和输出操作. 在字节流中输 ...
- Android开发之ViewPager实现轮播图(轮播广告)效果的自定义View
最近开发中需要做一个类似京东首页那样的广告轮播效果,于是采用ViewPager自己自定义了一个轮播图效果的View. 主要原理就是利用定时任务器定时切换ViewPager的页面. 效果图如下: 主页面 ...
- GUI编程笔记(java)04:GUI(HelloWorld)窗体案例
1.Frame 在JAVA中,Frame是一种控件,可作为父窗体加载其他swing控件.案例: package cn.itcast_01; import java.awt.Frame; public ...
- 大数据应用:五大地区喜新厌旧游戏APP类别之比较与分析
今天,我们来分享点不一样的资讯.....游戏APP之喜新厌旧排行榜!! 前阵子笔者开发了一套系统可以用来收集亚洲五大地区上架APP的每日排名信息,希望观察出五大地区在APP上的喜好和使用程度之间的相异 ...