From f616523e5cdc65726d36dad404ed2f66a2fc8fd8 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Wed, 26 Jul 2006 12:53:48 +0000 Subject: Check return values of write() and ftruncate() --- common/textfile.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'common/textfile.c') 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); -- cgit