[PATCH isomd5sum rhel6 2/5] Use symbolic constants for return values (#555107)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 checkisomd5.c    |   27 ++++++++++++++++++---------
 libcheckisomd5.c |   15 +++++++--------
 libcheckisomd5.h |    5 +++++
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/checkisomd5.c b/checkisomd5.c
index dc2c41e..8f2ba8b 100644
--- a/checkisomd5.c
+++ b/checkisomd5.c
@@ -126,17 +126,26 @@ int main(int argc, char **argv) {
     if (data.verbose)
 	printf("\n");
 
-    if (rc == 0)
-	result = "FAIL.\n\nIt is not recommended to use this media.";
-    else if (rc == 2)
-      result = "UNKNOWN.\n\nThe media check was aborted.";
-    else if (rc > 0)
-	result = "PASS.\n\nIt is OK to use this media.";
-    else
-	result = "NA.\n\nNo checksum information available, unable to verify media.";
+    switch (rc) {
+	case ISOMD5SUM_CHECK_FAILED:
+		result = "FAIL.\n\nIt is not recommended to use this media.";
+		break;
+	case ISOMD5SUM_CHECK_ABORTED:
+		result = "UNKNOWN.\n\nThe media check was aborted.";
+		break;
+	case ISOMD5SUM_CHECK_NOT_FOUND:
+		result = "NA.\n\nNo checksum information available, unable to verify media.";
+		break;
+	case ISOMD5SUM_CHECK_PASSED:
+		result = "PASS.\n\nIt is OK to use this media.";
+		break;
+	default:
+		result = "checkisomd5 ERROR - bad return value";
+		break;
+    }
 
     fprintf(stderr, "\nThe media check is complete, the result is: %s\n", result);
 
-    exit (rc == 0);
+    exit (rc == ISOMD5SUM_CHECK_FAILED);
 }
  
diff --git a/libcheckisomd5.c b/libcheckisomd5.c
index cd450df..138438b 100644
--- a/libcheckisomd5.c
+++ b/libcheckisomd5.c
@@ -172,7 +172,6 @@ static int parsepvd(int isofd, char *mediasum, int *skipsectors, long long *isos
     return offset;
 }
 
-/* returns -1 if no checksum encoded in media, 0 if no match, 1 if match */
 /* mediasum is the sum encoded in media, computedsum is one we compute   */
 /* both strings must be pre-allocated at least 33 chars in length        */
 static int checkmd5sum(int isofd, char *mediasum, char *computedsum, checkCallback cb, void *cbdata) {
@@ -196,7 +195,7 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, checkCallba
     MD5_CTX md5ctx, fragmd5ctx;
 
     if ((pvd_offset = parsepvd(isofd, mediasum, &skipsectors, &isosize, &supported, fragmentsums, &fragmentcount)) < 0)
-	return -1;
+	return ISOMD5SUM_CHECK_NOT_FOUND;
 
     /*    printf("Mediasum = %s\n",mediasum); */
 
@@ -264,13 +263,13 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, checkCallba
                 previous_fragment = current_fragment;
                 /* Exit immediately if current fragment sum is incorrect */
                 if (strcmp(thisfragsum, computedsum) != 0) {
-                    return 0;
+                    return ISOMD5SUM_CHECK_FAILED;
                 }
             }
         }
 	offset = offset + nread;
 	if (cb)
-          if(cb(cbdata, offset, isosize - skipsectors*2048)) return 2;
+          if(cb(cbdata, offset, isosize - skipsectors*2048)) return ISOMD5SUM_CHECK_ABORTED;
     }
 
     if (cb)
@@ -292,9 +291,9 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, checkCallba
     /*    printf("mediasum, computedsum = %s %s\n", mediasum, computedsum); */
 
     if (strcmp(mediasum, computedsum))
-	return 0;
+	return ISOMD5SUM_CHECK_FAILED;
     else
-	return 1;
+	return ISOMD5SUM_CHECK_PASSED;
 }
 
 
@@ -309,7 +308,7 @@ static int doMediaCheck(int isofd, char *mediasum, char *computedsum, long long
 			 "primary volume descriptor.\nThis probably "
 			 "means the disc was created without adding the "
 			 "checksum.");
-	return -1;
+	return ISOMD5SUM_CHECK_NOT_FOUND;
     }
 
     rc = checkmd5sum(isofd, mediasum, computedsum, cb, cbdata);
@@ -328,7 +327,7 @@ int mediaCheckFile(char *file, checkCallback cb, void *cbdata) {
 
     if (isofd < 0) {
 	fprintf(stderr, "Unable to find install image %s\n", file);
-	return -1;
+	return ISOMD5SUM_CHECK_NOT_FOUND;
     }
 
     rc = doMediaCheck(isofd, mediasum, computedsum, &isosize, &supported, cb, cbdata);
diff --git a/libcheckisomd5.h b/libcheckisomd5.h
index 5569a85..6987aff 100644
--- a/libcheckisomd5.h
+++ b/libcheckisomd5.h
@@ -1,6 +1,11 @@
 #ifndef __LIBCHECKISOMD5_H__
 #define  __LIBCHECKISOMD5_H__
 
+#define ISOMD5SUM_CHECK_PASSED          1
+#define ISOMD5SUM_CHECK_FAILED          0
+#define ISOMD5SUM_CHECK_ABORTED         2
+#define ISOMD5SUM_CHECK_NOT_FOUND       -1
+
 typedef int (*checkCallback)(void *, long long offset, long long total);
 
 int mediaCheckFile(char *iso, checkCallback cb, void *cbdata);
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux