linux 错误处理
linux程序设计中,有许多系统调用和函数会因为各种原因而失败.在失败时设置外部变量errno的值来指明失败原因.程序必须在函数报告出错之后立即检查errno变量,因为它可能被下一个函数调用所覆盖(外部变量errno只有一个,所有的失败调用(这些调用指的是失败会设置errno的调用)都会设置errno).
错误代码的取值和含义都列在errno.h里
EPERM: 操作不允许
ENOENT:文件或目录不存在
EINTR:系统调用被中断
EIO: I/O错误
EBUSY:设备或资源忙
EEXIST:文件存在
EINVAL:无效参数
EMFILE:打开的文件过多
ENODEV:设备不存在
EISDIR:是一个目录
ENOTDIR:不是一个目录
函数strerror 和 perror
strerror:把错误代码映射为一个字符串 #include <string.h> char *strerror( int errnum ). 该函数返回errnum对应的错误的描述 的字符串.如printf("%d : %s\n", i, strerror(5));
perror:用 来 将 上 一 个 函 数 发 生 错 误 的 原 因 输 出 到 标 准 错误 (stderr) 。参数 s 所指的字符串会先打印出,后面再加上错误原因字符串。此错误原因依照全局变量errno 的值来决定要输出的字符串。
linux 错误处理的更多相关文章
- 【转载】重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...
- 重置密码解决MySQL for Linux错误 ERROR 1045 (28000)
重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor ...
- 【linux错误解决】MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'的问题
问题描述: 从一台linux远程连接另一台linux上的MySQL, 出现ERROR 2003 (HY000): Can't connect to MySQL server on 'xxx.xxx.x ...
- 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor
一般这个错误是由密码错误引起,解决的办法自然就是重置密码. 假设我们使用的是root账户. 1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下: #vim /etc/my.cnf(注:wi ...
- 重置密码解决MySQL for Linux错误 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
出现报错: Warning: World-writable config file '/etc/my.cnf' is ignored // 该文件权限过高ERROR 1045 (28000): Acc ...
- MySQL linux错误处理
https://cloud.tencent.com/developer/article/1023732 mysql5.7 ERROR 1045 (28000): Access denied for u ...
- Linux 错误: $'\r': command not found
是linux无法解析$'\r'.这其实是windows与linux系统的差异导致的. 因为linux上的换行符为\n,而windows上的换行符为\r\n.所以脚本到linux上就无法解析了. 通常的 ...
- linux错误: locate: can not stat () `/var/lib/mlocate/mlocate.db': No such file or directory
命令 locate my.cnf 产生以上错误 此时执行 # updatedb 更新下数据库即可
- linux 错误总结
帝国cms登录后台提示“登录成功”,接着又提示“您还未登录” 把帝国cms文件夹下的/e/data/adminlogin 目录权限不可写导致,请将此目录权限设置为777权限即可解决.就可以正常登录后台 ...
随机推荐
- Do It Wrong, Get It Right
Do It Wrong, Get It Right Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB Total ...
- PCL常见编程问题
1.如何获取pcd文件点云里点的格式,比如是pcl::PointXYZ还是pcl::PointXYZRGB等类型? #include <pcl/io/pcd_io.h> #include ...
- ✡ leetcode 168. Excel Sheet Column Title 26进制数字 --------- java
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For exa ...
- 【转载】ANSYS动力学分析-瞬态分析
原文地址:http://www.cnblogs.com/ylhome/archive/2009/12/02/1615172.html 三种求解方法 瞬态动力学分析可采用三种方法:完全(Full)法.缩 ...
- [轉]Android Libraries 介紹 - Butter knife
原文地址 Butter Knife 簡介 Butter Knife - Field and method binding for Android views.助你簡化程式碼,方便閱讀. 使用方法 開發 ...
- LeetCode "Top K Frequent Elements"
A typical solution is heap based - "top K". Complexity is O(nlgk). typedef pair<int, un ...
- bzoj2518: [Shoi2010]滚动的正四面体
Description 正四面体总共有4个面,每个面都是一个正三角形.现在把它的一个面标记上字母A,如图 3中所示,A标记在底面上: 于是,这个正四面体的滚动过程就可以用一个只包含“L”“R”“B”的 ...
- http://www.iis.net/downloads/microsoft/url-rewrite
http://www.iis.net/downloads/microsoft/url-rewrite iis url重写模块.官方下载
- Xcode取消某条警告
[Xcode取消某条警告] 像下面这样,把双引号“”内的内容替成实际的警告类型即可. #pragma clang diagnostic push #pragma clang diagnostic ...
- Aquarium Cycling
http://www.fishyou.com/aquarium-cycling.php Aquarium Cycling Aquarium cycling actually refers to the ...