From ef4440ad1b68d0e8007f632b3c27b0b511213ff9 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 21 Mar 2006 16:18:45 +0100 Subject: [PATCH] sfnt2fnt: Remove output file on failure. --- tools/sfnt2fnt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/sfnt2fnt.c b/tools/sfnt2fnt.c index 6b9f341dd95..63e5b7aab97 100644 --- a/tools/sfnt2fnt.c +++ b/tools/sfnt2fnt.c @@ -55,6 +55,8 @@ typedef struct { #include "poppack.h" +static const char *output_name; + static void usage(char **argv) { fprintf(stderr, "%s foo.ttf ppem enc dpi def_char avg_width\n", argv[0]); @@ -65,6 +67,12 @@ static void usage(char **argv) #define __attribute__(X) #endif +/* atexit handler to cleanup files */ +static void cleanup(void) +{ + if (output_name) unlink( output_name ); +} + static void error(const char *s, ...) __attribute__((format (printf, 1, 2))); static void error(const char *s, ...) @@ -377,10 +385,13 @@ int main(int argc, char **argv) sprintf(output, "%s-%d-%d-%d.fnt", name, enc, dpi, ppem); + atexit( cleanup ); fp = fopen(output, "w"); + output_name = output; fill_fontinfo(face, enc, fp, dpi, def_char, avg_width); fclose(fp); + output_name = NULL; exit(0); }