tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkgsrc RC scripts

    Date:        Mon, 19 Oct 2009 23:07:07 +1300 (NZDT)
    From:        Steven Drake <>
    Message-ID:  <>

  | The all code regarding buf is taken from the fgetln(3) manpage! 

Not quite - the version I have (and the URL you gave) says ...

             char *buf, *lbuf;
             size_t len;

             lbuf = NULL;
             while ((buf = fgetln(fp, &len))) {

That "lbuf" is your "buf" (it is the thing that comes from malloc() and
is later tested and freed).   The equivalent of "lbuf = NULL;" was missing
from your patch.

  | strchr(3) requires that the string end with \0,

Sure (so does setenv())

  | and in the odd case were the last line of the file dosn't have
  | an ending newline (it can happen)

yes, it can happen - that's where my suggestion was just to ignore
such a line

        if (line[--len] != '\n')
        line[len] = '\0';

        value = strchr(line, '=');


Who cares about the last line of a file that doesn't end in \n?
This would hardly be the only application to treat that as bogus
(no objection to some kind of error if it happens, rather than just
ignoring it).


Home | Main Index | Thread Index | Old Index