-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib/getdef.c: Introduce getlong_normalized #884
Conversation
Stay compatible with current configuration files which allow all negative values, but convert them to -1 on the fly. Print a warning so these values can be modified by an administrator for a future release which won't have this support anymore. Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
"normalizing" is not something intrinsic to |
A getlong() variant that handles a range (similar to strtoi(3bsd)) is something I have in mind. Here's what I have in mind: inline int
getlong(const char *s, long *restrict num, char **endptr, int base, long min, long max)
{
int status;
*num = strtoi(s, endptr, base, min, max, &status);
if (status != 0) {
errno = status;
return -1;
}
return 0;
}
inline int
getl(const char *restrict s, long *restrict num)
{
return getlong(s, num, NULL, 0, LONG_MIN, LONG_MAX);
} The current getlong() would be (almost) my getl() suggestion, and getlong() would be the argumentful version. You could call |
This is a variant of get[u]l() that accepts a few more parameters. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
…terms of get[u]long() This is a variant of get[u]l() that accepts a few more parameters. get[u]l() is rewritten to be implemented in terms of get[u]long(). There are a few side effects of this in the behavior of get[u]l(): - get[u]l() now sets errno in a similar way to how strtoi(3bsd) sets &status. This replaces the old behavior, which was strtol(3)-like. The strtoi(3bsd) errors are much easier to differentiate. - get[u]l() now sets the number, even if the call failed. The old behavior was to leave it uninitialized. Link: <shadow-maint#884> Cc: Tobias Stoeckmann <tobias@stoeckmann.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Stay compatible with current configuration files which allow all negative values, but convert them to -1 on the fly.
Print a warning so these values can be modified by an administrator for a future release which won't have this support anymore.
As discussed in #877 (comment)