fnt2fon: janitorial IgnoredReturnValues.

Lionel Debroux lionel_debroux at yahoo.fr
Fri Sep 14 07:09:12 CDT 2007


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

diff --git a/tools/fnt2fon.c b/tools/fnt2fon.c
index 2c5c74f..a4d307d 100644
--- a/tools/fnt2fon.c
+++ b/tools/fnt2fon.c
@@ -57,10 +57,23 @@ static const BYTE MZ_hdr[] = {'M',  'Z',  0x0d, 0x01, 0x01, 0x00, 0x00, 0x00, 0x
 };
 
 static const char *output_file;
+static BOOL fp_is_open = FALSE;
+static FILE *fp = NULL;
+static FILE *ofp = NULL;
 
 static void cleanup_files(void)
 {
-    if (output_file) unlink( output_file );
+    if (fp && fp_is_open) {
+        (void)fclose(fp);
+        fp = NULL; fp_is_open = FALSE;
+    }
+
+    // output_file != NULL is almost synonymous of 'ofp is open'.
+    if (output_file) {
+        if (unlink(output_file) != 0) {
+            (void)fprintf(stderr, "Error deleting output file\n");
+        }
+    }
 }
 
 static void exit_on_signal( int sig )
@@ -94,7 +107,6 @@ static void error(const char *s, ...)
 int main(int argc, char **argv)
 {
     int i, j;
-    FILE *fp, *ofp;
     long off;
     char name[200];
     int c;
@@ -138,6 +150,7 @@ int main(int argc, char **argv)
             usage(argv);
             exit(1);
         }
+        fp_is_open = TRUE;
         fread(&ver, sizeof(short), 1, fp);
         if(ver != 0x200 && ver != 0x300) {
             error("invalid fnt file %s ver %d", argv[i+1], ver);
@@ -155,6 +168,7 @@ int main(int argc, char **argv)
         *cp = '\0';
         fprintf(stderr, "%s %d pts %dx%d dpi\n", name, pt, dpi[0], dpi[1]);
         fclose(fp);
+        fp = NULL; fp_is_open = FALSE;
         /* fontdir entries for version 3 fonts are the same as for version 2 */
         fontdir_len += 0x74 + strlen(name) + 1;
         if(i == 0) {
@@ -280,6 +294,7 @@ int main(int argc, char **argv)
     
     for(res = first_res, i = 0; i < num_files; i++, res++) {
         fp = fopen(argv[i+1], "rb");
+        fp_is_open = TRUE;
 
         fwrite(&res, sizeof(res), 1, ofp);
         fread(buf, 0x72, 1, fp);
@@ -295,6 +310,7 @@ int main(int argc, char **argv)
         *cp = '\0';
         fwrite(name, strlen(name) + 1, 1, ofp);
         fclose(fp);
+        fp = NULL; fp_is_open = FALSE;
     }
 
     pad = ftell(ofp) & 0xf;
@@ -305,6 +321,7 @@ int main(int argc, char **argv)
 
     for(res = first_res, i = 0; i < num_files; i++, res++) {
         fp = fopen(argv[i+1], "rb");
+        fp_is_open = TRUE;
 
         while(1) {
             nread = read(fileno(fp), buf, sizeof(buf));
@@ -312,6 +329,7 @@ int main(int argc, char **argv)
             fwrite(buf, nread, 1, ofp);
         }
         fclose(fp);
+        fp = NULL; fp_is_open = FALSE;
         pad = file_lens[i] & 0xf;
         if(pad != 0)
             pad = 0x10 - pad;
@@ -319,6 +337,7 @@ int main(int argc, char **argv)
             fputc(0x00, ofp);
     }
     fclose(ofp);
+    ofp = NULL;
     output_file = NULL;
 
     return 0;
-- 
1.5.2.4


--------------070503070206090604080400--



More information about the wine-patches mailing list