{
int fd;
bb_loop_info loopinfo;
- char *dev = 0;
+ char *dev = NULL;
fd = open(device, O_RDONLY);
- if (fd < 0) return 0;
- if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
- dev = xasprintf("%ld %s", (long) loopinfo.lo_offset,
- (char *)loopinfo.lo_file_name);
- close(fd);
+ if (fd >= 0) {
+ if (ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo) == 0) {
+ dev = xasprintf("%lu %s", (long) loopinfo.lo_offset,
+ (char *)loopinfo.lo_file_name);
+ }
+ close(fd);
+ }
return dev;
}
int fd, rc;
fd = open(device, O_RDONLY);
- if (fd < 0) return 1;
+ if (fd < 0)
+ return 1;
rc = ioctl(fd, LOOP_CLR_FD, 0);
close(fd);
sprintf(dev, LOOP_FORMAT, i);
/* Ran out of block devices, return failure. */
- if (stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) {
+ if (stat(try, &statbuf) != 0 || !S_ISBLK(statbuf.st_mode)) {
rc = -ENOENT;
break;
}
safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE);
loopinfo.lo_offset = offset;
/* Associate free loop device with file. */
- if (!ioctl(dfd, LOOP_SET_FD, ffd)) {
- if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo))
+ if (ioctl(dfd, LOOP_SET_FD, ffd) == 0) {
+ if (ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo) == 0)
rc = 0;
else
ioctl(dfd, LOOP_CLR_FD, 0);
file isn't pretty either. In general, mounting the same file twice
without using losetup manually is problematic.)
*/
- } else if (strcmp(file, (char *)loopinfo.lo_file_name) != 0
- || offset != loopinfo.lo_offset) {
+ } else
+ if (strcmp(file, (char *)loopinfo.lo_file_name) != 0
+ || offset != loopinfo.lo_offset
+ ) {
rc = -1;
}
close(dfd);
if (*device) break;
}
close(ffd);
- if (!rc) {
+ if (rc == 0) {
if (!*device)
*device = xstrdup(dev);
return (mode == O_RDONLY); /* 1:ro, 0:rw */