From 8a580fa45d7352a865fc4e4832657123982a2df9 Mon Sep 17 00:00:00 2001 From: martin-s Date: Fri, 13 Feb 2009 09:21:30 +0000 Subject: [PATCH] Fix:Core:Replaced g_file_get_contents with navit version git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2045 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/file.c | 28 ++++++++++++++++++++++++++-- navit/navit/file.h | 3 +++ navit/navit/osm2navit.c | 8 +++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/navit/navit/file.c b/navit/navit/file.c index 1c5d77f..3523554 100644 --- a/navit/navit/file.c +++ b/navit/navit/file.c @@ -62,8 +62,6 @@ file_create(char *name) struct stat stat; struct file *file= g_new0(struct file,1); - if (! file) - return file; file->fd=open(name, O_RDONLY|O_LARGEFILE | O_BINARY); if (file->fd == -1) { g_free(file); @@ -88,6 +86,12 @@ int file_is_dir(char *name) } +int +file_size(struct file *file) +{ + return file->size; +} + int file_mkdir(char *name, int pflag) { char buffer[strlen(name)+1]; @@ -161,6 +165,26 @@ file_data_read(struct file *file, long long offset, int size) } +unsigned char * +file_data_read_all(struct file *file) +{ + return file_data_read(file, 0, file->size); +} + +int +file_get_contents(char *name, unsigned char **buffer, int *size) +{ + struct file *file; + file=file_create(name); + if (!file) + return 0; + *size=file_size(file); + *buffer=file_data_read_all(file); + file_destroy(file); + return 1; +} + + static int uncompress_int(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) { diff --git a/navit/navit/file.h b/navit/navit/file.h index 79f211d..f5dae8e 100644 --- a/navit/navit/file.h +++ b/navit/navit/file.h @@ -53,9 +53,12 @@ struct file_wordexp; struct param_list; struct file *file_create(char *name); int file_is_dir(char *name); +int file_size(struct file *file); int file_mkdir(char *name, int pflag); int file_mmap(struct file *file); unsigned char *file_data_read(struct file *file, long long offset, int size); +unsigned char *file_data_read_all(struct file *file); +int file_get_contents(char *name, unsigned char **buffer, int *size); unsigned char *file_data_read_compressed(struct file *file, long long offset, int size, int size_uncomp); void file_data_free(struct file *file, unsigned char *data); int file_exists(char *name); diff --git a/navit/navit/osm2navit.c b/navit/navit/osm2navit.c index fac19c3..4407f96 100644 --- a/navit/navit/osm2navit.c +++ b/navit/navit/osm2navit.c @@ -33,6 +33,7 @@ #include #include #include +#include "file.h" #include "item.h" #include "map.h" #include "zipfile.h" @@ -382,7 +383,7 @@ struct country_table { int countryid; char *names; FILE *file; - unsigned int size; + int size; struct rect r; } country_table[] = { { 40,"Austria,�sterreich,AUT"}, @@ -1334,7 +1335,8 @@ sort_countries(void) struct coord *c; struct item_bin *ib; FILE *f; - char *p,*buffer,**idx,*name; + char *name; + unsigned char *p,**idx,*buffer; for (i = 0 ; i < sizeof(country_table)/sizeof(struct country_table) ; i++) { co=&country_table[i]; if (co->file) { @@ -1342,7 +1344,7 @@ sort_countries(void) co->file=NULL; } name=g_strdup_printf("country_%d.bin.unsorted", co->countryid); - if (g_file_get_contents(name, &buffer, &co->size, NULL)) { + if (file_get_contents(name, &buffer, &co->size)) { unlink(name); g_free(name); ib=(struct item_bin *)buffer; -- 2.7.4