Alexandre Julliard : fnt2fon: Clean output files when aborting on an error or signal.

Alexandre Julliard julliard at wine.codeweavers.com
Sat May 27 06:34:54 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 411fe29a546e895900d5204df3ed29cf8aaf7f9d
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=411fe29a546e895900d5204df3ed29cf8aaf7f9d

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Sat May 27 13:24:13 2006 +0200

fnt2fon: Clean output files when aborting on an error or signal.

---

 tools/fnt2fon.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/tools/fnt2fon.c b/tools/fnt2fon.c
index ab869e3..3f82fd9 100644
--- a/tools/fnt2fon.c
+++ b/tools/fnt2fon.c
@@ -21,6 +21,7 @@
 #include "config.h"
 #include "wine/port.h"
 
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -55,6 +56,18 @@ static const BYTE MZ_hdr[] = {'M',  'Z',
                  'm',  'o',  'd',  'e',  0x0d, 0x0a, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 
+static const char *output_file;
+
+static void cleanup_files(void)
+{
+    if (output_file) unlink( output_file );
+}
+
+static void exit_on_signal( int sig )
+{
+    exit(1);  /* this will call the atexit functions */
+}
+
 static void usage(char **argv)
 {
     fprintf(stderr, "%s fntfiles output.fon\n", argv[0]);
@@ -177,7 +190,15 @@ int main(int argc, char **argv)
     fontdir_off = (non_resident_name_off + non_resident_name_len + 15) & ~0xf;
     font_off = (fontdir_off + fontdir_len + 15) & ~0x0f;
 
-    ofp = fopen(argv[argc - 1], "wb");
+    atexit( cleanup_files );
+    signal( SIGTERM, exit_on_signal );
+    signal( SIGINT, exit_on_signal );
+#ifdef SIGHUP
+    signal( SIGHUP, exit_on_signal );
+#endif
+
+    output_file = argv[argc - 1];
+    ofp = fopen(output_file, "wb");
 
     fwrite(MZ_hdr, sizeof(MZ_hdr), 1, ofp);
     fwrite(&NE_hdr, sizeof(NE_hdr), 1, ofp);
@@ -288,6 +309,7 @@ int main(int argc, char **argv)
             fputc(0x00, ofp);
     }
     fclose(ofp);
+    output_file = NULL;
 
     return 0;
 }




More information about the wine-cvs mailing list