1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-14 14:55:41 +00:00

If the buffer supplied to kenv(KENV_DUMP, ...) isn't big enough,

return the number of bytes needed instead of 0.  The manpage claims
that we do this anyway.
This commit is contained in:
David Schultz 2004-04-28 01:27:33 +00:00
parent 4bb464ddb9
commit 06afcd9d10
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=128697

View File

@ -87,7 +87,7 @@ kenv(td, uap)
} */ *uap;
{
char *name, *value;
size_t len, done;
size_t len, done, needed;
int error, i;
KASSERT(dynamic_kenv, ("kenv: dynamic_kenv = 0"));
@ -99,30 +99,27 @@ kenv(td, uap)
if (error)
return (error);
#endif
len = 0;
/* Return the size if called with a NULL buffer */
if (uap->value == NULL) {
sx_slock(&kenv_lock);
for (i = 0; kenvp[i] != NULL; i++)
len += strlen(kenvp[i]) + 1;
sx_sunlock(&kenv_lock);
td->td_retval[0] = len;
return (0);
}
done = 0;
done = needed = 0;
sx_slock(&kenv_lock);
for (i = 0; kenvp[i] != NULL && done < uap->len; i++) {
len = min(strlen(kenvp[i]) + 1, uap->len - done);
error = copyout(kenvp[i], uap->value + done,
len);
if (error) {
sx_sunlock(&kenv_lock);
return (error);
for (i = 0; kenvp[i] != NULL; i++) {
len = strlen(kenvp[i]) + 1;
needed += len;
len = min(len, uap->len - done);
/*
* If called with a NULL or insufficiently large
* buffer, just keep computing the required size.
*/
if (uap->value != NULL && len > 0) {
error = copyout(kenvp[i], uap->value + done,
len);
if (error)
break;
done += len;
}
done += len;
}
sx_sunlock(&kenv_lock);
return (0);
td->td_retval[0] = ((done == needed) ? 0 : needed);
return (error);
}
if ((uap->what == KENV_SET) ||