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

Contents of /navit/navit/maptool/tempfile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (show annotations) (download)
Fri Oct 28 21:39:42 2011 UTC (12 years, 5 months ago) by zoff99
File MIME type: text/plain
File size: 1587 byte(s)
import
1 /**
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 <unistd.h>
20 #include "maptool.h"
21 #include "debug.h"
22
23 char *
24 tempfile_name(char *suffix, char *name)
25 {
26 return g_strdup_printf("%s_%s.tmp",name, suffix);
27 }
28 FILE *
29 tempfile(char *suffix, char *name, int mode)
30 {
31 char *buffer=tempfile_name(suffix, name);
32 FILE *ret=NULL;
33 switch (mode) {
34 case 0:
35 ret=fopen(buffer, "rb");
36 break;
37 case 1:
38 ret=fopen(buffer, "wb+");
39 break;
40 case 2:
41 ret=fopen(buffer, "ab");
42 break;
43 }
44 g_free(buffer);
45 return ret;
46 }
47
48 void
49 tempfile_unlink(char *suffix, char *name)
50 {
51 char buffer[4096];
52 sprintf(buffer,"%s_%s.tmp",name, suffix);
53 unlink(buffer);
54 }
55
56 void
57 tempfile_rename(char *suffix, char *from, char *to)
58 {
59 char buffer_from[4096],buffer_to[4096];
60 sprintf(buffer_from,"%s_%s.tmp",from,suffix);
61 sprintf(buffer_to,"%s_%s.tmp",to,suffix);
62 dbg_assert(rename(buffer_from, buffer_to) == 0);
63
64 }

   
Visit the ZANavi Wiki