|
Lines 520-528
add_host_to_hostfile(const char *filename, const char *host,
Link Here
|
| 520 |
if (key == NULL) |
520 |
if (key == NULL) |
| 521 |
return 1; /* XXX ? */ |
521 |
return 1; /* XXX ? */ |
| 522 |
hostfile_create_user_ssh_dir(filename, 0); |
522 |
hostfile_create_user_ssh_dir(filename, 0); |
| 523 |
f = fopen(filename, "a"); |
523 |
f = fopen(filename, "a+"); |
| 524 |
if (!f) |
524 |
if (!f) |
| 525 |
return 0; |
525 |
return 0; |
|
|
526 |
/* Make sure we have a terminating newline. */ |
| 527 |
if (fseek(f, -1, SEEK_END) == 0 && fgetc(f) != '\n') |
| 528 |
if (fputc('\n', f) != '\n') { |
| 529 |
error("Failed to add terminating newline to %s: %s", |
| 530 |
filename, strerror(errno) ); |
| 531 |
fclose(f); |
| 532 |
return 0; |
| 533 |
} |
| 526 |
success = write_host_entry(f, host, NULL, key, store_hash); |
534 |
success = write_host_entry(f, host, NULL, key, store_hash); |
| 527 |
fclose(f); |
535 |
fclose(f); |
| 528 |
return success; |
536 |
return success; |