diff options
author | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2012-11-06 15:47:56 +0000 |
---|---|---|
committer | martin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2012-11-06 15:47:56 +0000 |
commit | 142bf0d675d1bfba7ace95a23afc5bdd1e8cbf2b (patch) | |
tree | 6b14b57f5292750eb280c7c1071c8fd6ea5b1804 /navit/file.c | |
parent | 984fffc1acca84bd3569ca60c4d46cf74ce9398d (diff) | |
download | navit-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.c | 12 |
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) |