]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Clean up Matthais's "fix crash when /proc/acpi/ac_acapter is not present"
authorTheodore Ts'o <tytso@mit.edu>
Mon, 17 Jan 2005 18:59:18 +0000 (13:59 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 17 Jan 2005 18:59:18 +0000 (13:59 -0500)
patch.

e2fsck/unix.c

index 43a64b5ea48cb31ec9b128070d1aa02626666d6c..1adc18310c8aab63ae26956d6c129fa22c617a6b 100644 (file)
@@ -222,24 +222,25 @@ static int is_on_batt(void)
                return (acflag != 1);
        }
        d = opendir("/proc/acpi/ac_adapter");
-       while (d && (de=readdir(d))) {
-               if (!strncmp(".", de->d_name, 1))
-                       continue;
-               snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state", 
-                        de->d_name);
-               f = fopen(fname, "r");
-               if (!f)
-                       continue;
-               if (fscanf(f, "%s %s", tmp2, tmp) != 2)
-                       tmp[0] = 0;
-               fclose(f);
-               if (strncmp(tmp, "off-line", 8) == 0) {
-                       closedir(d);
-                       return 1;
+       if (d) {
+               while (de=readdir(d)) {
+                       if (!strncmp(".", de->d_name, 1))
+                               continue;
+                       snprintf(fname, 80, "/proc/acpi/ac_adapter/%s/state", 
+                                de->d_name);
+                       f = fopen(fname, "r");
+                       if (!f)
+                               continue;
+                       if (fscanf(f, "%s %s", tmp2, tmp) != 2)
+                               tmp[0] = 0;
+                       fclose(f);
+                       if (strncmp(tmp, "off-line", 8) == 0) {
+                               closedir(d);
+                               return 1;
+                       }
                }
-       }
-       if (d)
                closedir(d);
+       }
        return 0;
 }