← Back to context

Comment by lelanthran

3 days ago

> Additionally, the .env file parser is quite clean.

I didn't find it clean; it's so over-engineered that you won't easily be able to spot bugs in it.

What you want is (assuming you have a string-trimming function):

    while ((fgets (name, sizeof name, inputf)) {
        if (!(value = strchr (name, '='))) { continue; }
        *value++ = 0;
        strtrim(name);
        strtrim(value);
        if (!*name) { continue; }
        // Now store `name` and `value`
    }

> I guess a "good first issue" for anyone interested in contributing would be extending the `skipWhitespace` function to detect `#` tokens and skip the rest of the line when present.

Or do it before processing:

    // First statement of while loop
    char *comment = strchr (name, '#');
    if (comment) *comment = 0;
    // Continue with processing `name`

The way it's done in the linked code raises a ton of red flags.