… | |
… | |
14 | * You should have received a copy of the GNU General Public License |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write to the |
15 | * along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
18 | */ |
|
|
19 | #define _FILE_OFFSET_BITS 64 |
|
|
20 | #define _LARGEFILE_SOURCE |
|
|
21 | #define _LARGEFILE64_SOURCE |
19 | #include <unistd.h> |
22 | #include <unistd.h> |
20 | #include "maptool.h" |
23 | #include "maptool.h" |
21 | #include "debug.h" |
24 | #include "debug.h" |
22 | |
25 | |
23 | char * |
26 | char * |
24 | tempfile_name(char *suffix, char *name) |
27 | tempfile_name(char *suffix, char *name) |
25 | { |
28 | { |
26 | return g_strdup_printf("%s_%s.tmp",name, suffix); |
29 | return g_strdup_printf("%s_%s.tmp",name, suffix); |
27 | } |
30 | } |
|
|
31 | |
28 | FILE * |
32 | FILE * |
29 | tempfile(char *suffix, char *name, int mode) |
33 | tempfile(char *suffix, char *name, int mode) |
30 | { |
34 | { |
31 | char *buffer=tempfile_name(suffix, name); |
35 | char *buffer=tempfile_name(suffix, name); |
32 | FILE *ret=NULL; |
36 | FILE *ret=NULL; |
… | |
… | |
39 | break; |
43 | break; |
40 | case 2: |
44 | case 2: |
41 | ret=fopen(buffer, "ab"); |
45 | ret=fopen(buffer, "ab"); |
42 | break; |
46 | break; |
43 | } |
47 | } |
|
|
48 | |
|
|
49 | if (debug_itembin(6)) |
|
|
50 | { |
|
|
51 | fprintf(stderr,"== tempfile == open == FILENAME: %s FILEPOINTER: %p ==\n",buffer,ret); |
|
|
52 | } |
44 | g_free(buffer); |
53 | g_free(buffer); |
|
|
54 | |
45 | return ret; |
55 | return ret; |
46 | } |
56 | } |
47 | |
57 | |
48 | void |
58 | void |
49 | tempfile_unlink(char *suffix, char *name) |
59 | tempfile_unlink(char *suffix, char *name) |
… | |
… | |
58 | { |
68 | { |
59 | char buffer_from[4096],buffer_to[4096]; |
69 | char buffer_from[4096],buffer_to[4096]; |
60 | sprintf(buffer_from,"%s_%s.tmp",from,suffix); |
70 | sprintf(buffer_from,"%s_%s.tmp",from,suffix); |
61 | sprintf(buffer_to,"%s_%s.tmp",to,suffix); |
71 | sprintf(buffer_to,"%s_%s.tmp",to,suffix); |
62 | dbg_assert(rename(buffer_from, buffer_to) == 0); |
72 | dbg_assert(rename(buffer_from, buffer_to) == 0); |
63 | |
|
|
64 | } |
73 | } |
|
|
74 | |