]> err.no Git - dpkg/commitdiff
Fairly heavy work(net no lines changed), to fix longjmp() clashing variable
authorAdam Heath <doogie@debian.org>
Mon, 20 May 2002 03:54:22 +0000 (03:54 +0000)
committerAdam Heath <doogie@debian.org>
Mon, 20 May 2002 03:54:22 +0000 (03:54 +0000)
warnings.  Also, a few miscellaneous gcc -W<foo> fixes.

ChangeLog
utils/md5sum.c

index 95ba8da0758e3cec56b28d1fad9d52c3d38c6edc..e8798f05d0aec4cfc688c1055b3163ce74dd33bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun, 19 May 2002 22:56:41 -0500 Adam Heath <doogie@debian.org>
+
+  * utils/md5sum.c: Fairly heavy work(net no lines changed), to fix
+    longjmp() clashing variable warnings.  Also, a few miscellaneous gcc
+    -W<foo> fixes.
+
 Sun May 19 20:25:05 CDT 2002 Adam Heath <doogie@debian.org>
 
   * lib/showpkg.c, lib/utils.c, optlib/long-options.c, main/archives.c,
index c9c4a592cfdc2eadf1d4d5f00337571488a14bf5..b0bed5079802c4a9b69e86bb022e631c0f8c9d41 100644 (file)
@@ -68,6 +68,7 @@ int mdfile(int fd, unsigned char **digest);
 int do_check(FILE *chkf);
 int hex_digit(int c);
 int get_md5_line(FILE *fp, unsigned char *digest, char *file);
+int process_arg(const char* arg, int bin_mode, unsigned char **digest);
 
 char *progname;
 int verbose = 0;
@@ -79,7 +80,7 @@ print_md5sum_error(const char* emsg, const char* arg) {
        fprintf(stderr, _("error processing %s: %s\n"), arg, emsg);
 }
 
-void cu_closefile(int argc, void** argv) {
+static void cu_closefile(int argc, void** argv) {
        FILE *f = (FILE*)(argv[0]);
        fclose(f);
 }
@@ -134,38 +135,55 @@ main(int argc, char **argv)
                exit(0);
        }
        for ( ; argc > 0; --argc, ++argv) {
-               if (setjmp(ejbuf)) {
-                       error_unwind(ehflag_bombout);
-                       rc++;
-                       continue;
-               }
-               push_error_handler(&ejbuf, print_md5sum_error, *argv);
-               if (bin_mode)
-                       fp = fopen(*argv, FOPRBIN);
-               else
-                       fp = fopen(*argv, FOPRTXT);
-               if (fp == NULL) {
-                       perror(*argv);
-                       rc++;
-                       continue;
+               switch (process_arg(*argv, bin_mode, &digest)) {
+                       case 1:
+                               rc++;
+                               break;
+                       case 2:
+                               perror(*argv);
+                               rc++;
+                               break;
+                       case 3:
+                               perror(*argv);
+                               rc++;
+                               break;
                }
-               push_cleanup(cu_closefile,ehflag_bombout, 0,0, 1,(void*)fp);
-               
-               mdfile(fileno(fp), &digest);
                printf("%s %c%s\n", digest, bin_mode ? '*' : ' ', *argv);
-               pop_cleanup(ehflag_normaltidy); /* fd= fopen() */
-               fclose(fp);
-               fp= NULL;
-               set_error_display(0, 0);
-               error_unwind(ehflag_normaltidy);
        }
-
        return rc;
 }
 
-void usage() NONRETURNING;
+int process_arg(const char* arg, int bin_mode, unsigned char **digest)
+{
+       jmp_buf ejbuf;
+       FILE *fp = NULL;
+
+       if (setjmp(ejbuf)) {
+               error_unwind(ehflag_bombout);
+               return 1;
+       }
+       push_error_handler(&ejbuf, print_md5sum_error, arg);
+       if (bin_mode)
+               fp = fopen(arg, FOPRBIN);
+       else
+               fp = fopen(arg, FOPRTXT);
+       if (fp == NULL)
+               return 2;
+       push_cleanup(cu_closefile,ehflag_bombout, 0,0, 1,(void*)fp);
+       if (mdfile(fileno(fp), digest)) {
+               fclose(fp);
+               return 3;
+       }
+       pop_cleanup(ehflag_normaltidy); /* fd= fopen() */
+       fclose(fp);
+       set_error_display(0, 0);
+       error_unwind(ehflag_normaltidy);
+       return 0;
+}
+
+void usage(void) NONRETURNING;
 void
-usage()
+usage(void)
 {
         fputs(_("usage: md5sum [-bv] [-c [file]] | [file...]\n\
 Generates or checks MD5 Message Digests\n\
@@ -238,9 +256,7 @@ do_check(FILE *chkf)
        int rc, ex = 0, failed = 0, checked = 0;
        unsigned char chk_digest[32], *file_digest = NULL;
        char filename[256];
-       FILE *fp;
        size_t flen = 14;
-       jmp_buf ejbuf;
 
        while ((rc = get_md5_line(chkf, chk_digest, filename)) >= 0) {
                if (rc == 0)    /* not an md5 line */
@@ -250,32 +266,16 @@ do_check(FILE *chkf)
                                flen = strlen(filename);
                        fprintf(stderr, "%-*s ", (int)flen, filename);
                }
-               if (setjmp(ejbuf)) {
-                       error_unwind(ehflag_bombout);
-                       ex = 2;
-                       continue;
-               }
-               push_error_handler(&ejbuf, print_md5sum_error, filename);
-               if (bin_mode || rc == 2)
-                       fp = fopen(filename, FOPRBIN);
-               else
-                       fp = fopen(filename, FOPRTXT);
-               if (fp == NULL) {
-                       fprintf(stderr, _("%s: can't open %s\n"), progname, filename);
-                       ex = 2;
-                       continue;
-               }
-               push_cleanup(cu_closefile,ehflag_bombout, 0,0, 1,(void*)fp);
-               if (mdfile(fileno(fp), &file_digest)) {
-                       fprintf(stderr, _("%s: error reading %s\n"), progname, filename);
-                       ex = 2;
-                       fclose(fp);
-                       continue;
+               switch (process_arg(filename, bin_mode || rc == 2, &file_digest)) {
+                       case 2:
+                               fprintf(stderr, _("%s: can't open %s\n"), progname, filename);
+                               ex = 2;
+                               break;
+                       case 3:
+                               fprintf(stderr, _("%s: error reading %s\n"), progname, filename);
+                               ex = 2;
+                               break;
                }
-               pop_cleanup(ehflag_normaltidy); /* fd= fopen() */
-               fclose(fp);
-               set_error_display(0, 0);
-               error_unwind(ehflag_normaltidy);
                if (memcmp(chk_digest, file_digest, 32) != 0) {
                        if (verbose)
                                fprintf(stderr, _("FAILED\n"));