diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-07-26 12:53:48 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2006-07-26 12:53:48 +0000 |
commit | f616523e5cdc65726d36dad404ed2f66a2fc8fd8 (patch) | |
tree | 82c56b5d01f2733b8bf139e3a92c33537a54ce26 /common/textfile.c | |
parent | 7131510a19ff72583ff5ba7079fdb88d1346b587 (diff) |
Check return values of write() and ftruncate()
Diffstat (limited to 'common/textfile.c')
-rw-r--r-- | common/textfile.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/common/textfile.c b/common/textfile.c index 7814513a..cdb42d13 100644 --- a/common/textfile.c +++ b/common/textfile.c @@ -182,10 +182,14 @@ static int write_key(const char *pathname, const char *key, const char *value) len = size - (end - map); if (!len) { munmap(map, size); - ftruncate(fd, base); + if (ftruncate(fd, base) < 0) { + err = errno; + goto unlock; + } pos = lseek(fd, base, SEEK_SET); if (value) err = write_key_value(fd, key, value); + goto unlock; } @@ -203,12 +207,16 @@ static int write_key(const char *pathname, const char *key, const char *value) memcpy(str, end, len); munmap(map, size); - ftruncate(fd, base); + if (ftruncate(fd, base) < 0) { + err = errno; + goto unlock; + } pos = lseek(fd, base, SEEK_SET); if (value) err = write_key_value(fd, key, value); - write(fd, str, len); + if (write(fd, str, len) < 0) + err = errno; free(str); |