On Sat, Jan 30, 2021 at 12:22:04AM +0100, Christian Weisgerber wrote:
> Hiltjo Posthuma:
> 
> > > @@ -75,19 +74,8 @@ cookie_load(void)
> > >   if (fp == NULL)
> > >           err(1, "cannot open cookie file %s", cookiefile);
> > >   date = time(NULL);
> > > - lbuf = NULL;
> > > - while ((line = fgetln(fp, &len)) != NULL) {
> > > -         if (line[len - 1] == '\n') {
> > > -                 line[len - 1] = '\0';
> > > -                 --len;
> > > -         } else {
> > > -                 if ((lbuf = malloc(len + 1)) == NULL)
> > > -                         err(1, NULL);
> > > -                 memcpy(lbuf, line, len);
> > > -                 lbuf[len] = '\0';
> > > -                 line = lbuf;
> > > -         }
> > > -         line[strcspn(line, "\r")] = '\0';
> > > + while (getline(&line, &linesize, fp) != -1) {
> > > +         line[strcspn(line, "\r\n")] = '\0';
> > >  
> > 
> > getline returns the number of characters read including the delimeter. This
> > size could be used to '\0' terminate the string instead of a strcspn() call.
> 
> A strcspn() call is already there.
> 
> -- 
> Christian "naddy" Weisgerber                          [email protected]

Yes, my point is it scans the entire line again for delimeter, but it is not
needed, because it is already known after getline() and returned.

-- 
Kind regards,
Hiltjo

Reply via email to