|
Lines 588-604
Link Here
|
| 588 |
return prv; |
588 |
return prv; |
| 589 |
} |
589 |
} |
| 590 |
|
590 |
|
|
|
591 |
char * |
| 592 |
read_whole_line(char **line, size_t *size, FILE *f) |
| 593 |
{ |
| 594 |
char *ln = *line; |
| 595 |
size_t i, sz = *size; |
| 596 |
|
| 597 |
if (!ln) { |
| 598 |
fatal("read_whole_line: NULL pointer given as line argument"); |
| 599 |
} |
| 600 |
|
| 601 |
for (i = 0; ln[sz - 2] = '\0', fgets(ln + i, sz - i, f); i = sz - 1, sz <<= 1) { |
| 602 |
if (ln[sz - 2]) { |
| 603 |
ln = xrealloc(ln, sz << 1); |
| 604 |
continue; |
| 605 |
} |
| 606 |
|
| 607 |
*line = ln; |
| 608 |
*size = sz; |
| 609 |
|
| 610 |
return ln; |
| 611 |
} |
| 612 |
|
| 613 |
return NULL; |
| 614 |
} |
| 615 |
|
| 591 |
static int |
616 |
static int |
| 592 |
key_try_load_public(Key *k, const char *filename, char **commentp) |
617 |
key_try_load_public(Key *k, const char *filename, char **commentp) |
| 593 |
{ |
618 |
{ |
| 594 |
FILE *f; |
619 |
FILE *f; |
| 595 |
char line[4096]; |
620 |
size_t size; |
|
|
621 |
char *line; |
| 596 |
char *cp; |
622 |
char *cp; |
| 597 |
|
623 |
|
| 598 |
f = fopen(filename, "r"); |
624 |
f = fopen(filename, "r"); |
| 599 |
if (f != NULL) { |
625 |
if (f != NULL) { |
| 600 |
while (fgets(line, sizeof(line), f)) { |
626 |
size = 4096; |
| 601 |
line[sizeof(line)-1] = '\0'; |
627 |
line = xmalloc(size); |
|
|
628 |
|
| 629 |
while (read_whole_line(&line, &size, f)) { |
| 630 |
/* FIXME: is this useful? fgets already stores a '\0' |
| 631 |
* after the last character in the buffer... |
| 632 |
*/ |
| 633 |
line[size-1] = '\0'; |
| 634 |
|
| 602 |
cp = line; |
635 |
cp = line; |
| 603 |
switch (*cp) { |
636 |
switch (*cp) { |
| 604 |
case '#': |
637 |
case '#': |
|
Lines 613-623
Link Here
|
| 613 |
if (key_read(k, &cp) == 1) { |
646 |
if (key_read(k, &cp) == 1) { |
| 614 |
if (commentp) |
647 |
if (commentp) |
| 615 |
*commentp=xstrdup(filename); |
648 |
*commentp=xstrdup(filename); |
|
|
649 |
|
| 650 |
xfree(line); |
| 616 |
fclose(f); |
651 |
fclose(f); |
| 617 |
return 1; |
652 |
return 1; |
| 618 |
} |
653 |
} |
| 619 |
} |
654 |
} |
| 620 |
} |
655 |
} |
|
|
656 |
|
| 657 |
xfree(line); |
| 621 |
fclose(f); |
658 |
fclose(f); |
| 622 |
} |
659 |
} |
| 623 |
return 0; |
660 |
return 0; |