C - 如何允许 Argp 或 Getopt 中无法识别的选项?

标签 c arguments getopt argp

我正在编写使用一些参数的 FUSE 文件系统。我想将所有无法识别的选项传递给 FUSE(因为它有自己的选项)。我可以使用 argp 或 getopt 来做到这一点吗?目前,两者都给我“未知选项”错误。

最佳答案

Argp

来自the "Argp Flags" section of the documentation :

ARGP_NO_ERRS

Don't print error messages for unknown options to stderr; unless this flag is set, ARGP_PARSE_ARGV0 is ignored, as argv[0] is used as the program name in the error messages. This flag implies ARGP_NO_EXIT. This is based on the assumption that silent exiting upon errors is bad behavior.

Getopt

对于getopt(以及getopt_longgetopt_long_only),您只需将全局变量opterr设置为0 在调用该函数之前。或者,您可以使用带有前导 : 字符的短选项字符串(如 ":o:v" 中所示)来处理 -o 输出文件-v (如果 -o 缺少参数,则返回 :;如果有任何选项缺少参数,则返回 ?发现您的选项字符串中不存在)。

关于C - 如何允许 Argp 或 Getopt 中无法识别的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50125760/

相关文章:

c - Wayland API 中 serial 参数的用途是什么?

c - 如何检查给定参数是否是另一个给定参数的子字符串

ruby-on-rails-4 - 当我尝试编写 Rails finder 方法时获取 "wrong number of bind variables"

C getopt -<整数>

c - 模拟 ls 命令的 Linux C 程序

c++ - 为什么c++中数组的内容有时没有初始化?

c++ - 作为成员函数的operator[] 的正确模板参数/参数是什么?

PHP 命令行 : getopt always returns false

c - 字符串C上的getopt()

c - 二维数组行/列长度 C