diff options
author | Ken Raeburn <raeburn@mit.edu> | 2008-06-20 23:31:37 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2008-06-20 23:31:37 +0000 |
commit | e35fdd707e0b0c6acd9b29d715fb829653144533 (patch) | |
tree | 64b2d242773c032e597f5e3e36fabee072412032 | |
parent | 8d5bc3c15b103132350cf037ab8289369626ad7c (diff) | |
download | krb5-e35fdd707e0b0c6acd9b29d715fb829653144533.zip krb5-e35fdd707e0b0c6acd9b29d715fb829653144533.tar.gz krb5-e35fdd707e0b0c6acd9b29d715fb829653144533.tar.bz2 |
When extending the update log file, fill in some content instead of making it sparse
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/sun-iprop@20450 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r-- | src/lib/kdb/kdb_log.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/lib/kdb/kdb_log.c b/src/lib/kdb/kdb_log.c index 662703f..c2aebd8 100644 --- a/src/lib/kdb/kdb_log.c +++ b/src/lib/kdb/kdb_log.c @@ -855,9 +855,30 @@ ulog_set_role(krb5_context ctx, iprop_role role) */ static int extend_file_to(int fd, uint_t new_size) { - if (lseek(fd, new_size, SEEK_SET) == -1) + int current_offset; + static const char zero[512] = { 0, }; + + current_offset = lseek(fd, 0, SEEK_END); + if (current_offset < 0) return -1; - if (write(fd, "+", 1) != 1) + if (new_size > INT_MAX) { + errno = EINVAL; return -1; + } + while (current_offset < new_size) { + int write_size, wrote_size; + write_size = new_size - current_offset; + if (write_size > 512) + write_size = 512; + wrote_size = write(fd, zero, write_size); + if (wrote_size < 0) + return -1; + if (wrote_size == 0) { + errno = EINVAL; /* XXX ?? */ + return -1; + } + current_offset += wrote_size; + write_size = new_size - current_offset; + } return 0; } |