zoukankan      html  css  js  c++  java
  • 2010912 双模机顶盒学习记录

    双模机顶盒 直播走igmp/rtsp组播协议 单播走hls(OTT)协议。

    系统调用

    getopt

      位于 unistd.h 系统头文件,原型:

      int getopt( int argc, char *const argv[], const char *optstring );

    #include <unistd.h>
           extern char *optarg;  //选项的参数指针
           extern int optind,   //下一次调用getopt的时,从optind存储的位置处重新开始检查选项。 
           extern int opterr,  //当opterr=0时,getopt不向stderr输出错误信息。
           extern int optopt;  //当命令行选项字符不包括在optstring中或者选项缺少必要的参数时,该选项存储在optopt中,getopt返回'?’、
           int getopt(int argc, char * const argv[], const char *optstring);

      optstring是一段自己规定的选项串,例如本例中的"a:b::cde",表示可以有,-a,-b,-c,-d,-e这几个参数。

      “:”表示必须该选项带有额外的参数,全域变量optarg会指向此额外参数,“::”标识该额外的参数可选(有些Uinx可能不支持“::”)。

      getopt() 所设置的全局变量包括:

    • optarg——字符串, 指向当前选项参数(如果有)的指针。   选项的参数指针
    • optind——整型, 再次调用 getopt() 时的下一个 argv 指针的索引。下一次调用getopt的时,从optind存储的位置处重新开始检查选项。在argv[optind]至argv[argc-1]中可以找到。
        • argv的当前索引值。当getopt()在while循环中使用时,循环结束后,剩下的字串视为操作数,在argv[optind]至argv[argc-1]中可以找到。
    • optopt——整型, 最后一个已知选项。当命令行选项字符不包括在optstring中或者选项缺少必要的参数时,该选项存储在optopt中,getopt返回'?’、当发现无效选项字符之时,getopt()函数或返回'?'字 符,或返回':'字符,并且optopt包含了所发现的无效选项字符。
    • opterr        整型, 当opterr=0时,getopt不向stderr输出错误信息。 这个变量非零时,getopt()函数为“无效选项”和“缺少参数选项,并输出其错误信息。

      

      https://www.ibm.com/developerworks/cn/aix/library/au-unix-getopt.html

           http://blog.csdn.net/baixue6269/article/details/7550184

      http://vopit.blog.51cto.com/2400931/440453

      http://www.cnblogs.com/qingergege/p/5914218.html

  • 相关阅读:
    CodeForces 734F Anton and School
    CodeForces 733F Drivers Dissatisfaction
    CodeForces 733C Epidemic in Monstropolis
    ZOJ 3498 Javabeans
    ZOJ 3497 Mistwald
    ZOJ 3495 Lego Bricks
    CodeForces 732F Tourist Reform
    CodeForces 732E Sockets
    CodeForces 731E Funny Game
    CodeForces 731D 80-th Level Archeology
  • 原文地址:https://www.cnblogs.com/doscho/p/7515189.html
Copyright © 2011-2022 走看看