MFC: sbin/geom/misc/subr.c 1.7
sbin/geom/misc/subr.h 1.8 Implement gctl_change_param() function, which changes value of existing parameter.
This commit is contained in:
parent
86ab5edcc3
commit
1ebd1ed20e
@ -388,3 +388,29 @@ gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...)
|
||||
va_end(ap);
|
||||
return (p);
|
||||
}
|
||||
|
||||
int
|
||||
gctl_change_param(struct gctl_req *req, const char *name, int len,
|
||||
const void *value)
|
||||
{
|
||||
struct gctl_req_arg *ap;
|
||||
unsigned i;
|
||||
|
||||
if (req == NULL || req->error != NULL)
|
||||
return (EDOOFUS);
|
||||
for (i = 0; i < req->narg; i++) {
|
||||
ap = &req->arg[i];
|
||||
if (strcmp(ap->name, name) != 0)
|
||||
continue;
|
||||
ap->value = __DECONST(void *, value);
|
||||
if (len >= 0) {
|
||||
ap->flag &= ~GCTL_PARAM_ASCII;
|
||||
ap->len = len;
|
||||
} else if (len < 0) {
|
||||
ap->flag |= GCTL_PARAM_ASCII;
|
||||
ap->len = strlen(value) + 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
return (ENOENT);
|
||||
}
|
||||
|
@ -45,4 +45,6 @@ void gctl_error(struct gctl_req *req, const char *error, ...);
|
||||
int gctl_get_int(struct gctl_req *req, const char *pfmt, ...);
|
||||
intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...);
|
||||
const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...);
|
||||
int gctl_change_param(struct gctl_req *req, const char *name, int len,
|
||||
const void *value);
|
||||
#endif /* !_SUBR_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user