diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-05 13:20:28 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-05 13:20:28 +0100 |
| commit | 44fbfa78ca6126d658ff48cef79e2f7d29fae6c8 (patch) | |
| tree | 4eff59dd3aff3fe6a46df9bf6cc104a3d3c1ec61 /libbb | |
| parent | 917693b5b3d1ece0ade489bc4d922bfa368b979e (diff) | |
| download | busybox-w32-44fbfa78ca6126d658ff48cef79e2f7d29fae6c8.tar.gz busybox-w32-44fbfa78ca6126d658ff48cef79e2f7d29fae6c8.tar.bz2 busybox-w32-44fbfa78ca6126d658ff48cef79e2f7d29fae6c8.zip | |
libbb/loop.c: style and readability fixes, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
| -rw-r--r-- | libbb/loop.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/libbb/loop.c b/libbb/loop.c index 3fec7ad6d..a11933f35 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
| @@ -56,14 +56,16 @@ char* FAST_FUNC query_loop(const char *device) | |||
| 56 | { | 56 | { |
| 57 | int fd; | 57 | int fd; |
| 58 | bb_loop_info loopinfo; | 58 | bb_loop_info loopinfo; |
| 59 | char *dev = 0; | 59 | char *dev = NULL; |
| 60 | 60 | ||
| 61 | fd = open(device, O_RDONLY); | 61 | fd = open(device, O_RDONLY); |
| 62 | if (fd < 0) return 0; | 62 | if (fd >= 0) { |
| 63 | if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo)) | 63 | if (ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo) == 0) { |
| 64 | dev = xasprintf("%ld %s", (long) loopinfo.lo_offset, | 64 | dev = xasprintf("%lu %s", (long) loopinfo.lo_offset, |
| 65 | (char *)loopinfo.lo_file_name); | 65 | (char *)loopinfo.lo_file_name); |
| 66 | close(fd); | 66 | } |
| 67 | close(fd); | ||
| 68 | } | ||
| 67 | 69 | ||
| 68 | return dev; | 70 | return dev; |
| 69 | } | 71 | } |
| @@ -73,7 +75,8 @@ int FAST_FUNC del_loop(const char *device) | |||
| 73 | int fd, rc; | 75 | int fd, rc; |
| 74 | 76 | ||
| 75 | fd = open(device, O_RDONLY); | 77 | fd = open(device, O_RDONLY); |
| 76 | if (fd < 0) return 1; | 78 | if (fd < 0) |
| 79 | return 1; | ||
| 77 | rc = ioctl(fd, LOOP_CLR_FD, 0); | 80 | rc = ioctl(fd, LOOP_CLR_FD, 0); |
| 78 | close(fd); | 81 | close(fd); |
| 79 | 82 | ||
| @@ -110,7 +113,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
| 110 | sprintf(dev, LOOP_FORMAT, i); | 113 | sprintf(dev, LOOP_FORMAT, i); |
| 111 | 114 | ||
| 112 | /* Ran out of block devices, return failure. */ | 115 | /* Ran out of block devices, return failure. */ |
| 113 | if (stat(try, &statbuf) || !S_ISBLK(statbuf.st_mode)) { | 116 | if (stat(try, &statbuf) != 0 || !S_ISBLK(statbuf.st_mode)) { |
| 114 | rc = -ENOENT; | 117 | rc = -ENOENT; |
| 115 | break; | 118 | break; |
| 116 | } | 119 | } |
| @@ -131,8 +134,8 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
| 131 | safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE); | 134 | safe_strncpy((char *)loopinfo.lo_file_name, file, LO_NAME_SIZE); |
| 132 | loopinfo.lo_offset = offset; | 135 | loopinfo.lo_offset = offset; |
| 133 | /* Associate free loop device with file. */ | 136 | /* Associate free loop device with file. */ |
| 134 | if (!ioctl(dfd, LOOP_SET_FD, ffd)) { | 137 | if (ioctl(dfd, LOOP_SET_FD, ffd) == 0) { |
| 135 | if (!ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo)) | 138 | if (ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo) == 0) |
| 136 | rc = 0; | 139 | rc = 0; |
| 137 | else | 140 | else |
| 138 | ioctl(dfd, LOOP_CLR_FD, 0); | 141 | ioctl(dfd, LOOP_CLR_FD, 0); |
| @@ -143,8 +146,10 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
| 143 | file isn't pretty either. In general, mounting the same file twice | 146 | file isn't pretty either. In general, mounting the same file twice |
| 144 | without using losetup manually is problematic.) | 147 | without using losetup manually is problematic.) |
| 145 | */ | 148 | */ |
| 146 | } else if (strcmp(file, (char *)loopinfo.lo_file_name) != 0 | 149 | } else |
| 147 | || offset != loopinfo.lo_offset) { | 150 | if (strcmp(file, (char *)loopinfo.lo_file_name) != 0 |
| 151 | || offset != loopinfo.lo_offset | ||
| 152 | ) { | ||
| 148 | rc = -1; | 153 | rc = -1; |
| 149 | } | 154 | } |
| 150 | close(dfd); | 155 | close(dfd); |
| @@ -152,7 +157,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
| 152 | if (*device) break; | 157 | if (*device) break; |
| 153 | } | 158 | } |
| 154 | close(ffd); | 159 | close(ffd); |
| 155 | if (!rc) { | 160 | if (rc == 0) { |
| 156 | if (!*device) | 161 | if (!*device) |
| 157 | *device = xstrdup(dev); | 162 | *device = xstrdup(dev); |
| 158 | return (mode == O_RDONLY); /* 1:ro, 0:rw */ | 163 | return (mode == O_RDONLY); /* 1:ro, 0:rw */ |
