summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-01-21 18:01:39 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-01-21 18:01:39 +0000
commit6561447cafc0b9a857094c8aa43c0aeb0aa7adb2 (patch)
tree4638cc75720501413755024f1228072e450d9e8a /common
parentc57d6548a33e4222435162a3c4c09be1189ea36f (diff)
Check if value has changed before writing it
Diffstat (limited to 'common')
-rw-r--r--common/test_textfile.c10
-rw-r--r--common/textfile.c7
2 files changed, 16 insertions, 1 deletions
diff --git a/common/test_textfile.c b/common/test_textfile.c
index 814c806b..1c001f46 100644
--- a/common/test_textfile.c
+++ b/common/test_textfile.c
@@ -62,6 +62,16 @@ int main(int argc, char *argv[])
else
free(str);
+ snprintf(value, sizeof(value), "Test");
+ if (textfile_put(filename, key, value) < 0)
+ fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
+
+ if (textfile_put(filename, key, value) < 0)
+ fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
+
+ if (textfile_put(filename, key, value) < 0)
+ fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
+
if (textfile_del(filename, key) < 0)
fprintf(stderr, "%s (%d)\n", strerror(errno), errno);
diff --git a/common/textfile.c b/common/textfile.c
index 36bde03f..895e3f3d 100644
--- a/common/textfile.c
+++ b/common/textfile.c
@@ -168,7 +168,8 @@ static int write_key(const char *pathname, const char *key, const char *value, i
goto unlock;
}
- off = find_key(map, key, strlen(key), icase);
+ len = strlen(key);
+ off = find_key(map, key, len, icase);
if (!off) {
if (value) {
munmap(map, size);
@@ -186,6 +187,10 @@ static int write_key(const char *pathname, const char *key, const char *value, i
goto unmap;
}
+ if (value && (strlen(value) == end - off - len - 1) &&
+ !strncmp(off + len + 1, value, end - off - len - 1))
+ goto unmap;
+
len = strspn(end, "\r\n");
end += len;