当前位置: 技术问答>linux和unix
高分征求答案---parse_options函数的作用是什么?
来源: 互联网 发布时间:2015-03-01
本文导语: 在proc_read_super(fs/proc/inode.c)中调用此函数,原型为: static int parse_options(char *options,uid_t *uid,gid_t *gid) { char *this_char,*value; *uid = current->uid; *gid = current->gid; if (!options) return 1; for (this_char = strtok(options,","); th...
在proc_read_super(fs/proc/inode.c)中调用此函数,原型为:
static int parse_options(char *options,uid_t *uid,gid_t *gid)
{
char *this_char,*value;
*uid = current->uid;
*gid = current->gid;
if (!options) return 1;
for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
if ((value = strchr(this_char,'=')) != NULL)
*value++ = 0;
if (!strcmp(this_char,"uid")) {
if (!value || !*value)
return 0;
*uid = simple_strtoul(value,&value,0);
if (*value)
return 0;
}
else if (!strcmp(this_char,"gid")) {
if (!value || !*value)
return 0;
*gid = simple_strtoul(value,&value,0);
if (*value)
return 0;
}
else return 1;
}
return 1;
}
大家谁能告诉我这段代码是做什么用的?谢谢
static int parse_options(char *options,uid_t *uid,gid_t *gid)
{
char *this_char,*value;
*uid = current->uid;
*gid = current->gid;
if (!options) return 1;
for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
if ((value = strchr(this_char,'=')) != NULL)
*value++ = 0;
if (!strcmp(this_char,"uid")) {
if (!value || !*value)
return 0;
*uid = simple_strtoul(value,&value,0);
if (*value)
return 0;
}
else if (!strcmp(this_char,"gid")) {
if (!value || !*value)
return 0;
*gid = simple_strtoul(value,&value,0);
if (*value)
return 0;
}
else return 1;
}
return 1;
}
大家谁能告诉我这段代码是做什么用的?谢谢
|
呵呵,无它,就是分析/解析参数/选项用的。
参数保存于options中的
参数保存于options中的