Use return value to check error 01/244701/2
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 23 Sep 2020 08:39:22 +0000 (17:39 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 23 Sep 2020 09:12:33 +0000 (18:12 +0900)
- In general, return value is used to detect error
- Reference : http://c-faq.com/misc/errno.html

Change-Id: Ib58419ed2012e050d79fe1437b726885fafe046a
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/system-recovery.c

index 28f92c7013acad9c198700924a3eb39ae320989e..fa4d2695ca7b4fbc7f87a9e52267a710cfd14d4a 100644 (file)
@@ -58,6 +58,7 @@ static unsigned long long total_image_size;
 
 static int find_recovery_image(void)
 {
+       int ret = SUCCEED;
        _CLEANUP_DIR_ DIR *dir = NULL;
        struct dirent *dirent = NULL;
        char path[PATH_MAX - FIELD_LENGTH];
@@ -75,10 +76,8 @@ static int find_recovery_image(void)
 
                        snprintf(path, sizeof(path), "%s/%s/%s",
                                        USB_MOUNTPOINT_ROOT, dirent->d_name, RECOVERY_IMAGE_BASENAME);
-                       errno = 0;
-                       access(path, F_OK);
-                       switch (errno) {
-                       case 0:
+                       ret = access(path, F_OK);
+                       if (ret == 0) {
                                _I("Find recovery image : %s", path);
 
                                /**
@@ -90,10 +89,7 @@ static int find_recovery_image(void)
                                                "There are many recovery images. Please put exactly one image");
 
                                snprintf(recovery_image_path, sizeof(recovery_image_path), "%s", path);
-                               break;
-                       case ENOENT:
-                               break;
-                       default:
+                       } else if (errno != ENOENT) {
                                _E("access for %s failed (%d)", path, errno);
                                return errno;
                        }
@@ -119,16 +115,13 @@ static int try_launch(const char *argv, ...)
                return EINVAL;
        }
 
-       errno = 0;
-       access(path, F_OK);
-       switch (errno) {
-       case 0:
+       ret = access(path, F_OK);
+       if (ret == 0)
                _I("Find %s... Try to launch it", path);
-               break;
-       case ENOENT:
+       else if (errno == ENOENT) {
                _W("%s not found... Skip it", path);
                return SUCCEED;
-       default:
+       } else {
                _E("access for %s failed (%d)", path, errno);
                return errno;
        }