当前位置:网站首页>Errno perrno and strerrno
Errno perrno and strerrno
2022-06-25 14:59:00 【qq_ twenty-three million nine hundred and fifty-three thousand 】
errno
The header file <errno.h>
errno It's a by POSIX and ISO C Symbols defined by the standard . When an error occurs in a system call or library function , For example, when opening a nonexistent file in an institutional way , Its value will be changed , according to errno The difference in value , We can see what went wrong with the program .
Such as error code errno by 12 The error is Cannot allocate memory
perror
The function prototype :void perror(const char *s)
Function description : Output the cause of the error in the previous function to the standard error (stderr), Parameters s The string pointed to will be printed out first , Then print the real error output , Such as perror(“ABC:”), String is ABC:Cannot allocate memory
strerror
The function prototype :void strerror(int errno)
Function description : Convert the error code to a string error message , This string and other information can be combined and output to the user interface , Such as printf(“errno :%d, %s”, errno, strerror(errno)) The output value is errno:12,Cannot allocate memory
matters needing attention
1, If the system call or library function is executed correctly ,errno The value of is not cleared , If you execute a function A There was a mistake errno Be changed , Next, execute the function directly B, If the function B If executed correctly ,errno Also keep functions A The value set when an error occurs .
2, The system call or library function is executed correctly , There is no guarantee that errno The value of will not be changed
3, All error numbers are non - 0 Of
Sum up : When needed errno To determine whether the function is executed correctly , take errno Set up 0, At the end of function execution , Determine whether the function is executed correctly , When an execution error occurs , Follow up errno To determine exactly what went wrong .
边栏推荐
猜你喜欢

搭建极简GB28181 网守和网关服务器,建立AI推理和3d服务场景,然后开源代码(一)

Gif动图如何裁剪?收下这个图片在线裁剪工具

Gif动画怎么在线制作?快试试这款gif在线制作工具

How to crop GIF dynamic graph? Take this picture online clipping tool

如何裁剪动图大小?试试这个在线照片裁剪工具

About the problem of kicad stuck in win10 version, version 6 x

Kubernetes understands kubectl/ debugging

New good friend Pinia, leading the new era of state management

Power automatic test system nsat-8000, accurate, high-speed and reliable power test equipment

Character encoding minutes
随机推荐
Arithmetic operations and expressions
About the problem of kicad stuck in win10 version, version 6 x
Modal and modeless dialogs for QT
买卖股票的最佳时机
Vs2019 scanf error
[Ocean University of China] information sharing for the first and second examinations of postgraduate entrance examination
One question per day, punch in
QQ情话糖果情话内容获取并保存
Source code analysis of zeromq lockless queue
Common operations in VIM
JS to add elements to the header, or tail of an array
Function of getinstance() method
Go语言Zap库Logger的定制化和封装使用详解
【Try to Hack】vulhub靶场搭建
Usage of qlist
Brain tree (I)
1090.Phone List
Biscuit distribution
System Verilog — interface
QT file reading -qfile