]> www.infradead.org Git - mtd-utils.git/commitdiff
ubi-utils: fix bug using readdir
authorAdrian Hunter <ext-adrian.hunter@nokia.com>
Mon, 7 Jan 2008 07:49:25 +0000 (09:49 +0200)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Tue, 15 Jan 2008 09:53:07 +0000 (11:53 +0200)
Library functions never reset errno to zero, so if you want
to use its value to check for errors then you must set it to zero
before calling the library function (in this case readdir).

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/src/libubi.c

index 855aa82d8c2f3b569e488d8a89451f197258cfd9..be06f70a8c45131e5bfcf6984434fc39bfb33067 100644 (file)
@@ -872,9 +872,13 @@ int ubi_get_info(libubi_t desc, struct ubi_info *info)
        }
 
        info->lowest_dev_num = INT_MAX;
-       while ((dirent = readdir(sysfs_ubi))) {
+       while (1) {
                int dev_num, ret;
 
+               errno = 0;
+               dirent = readdir(sysfs_ubi);
+               if (!dirent)
+                       break;
                /*
                 * Make sure this direntry is a directory and not a symlink -
                 * Linux puts symlinks to UBI volumes on this UBI device to the
@@ -1022,9 +1026,14 @@ int ubi_get_dev_info1(libubi_t desc, int dev_num, struct ubi_dev_info *info)
                return -1;
 
        info->lowest_vol_num = INT_MAX;
-       while ((dirent = readdir(sysfs_ubi))) {
+
+       while (1) {
                int vol_id, ret, devno;
 
+               errno = 0;
+               dirent = readdir(sysfs_ubi);
+               if (!dirent)
+                       break;
                ret = sscanf(dirent->d_name, UBI_VOL_NAME_PATT, &devno, &vol_id);
                if (ret == 2 && devno == dev_num) {
                        info->vol_count += 1;