Use -1 to mark invalid file descriptors as 0 can theoretically be a
valid open file descriptor.
Do not ignore lseek() return value and check if an error has occured.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
return;
close(p->fd);
- p->fd = 0;
+ p->fd = -1;
}
static int mtd_volume_load(struct mtd_volume *p)
struct mtd_info_user mtdInfo;
struct erase_info_user mtdLockInfo;
- if (p->fd) {
- lseek(p->fd, 0, SEEK_SET);
- return 0;
- }
+ if (p->fd >= 0)
+ return (lseek(p->fd, 0, SEEK_SET) == -1);
if (!p->chr)
return -1;
p->fd = mtd_open(p->chr, 0);
if (p->fd < 0) {
- p->fd = 0;
ULOG_ERR("Could not open mtd device: %s\n", p->chr);
return -1;
}
v->name = strdup(name);
v->drv = &mtd_driver;
p->idx = atoi(idx);
+ p->fd = -1;
snprintf(buffer, sizeof(buffer), "/dev/mtdblock%s", idx);
v->blk = strdup(buffer);