当前位置:网站首页>Detailed explanation of errno
Detailed explanation of errno
2022-07-19 01:51:00 【tissar】
errno Detailed explanation
effect
errno yes error number Abbreviation , It means the system call error code .
If the system call returns success ,errno It is possible, but not necessarily 0; When the system call fails ,errno It must be set to the corresponding error number . therefore , OCD patients can call the system call before , Manual will errno Set up 0. however , If the system call returns success , Who will be free to see errno Well ?
Correlation function
Generally speaking , Do we need to know each errno What does the number of mean . We will use two C Library functions help us translate errno That's what it means .
They are :
#include <string.h>
char *strerror(int errnum);
#include <stdio.h>
void perror(const char *msg);
Multithreading
Before multithreading ,errno It's actually a global variable . It's easy to understand , But it's past tense .
Because every thread may call system calls , Then the subsequent mistakes , It will cover the previous errors . If we can't guarantee errno The reliability of the , that errno What's the point? ?
therefore , It has changed .
- When multithreading , Need to include header file
#include <errno.h> - errno It is no longer a global variable , Now it has become a macro
although errno Changed , But it's still an lvalue ( The left value can be written as “ The left value = Right value ” In the form of ).
What the hell is this macro ? Don't wait to decompose , Let's keep looking :
extern int *__errno_location(void);
#define errno (*__errno_location())
First , Declared functions from outside __errno_location(); Watch out! , The return value of this function is a function pointer , This pointer points to the thread's own errno The location of , By dereferencing this pointer , You can access the thread only errno.
therefore ,errno Is defined as (*__errno_location()).
边栏推荐
猜你喜欢

争夺存量用户关键战,助力企业构建完美标签体系丨01期直播回顾

The popularity of NFT IP licensing is rising, and the era of nft2.0 is coming?

Learning Transferable Visual Models From Natural Language Supervision

Why is opensea the absolute monopolist of NFT trading market?

4章 性能平台GodEye源码分析-监控模块

MapReduce environment preparation

1章 性能平台GodEye源码分析-整体架构

NameNode 和 SecondaryNameNode

The interviewer asked: how to check if redis suddenly slows down?

Iptables and snort basic configuration
随机推荐
AXS is popular. What other gold games are there (Part 1)
The popularity of NFT IP licensing is rising, and the era of nft2.0 is coming?
mysql innodb 事务相关记录
【文献阅读】Counting Integer Points in Parametric Polytopes Using Barvinok‘s Rational Functions
常见的Go写文件方式
爭奪存量用戶關鍵戰,助力企業構建完美標簽體系丨01期直播回顧
Introduction to software vulnerability analysis (5)
数据指标体系如何搭建才最有效,从0到1带你快速入门丨02期直播回顾
2章 性能平台GodEye源码分析-数据模块
面向NDN的网络攻击检测技术分析
Why do you spend 1.16 million to buy an NFT avatar in the library of NFT digital collections? The answer may be found by reviewing the "rise history" of NFT avatars
MXNet网络模型(四)GAN神经网络
Cocos Creator 3.0 基础——事件系统
Punch in 10 interview questions every day - JVM article
量子计算机带来的全新通信安全风险分析及应对建议
走好数据中台最后一公里,为什么说数据服务API是数据中台的标配?
ACE下载地址
【Go语言】动态库和静态库详解
通信感知一体化应用场景、关键技术和网络架构
touchID 和 FaceID~1