summaryrefslogtreecommitdiff
path: root/ubi-utils/src
diff options
context:
space:
mode:
authorAdrian Hunter <ext-adrian.hunter@nokia.com>2008-01-07 09:49:25 +0200
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-01-15 11:53:07 +0200
commit07e6203fd3078d6855e7d33597bdbbae10e555fd (patch)
treef5ddc76bfdf7985f47b77c38f6c0171562908af2 /ubi-utils/src
parent9ba41c4dc891e38c92126bfcc4c366d765841da0 (diff)
ubi-utils: fix bug using readdir
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>
Diffstat (limited to 'ubi-utils/src')
-rw-r--r--ubi-utils/src/libubi.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/ubi-utils/src/libubi.c b/ubi-utils/src/libubi.c
index 855aa82..be06f70 100644
--- a/ubi-utils/src/libubi.c
+++ b/ubi-utils/src/libubi.c
@@ -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;