diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2005-09-07 17:31:56 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2005-09-07 17:31:56 +0000 |
commit | 50195243cfcac56a039480c3506acd0f5c5f80e0 (patch) | |
tree | 7fdfea8fe7c9d4cd7d31be8c33fe59bb250c570c /common | |
parent | a8b5fad54044c7b5e7c6aa30ad24e5a86fc51daf (diff) |
Let textfile_put() also replace the last key value pair
Diffstat (limited to 'common')
-rw-r--r-- | common/textfile.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/common/textfile.c b/common/textfile.c index 26cbbea7..095e0355 100644 --- a/common/textfile.c +++ b/common/textfile.c @@ -180,8 +180,15 @@ int textfile_put(char *pathname, char *key, char *value) end += len; len = size - (end - map); + if (!len) { + munmap(map, size); + ftruncate(fd, base); + pos = lseek(fd, base, SEEK_SET); + err = write_key_value(fd, key, value); + goto unlock; + } - if (len <= 0 || len > size) { + if (len < 0 || len > size) { err = EILSEQ; goto unmap; } @@ -193,12 +200,12 @@ int textfile_put(char *pathname, char *key, char *value) } memcpy(str, end, len); - munmap(map, size); + munmap(map, size); ftruncate(fd, base); pos = lseek(fd, base, SEEK_SET); + err = write_key_value(fd, key, value); - write_key_value(fd, key, value); write(fd, str, len); free(str); |