/[zanavi_public1]/navit/navit/maptool/buffer.c
ZANavi

Contents of /navit/navit/maptool/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations) (download)
Fri Oct 28 21:39:42 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 1607 byte(s)
import
1 zoff99 8 /**
2     * Navit, a modular navigation system.
3     * Copyright (C) 2005-2011 Navit Team
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * version 2 as published by the Free Software Foundation.
8     *
9     * This program is distributed in the hope that it will be useful,
10     * but WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     * GNU General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with this program; if not, write to the
16     * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17     * Boston, MA 02110-1301, USA.
18     */
19     #include <stdlib.h>
20     #include "maptool.h"
21     #include "debug.h"
22    
23     void
24     save_buffer(char *filename, struct buffer *b, long long offset)
25     {
26     FILE *f;
27     f=fopen(filename,"rb+");
28     if (! f)
29     f=fopen(filename,"wb+");
30    
31     dbg_assert(f != NULL);
32     fseek(f, offset, SEEK_SET);
33     fwrite(b->base, b->size, 1, f);
34     fclose(f);
35     }
36    
37     void
38     load_buffer(char *filename, struct buffer *b, long long offset, long long size)
39     {
40     FILE *f;
41     long long len;
42     int ret;
43     if (b->base)
44     free(b->base);
45     b->malloced=0;
46     f=fopen(filename,"rb");
47     fseek(f, 0, SEEK_END);
48     len=ftell(f);
49     if (offset+size > len) {
50     size=len-offset;
51     ret=1;
52     }
53     b->size=b->malloced=size;
54     fprintf(stderr,"reading "LONGLONG_FMT" bytes from %s at "LONGLONG_FMT"\n", b->size, filename, offset);
55     fseek(f, offset, SEEK_SET);
56     b->base=malloc(b->size);
57     dbg_assert(b->base != NULL);
58     fread(b->base, b->size, 1, f);
59     fclose(f);
60     }

   
Visit the ZANavi Wiki