Skip to content
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

rc_config.3 (manual page) has erroneous description for rc_yesno() #706

Open
gkloepfer opened this issue May 19, 2024 · 0 comments
Open
Assignees

Comments

@gkloepfer
Copy link

The current description for rc_yesno() in rc_config.3 manual page has an ambiguous or somewhat nonsense description. As currently described, rc_yesno will not return if value is not true, and will set EINVAL if "value" is not a false description. It also indicates it recognizes "on" as a possible value, and it does not.

This is not how rc_yesno() actually works.

The description should be changed as follows:

**** returns true if value is true, yes, y, or 1 (regardless of case), otherwise returns false. If value is not a valid representation of true or the values false, no, n, or 0 (regardless of case), then rc_yesno() returns false and errno is set to EINVAL.

Here is the output of test cases for rc_yesno() that should exemplify what the manual page should describe:

$ ./docbug
Test case [yes] ==> returns [true] / errno 0
Test case [YES] ==> returns [true] / errno 0
Test case [Yes] ==> returns [true] / errno 0
Test case [Y] ==> returns [true] / errno 0
Test case [Yup] ==> returns [false] / errno 22
Test case [1] ==> returns [true] / errno 0
Test case [true] ==> returns [true] / errno 0
Test case [TRUE] ==> returns [true] / errno 0
Test case [True] ==> returns [true] / errno 0
Test case [One] ==> returns [false] / errno 22
Test case [on] ==> returns [false] / errno 22
Test case [On] ==> returns [false] / errno 22
Test case [oN] ==> returns [false] / errno 22
Test case [no] ==> returns [false] / errno 0
Test case [NO] ==> returns [false] / errno 0
Test case [No] ==> returns [false] / errno 0
Test case [N] ==> returns [false] / errno 0
Test case [Nope] ==> returns [false] / errno 22
Test case [0] ==> returns [false] / errno 0
Test case [false] ==> returns [false] / errno 0
Test case [FALSE] ==> returns [false] / errno 0
Test case [False] ==> returns [false] / errno 0
Test case [off] ==> returns [false] / errno 22
Test case [This] ==> returns [false] / errno 22
Test case [Is] ==> returns [false] / errno 22
Test case [just] ==> returns [false] / errno 22
Test case [some] ==> returns [false] / errno 22
Test case [random] ==> returns [false] / errno 22
Test case [Junk] ==> returns [false] / errno 22

If it is desired to recognize on/off as values, then this is a bug in rc_yesno().

The following is the program that generates the output above:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

#include <rc.h>

int main(int argc, char *argv[])
{
        char *test_cases[] = {
                "yes", "YES", "Yes", "Y", "Yup", "1", "true", "TRUE", "True",
                "One", "on", "On", "oN",

                "no", "NO", "No", "N", "Nope", "0", "false", "FALSE", "False",
                "off",

                "This", "Is", "just", "some", "random", "Junk",
                NULL
        };

        int i;
        bool ret;

        for (i = 0; test_cases[i] != NULL; i++) {
                errno = 0;
                ret = rc_yesno(test_cases[i]);
                printf("Test case [%s] ==> returns [%s] / errno %d\n",
                        test_cases[i], (ret ? "true" : "false"), errno);
        }

        exit(0);
}
@navi-desu navi-desu self-assigned this Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants