summaryrefslogtreecommitdiff
path: root/navit/file.c
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-11-06 15:47:56 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2012-11-06 15:47:56 +0000
commit142bf0d675d1bfba7ace95a23afc5bdd1e8cbf2b (patch)
tree6b14b57f5292750eb280c7c1071c8fd6ea5b1804 /navit/file.c
parent984fffc1acca84bd3569ca60c4d46cf74ce9398d (diff)
downloadnavit-142bf0d675d1bfba7ace95a23afc5bdd1e8cbf2b.tar.gz
Fix:Core:Add file_sync function, truncate files if create flag is set, avoid crashing file_get_content on seek errors
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@5260 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/file.c')
-rw-r--r--navit/file.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/navit/file.c b/navit/file.c
index 87a2adf8e..04b975df8 100644
--- a/navit/file.c
+++ b/navit/file.c
@@ -232,7 +232,7 @@ file_create(char *name, struct attr **options)
if (options && (attr=attr_search(options, NULL, attr_readwrite)) && attr->u.num) {
open_flags |= O_RDWR;
if ((attr=attr_search(options, NULL, attr_create)) && attr->u.num)
- open_flags |= O_CREAT;
+ open_flags |= O_CREAT|O_TRUNC;
} else
open_flags |= O_RDONLY;
file->name = g_strdup(name);
@@ -243,6 +243,8 @@ file_create(char *name, struct attr **options)
}
dbg(1,"fd=%d\n", file->fd);
file->size=lseek(file->fd, 0, SEEK_END);
+ if (file->size < 0)
+ file->size=0;
dbg(1,"size="LONGLONG_FMT"\n", file->size);
file->name_id = (long)atom(name);
}
@@ -805,6 +807,14 @@ file_create_caseinsensitive(char *name, struct attr **options)
}
void
+file_fsync(struct file *f)
+{
+#ifdef HAVE_FSYNC
+ fsync(f->fd);
+#endif
+}
+
+void
file_destroy(struct file *f)
{
if (f->headers)