Procházet zdrojové kódy

Use libdpkg style error handling in md5sum

Wichert Akkerman před 25 roky
rodič
revize
2a8dcf3860
3 změnil soubory, kde provedl 43 přidání a 13 odebrání
  1. 5 0
      ChangeLog
  2. 1 1
      debian/changelog
  3. 37 12
      utils/md5sum.c

+ 5 - 0
ChangeLog

@@ -1,3 +1,8 @@
+Thu Apr 26 13:36:41 CEST 2001 Wichert Akkerman <wakkerma@debian.org>
+
+  * utils/md5sum.c: use libdpkg error handling since fd_md5 uses that
+    to report errors.
+
 Wed Apr 25 20:20:07 CDT 2001 Adam Heath <doogie@debian.org>
 Wed Apr 25 20:20:07 CDT 2001 Adam Heath <doogie@debian.org>
 
 
   * utils/md5sum.c, lib/mlib.c: Modified mlib.c, to malloc enough space
   * utils/md5sum.c, lib/mlib.c: Modified mlib.c, to malloc enough space

+ 1 - 1
debian/changelog

@@ -108,7 +108,7 @@ dpkg (1.9.0) unstable; urgency=low
   * Fix formating and a typo in the dpkg manpage
   * Fix formating and a typo in the dpkg manpage
   * Document the dpkg.cfg configuration file in dpkg(8)
   * Document the dpkg.cfg configuration file in dpkg(8)
 
 
- -- Wichert Akkerman <wakkerma@debian.org>  Tue, 24 Apr 2001 02:23:46 +0200
+ -- Wichert Akkerman <wakkerma@debian.org>  Thu, 26 Apr 2001 12:39:16 +0200
 
 
 dpkg (1.8.3.1) unstable; urgency=low
 dpkg (1.8.3.1) unstable; urgency=low
 
 

+ 37 - 12
utils/md5sum.c

@@ -72,10 +72,21 @@ char *progname;
 int verbose = 0;
 int verbose = 0;
 int bin_mode = 0;
 int bin_mode = 0;
 
 
-int main(int argc, char **argv) NONRETURNING;
+static
+void
+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) {
+	FILE *f = (FILE*)(argv[0]);
+	fclose(f);
+}
+
 int
 int
 main(int argc, char **argv)
 main(int argc, char **argv)
 {
 {
+	jmp_buf ejbuf;
 	int opt, rc = 0;
 	int opt, rc = 0;
 	int check = 0;
 	int check = 0;
 	FILE *fp = NULL;
 	FILE *fp = NULL;
@@ -109,32 +120,46 @@ main(int argc, char **argv)
 		exit(do_check(fp));
 		exit(do_check(fp));
 	}
 	}
 	if (argc == 0) {
 	if (argc == 0) {
-		if (mdfile(fileno(stdin), &digest)) {
-			fprintf(stderr, _("%s: read error on stdin\n"), progname);
-			exit(2);
+		if (setjmp(ejbuf)) {
+			error_unwind(ehflag_bombout);
+			exit(1);
 		}
 		}
+		push_error_handler(&ejbuf, print_md5sum_error, "stdin");
+
+		mdfile(fileno(stdin), &digest);
 		printf("%s\n", digest);
 		printf("%s\n", digest);
+		set_error_display(0, 0);
+		error_unwind(ehflag_normaltidy);
 		exit(0);
 		exit(0);
 	}
 	}
 	for ( ; argc > 0; --argc, ++argv) {
 	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)
 		if (bin_mode)
 			fp = fopen(*argv, FOPRBIN);
 			fp = fopen(*argv, FOPRBIN);
 		else
 		else
 			fp = fopen(*argv, FOPRTXT);
 			fp = fopen(*argv, FOPRTXT);
 		if (fp == NULL) {
 		if (fp == NULL) {
 			perror(*argv);
 			perror(*argv);
-			rc = 2;
+			rc++;
 			continue;
 			continue;
 		}
 		}
-		if (mdfile(fileno(fp), &digest)) {
-			fprintf(stderr, _("%s: error reading %s\n"), progname, *argv);
-			rc = 2;
-		} else {
-			printf("%s %c%s\n", digest, bin_mode ? '*' : ' ', *argv);
-		}
+		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);
 		fclose(fp);
+		fp= NULL;
+		set_error_display(0, 0);
+		error_unwind(ehflag_normaltidy);
 	}
 	}
-	exit(rc);
+
+	return rc;
 }
 }
 
 
 void usage() NONRETURNING;
 void usage() NONRETURNING;