当前位置:网站首页>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 .
边栏推荐
- Master XSS completely from 0 to 1
- Using Sphinx to automatically generate API documents from py source files
- Usage of qlist
- JS Base64 Library Learning
- Dmsetup command
- Qt: Pro project file
- 移除区间(贪心)
- Source code analysis of synergetics and ntyco
- Dynamic memory allocation
- Is it normal to dig for money? Is it safe to open a stock account?
猜你喜欢
【中國海洋大學】考研初試複試資料分享
Kubernetes understands kubectl/ debugging
【Try to Hack】vulnhub DC1
Introduction to flexible array
Source code analysis of synergetics and ntyco
Dynamic memory allocation
Use Matplotlib to draw a line chart
How to combine multiple motion graphs into a GIF? Generate GIF animation pictures in three steps
定位position(5种方式)
开餐馆
随机推荐
Jaspersoft studio installation
QT loading third-party library basic operation
Mutationobserver listens for DOM changes
Async await to achieve sleep waiting effect
Master XSS completely from 0 to 1
Heavyweight! The domestic IDE is released and developed by Alibaba. It is completely open source! (high performance + high customization)
Yolov3 spp Darknet version to caffemodel and then to OM model
One question per day,
Extend JS copy content to clipboard
【Try to Hack】vulnhub DC1
[try to hack] vulhub shooting range construction
Dynamic memory allocation
[untitled] PTA check password
Is it normal to dig for money? Is it safe to open a stock account?
Design and implementation of timer
‘make_ unique’ is not a member of ‘std’
买卖股票的最佳时机
What is the difference between escape, encodeuri and encodeuricomponent?
Qlogsystem log system configuration use
How to crop GIF dynamic graph? Take this picture online clipping tool