zoukankan      html  css  js  c++  java
  • linxu中系统错误码errno

    Unix errno值、

    •   只要一个Unix函数(如,某个套接字函数)中有错误发生,全局变量errno就被设置为一个指明该错误类型的正直,函数本身则通过返回-1.
    •   errno的值只在函数发生错误时被设置,如果函数不返回错误,errno的值就没有定义。
    •   errno的所有证书错误值都是常值,具有以“E”开头的全大写字母名字,并通常在<sys/errno.h>头文件中定义,0值不表示任何错误;
    •   sys_errlist
    #include <iostream>
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <errno.h>
    #include <string.h> int main(int argc, char **argv) { int sockfd = 0; if ((sockfd = socket(0, SOCK_STREAM, 0)) < 0) { if (errno >= 0 && errno <= sys_nerr) printf("socket created, failed[%d], reason:%s ", errno, sys_errlist[errno]);
         printf("%s ",strerror(errno)); //头文件string.h内 }
    else { printf("socket successful "); } return 0; }

    输出结果:

    socket created, failed[97], reason:Address family not supported by protocol
    Address family not supported by protocol
  • 相关阅读:
    第五章.函数
    第四章.文件操作
    第三章.数据类型
    PyYaml简单学习
    Vim编辑器基本用法
    numpy.ndarray.transpose用法理解
    Django Formsets总结
    学习,认知,思维
    Django model总结(上)
    结合pandas,sqlite3批量将csv数据导入sqlite数据库
  • 原文地址:https://www.cnblogs.com/weiyouqing/p/13055203.html
Copyright © 2011-2022 走看看