Implement gctl_change_param() function, which changes value of existing
parameter. MFC after: 1 week
This commit is contained in:
parent
c4b1628e07
commit
1378624c2e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=166215
@ -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, ...) __printflike(2, 3)
|
||||
int gctl_get_int(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
|
||||
intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
|
||||
const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
|
||||
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