我正在编写使用一些参数的 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, asargv[0]
is used as the program name in the error messages. This flag impliesARGP_NO_EXIT
. This is based on the assumption that silent exiting upon errors is bad behavior.
Getopt
对于getopt
(以及getopt_long
和getopt_long_only
),您只需将全局变量opterr
设置为0 在调用该函数之前。或者,您可以使用带有前导 :
字符的短选项字符串(如 ":o:v"
中所示)来处理 -o 输出文件
和 -v
(如果 -o
缺少参数,则返回 :
;如果有任何选项缺少参数,则返回 ?
发现您的选项字符串中不存在)。
关于C - 如何允许 Argp 或 Getopt 中无法识别的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50125760/