diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c index 89e54d6f4..2fb442dc3 100644 --- a/disk-utils/cfdisk.c +++ b/disk-utils/cfdisk.c @@ -986,7 +986,9 @@ static size_t menuitem_get_line(struct cfdisk *cf, size_t idx) if (!m->page_sz) /* small menu */ return (ui_lines - (cf->menu->nitems + 1)) / 2 + idx; return (idx % m->page_sz) + 1; - } else { + } + + { size_t len = MENU_H_ITEMWIDTH(m) + MENU_H_BETWEEN; /** item width */ size_t items = ui_cols / len; /* items per line */ @@ -1003,7 +1005,9 @@ static int menuitem_get_column(struct cfdisk *cf, size_t idx) if ((size_t) ui_cols <= nc) return 0; return (ui_cols - nc) / 2; - } else { + } + + { size_t len = MENU_H_ITEMWIDTH(cf->menu) + MENU_H_BETWEEN; /* item width */ size_t items = ui_cols / len; /* items per line */ size_t extra = items < cf->menu->nitems ? /* extra space on line */ @@ -1877,7 +1881,7 @@ static int ui_get_size(struct cfdisk *cf, /* context */ if (rc == 0) { ui_warnx(_("Please, specify size.")); continue; /* nothing specified */ - } else if (rc == -CFDISK_ERR_ESC) + } if (rc == -CFDISK_ERR_ESC) break; /* cancel dialog */ if (strcmp(buf, dflt) == 0) diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c index a071c0eb4..8391e5d94 100644 --- a/disk-utils/fsck.c +++ b/disk-utils/fsck.c @@ -172,8 +172,8 @@ static int string_to_int(const char *s) l = strtol(s, &p, 0); if (*p || l == LONG_MIN || l == LONG_MAX || l < 0 || l > INT_MAX) return -1; - else - return (int) l; + + return (int) l; } /* Do we really really want to check this fs? */ diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c index 3a43dd7b9..5145bcfd7 100644 --- a/disk-utils/fsck.cramfs.c +++ b/disk-utils/fsck.cramfs.c @@ -131,12 +131,15 @@ static int get_superblock_endianness(uint32_t magic) if (magic == CRAMFS_MAGIC) { cramfs_is_big_endian = HOST_IS_BIG_ENDIAN; return 0; - } else if (magic == + } + + if (magic == u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) { cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN; return 0; - } else - return -1; + } + + return -1; } static void test_super(int *start, size_t * length) diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c index 53879895d..d3725ee0d 100644 --- a/disk-utils/fsck.minix.c +++ b/disk-utils/fsck.minix.c @@ -300,7 +300,7 @@ static int is_valid_zone_nr(unsigned short nr) { if (nr < get_first_zone()) return 0; - else if (nr >= get_nzones()) + if (nr >= get_nzones()) return 0; return 1; } @@ -1355,7 +1355,9 @@ main(int argc, char **argv) { if (repair) printf(_("%s is clean, no check.\n"), device_name); return retcode; - } else if (force) + } + + if (force) printf(_("Forcing filesystem check on %s.\n"), device_name); else if (repair) printf(_("Filesystem on %s is dirty, needs checking.\n"), diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index e6afd2df0..1d0d17bf1 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -547,9 +547,9 @@ static int is_zero(unsigned char const *begin, unsigned len) (len-- == 0 || (begin[3] == '\0' && memcmp(begin, begin + 4, len) == 0)))))))); - else - /* Never create holes. */ - return 0; + + /* Never create holes. */ + return 0; } /* diff --git a/disk-utils/partx.c b/disk-utils/partx.c index e1f6b8f9e..4f73c5f23 100644 --- a/disk-utils/partx.c +++ b/disk-utils/partx.c @@ -332,7 +332,9 @@ static int del_parts(int fd, const char *device, dev_t devno, if (verbose) printf(_("%s: partition #%d removed\n"), device, i); continue; - } else if (errno == ENXIO) { + } + + if (errno == ENXIO) { if (verbose) printf(_("%s: partition #%d doesn't exist\n"), device, i); continue; diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 0c1462779..24d1f729c 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -1869,14 +1869,18 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) buf[sizeof(buf) - 1] = '\0'; fdisk_warnx(sf->cxt, _("Unknown script header '%s' -- ignore."), buf); continue; - } else if (rc < 0) { + } + + if (rc < 0) { DBG(PARSE, ul_debug("script parsing failed, trying sfdisk specific commands")); buf[sizeof(buf) - 1] = '\0'; rc = loop_control_commands(sf, dp, buf); if (rc) break; continue; - } else if (rc == 1) { + } + + if (rc == 1) { rc = SFDISK_DONE_EOF; if (!sf->quiet) fputs(_("Done.\n"), stdout); @@ -1910,7 +1914,9 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv) rc = fdisk_set_partition(sf->cxt, partno, pa); rc = rc == 0 ? SFDISK_DONE_ASK : SFDISK_DONE_ABORT; break; - } else if (!rc) { /* add partition */ + } + + if (!rc) { /* add partition */ if (!sf->interactive && !sf->quiet && (!sf->prompt || startswith(sf->prompt, SFDISK_PROMPT))) { refresh_prompt_buffer(sf, devname, next_partno, created); diff --git a/lib/blkdev.c b/lib/blkdev.c index 0616142b8..c71550e63 100644 --- a/lib/blkdev.c +++ b/lib/blkdev.c @@ -281,8 +281,8 @@ int blkdev_is_cdrom(int fd) if ((ret = ioctl(fd, CDROM_GET_CAPABILITY, NULL)) < 0) return 0; - else - return ret; + + return ret; } #else int blkdev_is_cdrom(int fd __attribute__((__unused__))) diff --git a/lib/encode.c b/lib/encode.c index bee5bd53d..10b5971c5 100644 --- a/lib/encode.c +++ b/lib/encode.c @@ -48,7 +48,9 @@ size_t ul_encode_to_utf8(int enc, unsigned char *dest, size_t len, if (c == 0) { dest[j] = '\0'; break; - } else if (c < 0x80) { + } + + if (c < 0x80) { if (j+1 >= len) break; dest[j++] = (uint8_t) c; diff --git a/lib/loopdev.c b/lib/loopdev.c index 99a093926..76eac7b8d 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -1074,8 +1074,8 @@ found: uint64_t sz = 0; return loopcxt_get_sizelimit(lc, &sz) == 0 && sz == sizelimit; - } else - return rc; + } + return rc; } return 1; } diff --git a/lib/strutils.c b/lib/strutils.c index b76ab9952..e1629fb56 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -255,7 +255,9 @@ int parse_switch(const char *arg, const char *errmesg, ...) if (strcmp(arg, a) == 0) { va_end(ap); return 1; - } else if (strcmp(arg, b) == 0) { + } + + if (strcmp(arg, b) == 0) { va_end(ap); return 0; } @@ -1110,19 +1112,16 @@ int main(int argc, char *argv[]) if (argc == 3 && strcmp(argv[1], "--size") == 0) return test_strutils_sizes(argc - 1, argv + 1); - else if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0) + if (argc == 4 && strcmp(argv[1], "--cmp-paths") == 0) return test_strutils_cmp_paths(argc - 1, argv + 1); - else if (argc == 4 && strcmp(argv[1], "--strdup-member") == 0) + if (argc == 4 && strcmp(argv[1], "--strdup-member") == 0) return test_strdup_to_member(argc - 1, argv + 1); - else { - fprintf(stderr, "usage: %1$s --size [suffix]\n" - " %1$s --cmp-paths \n" - " %1$s --strdup-member \n", - argv[0]); - exit(EXIT_FAILURE); - } + fprintf(stderr, "usage: %1$s --size [suffix]\n" + " %1$s --cmp-paths \n" + " %1$s --strdup-member \n", + argv[0]); return EXIT_FAILURE; } diff --git a/lib/ttyutils.c b/lib/ttyutils.c index 8649f435a..706456503 100644 --- a/lib/ttyutils.c +++ b/lib/ttyutils.c @@ -73,9 +73,9 @@ int get_terminal_stdfd(void) { if (isatty(STDIN_FILENO)) return STDIN_FILENO; - else if (isatty(STDOUT_FILENO)) + if (isatty(STDOUT_FILENO)) return STDOUT_FILENO; - else if (isatty(STDERR_FILENO)) + if (isatty(STDERR_FILENO)) return STDERR_FILENO; return -EINVAL; diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c index 3ca64183c..889ff772c 100644 --- a/libblkid/src/partitions/gpt.c +++ b/libblkid/src/partitions/gpt.c @@ -321,7 +321,7 @@ static int probe_gpt_pt(blkid_probe pr, ret = is_pmbr_valid(pr, NULL); if (ret < 0) return ret; - else if (ret == 0) + if (ret == 0) goto nothing; errno = 0; diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index faf3596e6..e148fddc0 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1245,7 +1245,9 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) return blkid_probe_step_back(pr); - } else if (dryrun) { + } + + if (dryrun) { /* wipe in memory only */ blkid_probe_hide_range(pr, magoff, len); return blkid_probe_step_back(pr); diff --git a/libblkid/src/superblocks/befs.c b/libblkid/src/superblocks/befs.c index 516d80093..211feae9f 100644 --- a/libblkid/src/superblocks/befs.c +++ b/libblkid/src/superblocks/befs.c @@ -169,8 +169,7 @@ static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_bloc return get_custom_block_run(pr, bs, &ds->direct[i], start, length, fs_le); - else - start -= br_len; + start -= br_len; } } else if (start < (int64_t) FS64_TO_CPU(ds->max_indirect_range, fs_le)) { struct block_run *br; @@ -192,8 +191,7 @@ static unsigned char *get_tree_node(blkid_probe pr, const struct befs_super_bloc if (start < br_len) return get_custom_block_run(pr, bs, &br[i], start, length, fs_le); - else - start -= br_len; + start -= br_len; } } else if (start < (int64_t) FS64_TO_CPU(ds->max_double_indirect_range, fs_le)) { struct block_run *br; @@ -333,8 +331,8 @@ static int64_t get_key_value(blkid_probe pr, const struct befs_super_block *bs, if ((int64_t) FS64_TO_CPU(bn->overflow_link, fs_le) == BPLUSTREE_NULL) return FS64_TO_CPU(values[last], fs_le); - else - node_pointer = FS64_TO_CPU(values[last], fs_le); + + node_pointer = FS64_TO_CPU(values[last], fs_le); } else if (cmp < 0) node_pointer = FS64_TO_CPU(bn->overflow_link, fs_le); else { @@ -352,9 +350,10 @@ static int64_t get_key_value(blkid_probe pr, const struct befs_super_block *bs, fs_le) == BPLUSTREE_NULL) return FS64_TO_CPU(values[mid], fs_le); - else - break; - } else if (cmp < 0) + break; + } + + if (cmp < 0) first = mid + 1; else last = mid - 1; @@ -411,7 +410,9 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs, sizeof(uint64_t)); break; - } else if (FS32_TO_CPU(sd->type, fs_le) == 0 + } + + if (FS32_TO_CPU(sd->type, fs_le) == 0 && FS16_TO_CPU(sd->name_size, fs_le) == 0 && FS16_TO_CPU(sd->data_size, fs_le) == 0) break; @@ -437,7 +438,7 @@ static int get_uuid(blkid_probe pr, const struct befs_super_block *bs, if (value < 0) return value == -ENOENT ? BLKID_PROBE_NONE : value; - else if (value > 0) { + if (value > 0) { bi = (struct befs_inode *) blkid_probe_get_buffer(pr, value << FS32_TO_CPU(bs->block_shift, fs_le), FS32_TO_CPU(bs->block_size, fs_le)); diff --git a/libblkid/src/superblocks/luks.c b/libblkid/src/superblocks/luks.c index 67d7cfcc5..0230b3492 100644 --- a/libblkid/src/superblocks/luks.c +++ b/libblkid/src/superblocks/luks.c @@ -108,18 +108,18 @@ static int probe_luks(blkid_probe pr, const struct blkid_idmag *mag __attribute_ if (!memcmp(header->magic, LUKS_MAGIC, LUKS_MAGIC_L)) { /* LUKS primary header was found. */ return luks_attributes(pr, header, 0); - } else { - /* No primary header, scan for known offsets of LUKS2 secondary header. */ - for (i = 0; i < ARRAY_SIZE(secondary_offsets); i++) { - header = (struct luks2_phdr *) blkid_probe_get_buffer(pr, - secondary_offsets[i], sizeof(struct luks2_phdr)); + } - if (!header) - return errno ? -errno : BLKID_PROBE_NONE; + /* No primary header, scan for known offsets of LUKS2 secondary header. */ + for (i = 0; i < ARRAY_SIZE(secondary_offsets); i++) { + header = (struct luks2_phdr *) blkid_probe_get_buffer(pr, + secondary_offsets[i], sizeof(struct luks2_phdr)); - if (!memcmp(header->magic, LUKS_MAGIC_2, LUKS_MAGIC_L)) - return luks_attributes(pr, header, secondary_offsets[i]); - } + if (!header) + return errno ? -errno : BLKID_PROBE_NONE; + + if (!memcmp(header->magic, LUKS_MAGIC_2, LUKS_MAGIC_L)) + return luks_attributes(pr, header, secondary_offsets[i]); } return BLKID_PROBE_NONE; diff --git a/libblkid/src/superblocks/minix.c b/libblkid/src/superblocks/minix.c index a3354f6e7..b521efb2b 100644 --- a/libblkid/src/superblocks/minix.c +++ b/libblkid/src/superblocks/minix.c @@ -143,7 +143,8 @@ static int probe_minix(blkid_probe pr, ext = blkid_probe_get_buffer(pr, 0x400 + 0x38, 2); if (!ext) return errno ? -errno : 1; - else if (memcmp(ext, "\123\357", 2) == 0) + + if (memcmp(ext, "\123\357", 2) == 0) return 1; blkid_probe_sprintf_version(pr, "%d", version); diff --git a/libblkid/src/superblocks/swap.c b/libblkid/src/superblocks/swap.c index 3f21391c8..94f51aa11 100644 --- a/libblkid/src/superblocks/swap.c +++ b/libblkid/src/superblocks/swap.c @@ -91,7 +91,9 @@ static int probe_swap(blkid_probe pr, const struct blkid_idmag *mag) blkid_probe_set_version(pr, "0"); return 0; - } else if (!memcmp(mag->magic, "SWAPSPACE2", mag->len)) + } + + if (!memcmp(mag->magic, "SWAPSPACE2", mag->len)) return swap_set_info(pr, "1"); return 1; diff --git a/libblkid/src/superblocks/udf.c b/libblkid/src/superblocks/udf.c index a8f009964..f2865b2d0 100644 --- a/libblkid/src/superblocks/udf.c +++ b/libblkid/src/superblocks/udf.c @@ -217,7 +217,7 @@ static int probe_udf(blkid_probe pr, if (vsd_len == 2048) { if (vsd_2048_valid == 0) continue; - else if (vsd_2048_valid == 1) + if (vsd_2048_valid == 1) goto anchor; } diff --git a/libfdisk/src/context.c b/libfdisk/src/context.c index efbd80c1a..153f1a862 100644 --- a/libfdisk/src/context.c +++ b/libfdisk/src/context.c @@ -226,7 +226,8 @@ struct fdisk_label *fdisk_get_label(struct fdisk_context *cxt, const char *name) if (!name) return cxt->label; - else if (strcasecmp(name, "mbr") == 0) + + if (strcasecmp(name, "mbr") == 0) name = "dos"; for (i = 0; i < cxt->nlabels; i++) @@ -818,17 +819,16 @@ int fdisk_reread_partition_table(struct fdisk_context *cxt) if (!S_ISBLK(cxt->dev_st.st_mode)) return 0; - else { - DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl")); - sync(); + + DBG(CXT, ul_debugobj(cxt, "calling re-read ioctl")); + sync(); #ifdef BLKRRPART - fdisk_info(cxt, _("Calling ioctl() to re-read partition table.")); - i = ioctl(cxt->dev_fd, BLKRRPART); + fdisk_info(cxt, _("Calling ioctl() to re-read partition table.")); + i = ioctl(cxt->dev_fd, BLKRRPART); #else - errno = ENOSYS; - i = 1; + errno = ENOSYS; + i = 1; #endif - } if (i) { fdisk_warn(cxt, _("Re-reading the partition table failed.")); diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index a79912e8b..5e8ad178e 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -1715,7 +1715,9 @@ static int dos_add_partition(struct fdisk_context *cxt, if (!ext_pe) { fdisk_warnx(cxt, _("Extended partition does not exists. Failed to add logical partition.")); return -EINVAL; - } else if (fdisk_partition_has_start(pa) + } + + if (fdisk_partition_has_start(pa) && pa->start < l->ext_offset && pa->start > get_abs_partition_end(ext_pe)) { DBG(LABEL, ul_debug("DOS: pa template specifies partno>=4, but start out of extended")); @@ -1775,8 +1777,8 @@ static int dos_add_partition(struct fdisk_context *cxt, if (pa && fdisk_partition_has_start(pa)) { fdisk_warnx(cxt, msg); return -EINVAL; - } else - fdisk_info(cxt, msg); + } + fdisk_info(cxt, msg); } rc = add_logical(cxt, pa, &res); } else { diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 3aa1ea67c..f737ff9be 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -753,7 +753,9 @@ int fdisk_partition_next_partno( } return -ERANGE; - } else if (pa && fdisk_partition_has_partno(pa)) { + } + + if (pa && fdisk_partition_has_partno(pa)) { DBG(PART, ul_debugobj(pa, "next partno (specified=%zu)", pa->partno)); @@ -763,7 +765,9 @@ int fdisk_partition_next_partno( *n = pa->partno; return 0; - } else if (fdisk_has_dialogs(cxt)) + } + + if (fdisk_has_dialogs(cxt)) return fdisk_ask_partnum(cxt, n, 1); return -EINVAL; diff --git a/libfdisk/src/sgi.c b/libfdisk/src/sgi.c index 884e385ac..d5391b51a 100644 --- a/libfdisk/src/sgi.c +++ b/libfdisk/src/sgi.c @@ -396,14 +396,18 @@ static int sgi_check_bootfile(struct fdisk_context *cxt, const char *name) "e.g. \"/unix\" or \"/unix.save\".")); return -EINVAL; - } else if (sz > sizeof(sgilabel->boot_file)) { + } + + if (sz > sizeof(sgilabel->boot_file)) { fdisk_warnx(cxt, P_("Name of bootfile is too long: %zu byte maximum.", "Name of bootfile is too long: %zu bytes maximum.", sizeof(sgilabel->boot_file)), sizeof(sgilabel->boot_file)); return -EINVAL; - } else if (*name != '/') { + } + + if (*name != '/') { fdisk_warnx(cxt, _("Bootfile must have a fully qualified pathname.")); return -EINVAL; } diff --git a/libmount/python/context.c b/libmount/python/context.c index 982414d01..6e3ffcb39 100644 --- a/libmount/python/context.c +++ b/libmount/python/context.c @@ -34,12 +34,12 @@ static PyObject *Context_set_tables_errcb(ContextObjext *self, PyObject *func, if (!PyCallable_Check(func)) return NULL; - else { - PyObject *tmp = self->table_errcb; - Py_INCREF(func); - self->table_errcb = func; - Py_XDECREF(tmp); - } + + PyObject *tmp = self->table_errcb; + Py_INCREF(func); + self->table_errcb = func; + Py_XDECREF(tmp); + return UL_IncRef(self); } @@ -570,7 +570,7 @@ static int Context_set_optsmode(ContextObjext *self, PyObject *value, void *clos PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; } - else if (!PyLong_Check(value)) { + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -586,7 +586,7 @@ static int Context_set_syscall_status(ContextObjext *self, PyObject *value, void PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; } - else if (!PyLong_Check(value)) { + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -602,7 +602,7 @@ static int Context_set_user_mflags(ContextObjext *self, PyObject *value, void *c PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; } - else if (!PyLong_Check(value)) { + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -619,7 +619,7 @@ static int Context_set_mflags(ContextObjext *self, PyObject *value, void *closur PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; } - else if (!PyLong_Check(value)) { + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } diff --git a/libmount/python/fs.c b/libmount/python/fs.c index b35cfe33d..0ba78bed0 100644 --- a/libmount/python/fs.c +++ b/libmount/python/fs.c @@ -370,7 +370,9 @@ static int Fs_set_freq(FsObject *self, PyObject *value, PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; - } else if (!PyLong_Check(value)) { + } + + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -395,7 +397,9 @@ static int Fs_set_passno(FsObject *self, PyObject *value, void *closure __attrib if (!value) { PyErr_SetString(PyExc_TypeError, NODEL_ATTR); return -1; - } else if (!PyLong_Check(value)) { + } + + if (!PyLong_Check(value)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -810,7 +814,9 @@ static PyObject *Fs_copy_fs(FsObject *self, PyObject *args, PyObject *kwds) DBG(FS, pymnt_debug_h(dest, "copy data")); return (PyObject *)dest; - } else if (dest == Py_None) { /* create new object */ + } + + if (dest == Py_None) { /* create new object */ FsObject *result = PyObject_New(FsObject, &FsType); DBG(FS, pymnt_debug_h(result, "new copy")); diff --git a/libmount/python/tab.c b/libmount/python/tab.c index ce604dd61..e3185065e 100644 --- a/libmount/python/tab.c +++ b/libmount/python/tab.c @@ -492,7 +492,9 @@ static PyObject *Table_next_fs(TableObject *self) if (rc == 1) { mnt_reset_iter(self->iter, MNT_ITER_FORWARD); Py_RETURN_NONE; - } else if (rc) + } + + if (rc) return UL_RaiseExc(-rc); return PyObjectResultFs(fs); diff --git a/libmount/src/cache.c b/libmount/src/cache.c index 7adadb849..0e76891b8 100644 --- a/libmount/src/cache.c +++ b/libmount/src/cache.c @@ -578,7 +578,8 @@ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache) p = (char *) cache_find_path(cache, path); if (p) return p; - else { + + { struct libmnt_iter itr; struct libmnt_fs *fs = NULL; @@ -586,8 +587,8 @@ char *mnt_resolve_target(const char *path, struct libmnt_cache *cache) while (mnt_table_next_fs(cache->mtab, &itr, &fs) == 0) { if (!mnt_fs_is_kernel(fs) - || mnt_fs_is_swaparea(fs) - || !mnt_fs_streq_target(fs, path)) + || mnt_fs_is_swaparea(fs) + || !mnt_fs_streq_target(fs, path)) continue; p = strdup(path); diff --git a/libmount/src/context.c b/libmount/src/context.c index 91fe8e4bf..2b598dbb9 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -2864,7 +2864,9 @@ int mnt_context_is_fs_mounted(struct libmnt_context *cxt, } *mounted = 0; return 0; /* /proc not mounted */ - } else if (rc) + } + + if (rc) return rc; *mounted = __mnt_table_is_fs_mounted(mtab, fs, diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index ff7ee695e..c00e73261 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -1733,12 +1733,16 @@ int mnt_context_get_mount_excode( if (buf) snprintf(buf, bufsz, _("filesystem was mounted, but failed to update userspace mount table")); return MNT_EX_FILEIO; - } else if (rc == -MNT_ERR_NAMESPACE) { + } + + if (rc == -MNT_ERR_NAMESPACE) { if (buf) snprintf(buf, bufsz, _("filesystem was mounted, but failed to switch namespace back")); return MNT_EX_SYSERR; - } else if (rc < 0) + } + + if (rc < 0) return mnt_context_get_generic_excode(rc, buf, bufsz, _("filesystem was mounted, but any subsequent operation failed: %m")); diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index e3547d356..f3e079981 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -1253,11 +1253,15 @@ int mnt_context_get_umount_excode( if (buf) snprintf(buf, bufsz, _("not mounted")); return MNT_EX_USAGE; - } else if (rc == -MNT_ERR_LOCK) { + } + + if (rc == -MNT_ERR_LOCK) { if (buf) snprintf(buf, bufsz, _("locking failed")); return MNT_EX_FILEIO; - } else if (rc == -MNT_ERR_NAMESPACE) { + } + + if (rc == -MNT_ERR_NAMESPACE) { if (buf) snprintf(buf, bufsz, _("failed to switch namespace")); return MNT_EX_SYSERR; @@ -1265,7 +1269,7 @@ int mnt_context_get_umount_excode( return mnt_context_get_generic_excode(rc, buf, bufsz, _("umount failed: %m")); - } else if (mnt_context_get_syscall_errno(cxt) == 0) { + } if (mnt_context_get_syscall_errno(cxt) == 0) { /* * umount(2) syscall success, but something else failed * (probably error in mtab processing). @@ -1274,12 +1278,16 @@ int mnt_context_get_umount_excode( if (buf) snprintf(buf, bufsz, _("filesystem was unmounted, but failed to update userspace mount table")); return MNT_EX_FILEIO; - } else if (rc == -MNT_ERR_NAMESPACE) { + } + + if (rc == -MNT_ERR_NAMESPACE) { if (buf) snprintf(buf, bufsz, _("filesystem was unmounted, but failed to switch namespace back")); return MNT_EX_SYSERR; - } else if (rc < 0) + } + + if (rc < 0) return mnt_context_get_generic_excode(rc, buf, bufsz, _("filesystem was unmounted, but any subsequent operation failed: %m")); diff --git a/libmount/src/lock.c b/libmount/src/lock.c index e6eefa13a..484841fbc 100644 --- a/libmount/src/lock.c +++ b/libmount/src/lock.c @@ -474,25 +474,25 @@ static int lock_mtab(struct libmnt_lock *ml) /* proceed, since it was us who created the lockfile anyway */ } break; - } else { - /* Someone else made the link. Wait. */ - int err = mnt_wait_mtab_lock(ml, &flock, maxtime.tv_sec); - - if (err == 1) { - DBG(LOCKS, ul_debugobj(ml, - "%s: can't create link: time out (perhaps " - "there is a stale lock file?)", lockfile)); - rc = -ETIMEDOUT; - goto failed; - - } else if (err < 0) { - rc = err; - goto failed; - } - nanosleep(&waittime, NULL); - close(ml->lockfile_fd); - ml->lockfile_fd = -1; } + + /* Someone else made the link. Wait. */ + int err = mnt_wait_mtab_lock(ml, &flock, maxtime.tv_sec); + + if (err == 1) { + DBG(LOCKS, ul_debugobj(ml, + "%s: can't create link: time out (perhaps " + "there is a stale lock file?)", lockfile)); + rc = -ETIMEDOUT; + goto failed; + + } else if (err < 0) { + rc = err; + goto failed; + } + nanosleep(&waittime, NULL); + close(ml->lockfile_fd); + ml->lockfile_fd = -1; } DBG(LOCKS, ul_debugobj(ml, "%s: (%d) successfully locked", lockfile, getpid())); diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index 1f6eb1a57..dada02ed3 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -263,7 +263,9 @@ static int userspace_add_watch(struct monitor_entry *me, int *final, int *fd) if (fd) *fd = wd; break; - } else if (errno != ENOENT) { + } + + if (errno != ENOENT) { rc = -errno; break; } diff --git a/libmount/src/optmap.c b/libmount/src/optmap.c index abd81bc8e..1f3ace3d8 100644 --- a/libmount/src/optmap.c +++ b/libmount/src/optmap.c @@ -209,7 +209,7 @@ const struct libmnt_optmap *mnt_get_builtin_optmap(int id) if (id == MNT_LINUX_MAP) return linux_flags_map; - else if (id == MNT_USERSPACE_MAP) + if (id == MNT_USERSPACE_MAP) return userspace_opts_map; return NULL; } diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c index 49fc9cc40..f975cef24 100644 --- a/libmount/src/optstr.c +++ b/libmount/src/optstr.c @@ -983,7 +983,7 @@ int mnt_optstr_fix_uid(char **optstr, char *value, size_t valsz, char **next) (*(value + 7) == ',' || !*(value + 7))) return set_uint_value(optstr, getuid(), value, end, next); - else if (!isdigit(*value)) { + if (!isdigit(*value)) { uid_t id; int rc; char *p = strndup(value, valsz); @@ -1031,7 +1031,7 @@ int mnt_optstr_fix_gid(char **optstr, char *value, size_t valsz, char **next) (*(value + 7) == ',' || !*(value + 7))) return set_uint_value(optstr, getgid(), value, end, next); - else if (!isdigit(*value)) { + if (!isdigit(*value)) { int rc; gid_t id; char *p = strndup(value, valsz); diff --git a/libmount/src/utils.c b/libmount/src/utils.c index 77207e7e7..606830797 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -701,28 +701,32 @@ static int try_write(const char *filename, const char *directory) if (eaccess(filename, R_OK|W_OK) == 0) { DBG(UTILS, ul_debug(" access OK")); return 0; - } else if (errno != ENOENT) { + } + + if (errno != ENOENT) { DBG(UTILS, ul_debug(" access FAILED")); return -errno; - } else if (directory) { + } + + if (directory) { /* file does not exist; try if directory is writable */ if (eaccess(directory, R_OK|W_OK) != 0) rc = -errno; DBG(UTILS, ul_debug(" access %s [%s]", rc ? "FAILED" : "OK", directory)); return rc; - } else -#endif - { - DBG(UTILS, ul_debug(" doing open-write test")); - - int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC, - S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); - if (fd < 0) - rc = -errno; - else - close(fd); } +#endif + + DBG(UTILS, ul_debug(" doing open-write test")); + + int fd = open(filename, O_RDWR|O_CREAT|O_CLOEXEC, + S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH); + if (fd < 0) + rc = -errno; + else + close(fd); + return rc; } @@ -1210,7 +1214,7 @@ static int read_procfs_file(int fd, char **buf, size_t *bufsiz) } break; - } else if (ret > 0) { + } if (ret > 0) { /* success -- verify no event during read */ struct pollfd fds[] = { { .fd = fd, .events = POLLPRI } diff --git a/libsmartcols/src/calculate.c b/libsmartcols/src/calculate.c index 625fe71ea..360c7e0c1 100644 --- a/libsmartcols/src/calculate.c +++ b/libsmartcols/src/calculate.c @@ -60,7 +60,7 @@ static int count_cell_width(struct libscols_table *tb, if (cl->is_extreme && cl->width_avg && len > cl->width_avg * 2) return 0; - else if (scols_column_is_noextremes(cl)) { + if (scols_column_is_noextremes(cl)) { cl->extreme_sum += len; cl->extreme_count++; } diff --git a/libsmartcols/src/cell.c b/libsmartcols/src/cell.c index 0717a2d09..4cd6e5981 100644 --- a/libsmartcols/src/cell.c +++ b/libsmartcols/src/cell.c @@ -226,7 +226,7 @@ int scols_cell_get_alignment(const struct libscols_cell *ce) { if (ce->flags & SCOLS_CELL_FL_RIGHT) return SCOLS_CELL_FL_RIGHT; - else if (ce->flags & SCOLS_CELL_FL_CENTER) + if (ce->flags & SCOLS_CELL_FL_CENTER) return SCOLS_CELL_FL_CENTER; return SCOLS_CELL_FL_LEFT; /* default */ diff --git a/libuuid/src/parse.c b/libuuid/src/parse.c index 536b1ed23..ce9cc09e9 100644 --- a/libuuid/src/parse.c +++ b/libuuid/src/parse.c @@ -62,8 +62,7 @@ int uuid_parse_range(const char *in_start, const char *in_end, uuid_t uu) (i == 23)) { if (*cp == '-') continue; - else - return -1; + return -1; } if (i== 36) if (*cp == 0) diff --git a/libuuid/src/predefined.c b/libuuid/src/predefined.c index 0be90ca04..fec17739b 100644 --- a/libuuid/src/predefined.c +++ b/libuuid/src/predefined.c @@ -68,13 +68,16 @@ const uuid_t *uuid_get_template(const char *alias) if (!strcmp(alias, "dns")) return &NameSpace_DNS; - else if (!strcmp(alias, "url")) + + if (!strcmp(alias, "url")) return &NameSpace_URL; - else if (!strcmp(alias, "oid")) + + if (!strcmp(alias, "oid")) return &NameSpace_OID; - else if (!strcmp(alias, "x500") || !strcmp(alias, "x.500")) + + if (!strcmp(alias, "x500") || !strcmp(alias, "x.500")) return &NameSpace_X500; - else - return NULL; + + return NULL; } diff --git a/login-utils/islocal.c b/login-utils/islocal.c index 469bc5629..ab5c52ed5 100644 --- a/login-utils/islocal.c +++ b/login-utils/islocal.c @@ -56,12 +56,11 @@ static int is_local_in_file(const char *user, const char *filename) * but it is just an optimisation * anyway. */ break; - } else { - /* we read a whole username, but it - * is the wrong user. Skip to the - * next line. */ - skip = 1; } + /* we read a whole username, but it + * is the wrong user. Skip to the + * next line. */ + skip = 1; } else if ('\n' == chin) { /* This line contains no colon; it's * malformed. No skip since we are already @@ -96,17 +95,17 @@ int main(int argc, char *argv[]) fprintf(stderr, _("Usage: %s ...\n"), argv[0]); return 1; - } else { - int i; - for (i = 2; i < argc; i++) { - const int rv = is_local_in_file(argv[i], argv[1]); - if (rv < 0) { - perror(argv[1]); - return 2; - } - printf("%d:%s\n", rv, argv[i]); - } - return 0; } + + int i; + for (i = 2; i < argc; i++) { + const int rv = is_local_in_file(argv[i], argv[1]); + if (rv < 0) { + perror(argv[1]); + return 2; + } + printf("%d:%s\n", rv, argv[i]); + } + return 0; } #endif diff --git a/login-utils/logindefs.c b/login-utils/logindefs.c index 2b505d255..9782e6804 100644 --- a/login-utils/logindefs.c +++ b/login-utils/logindefs.c @@ -391,8 +391,9 @@ int get_hushlogin_status(struct passwd *pwd, int force_check) rc = effective_access(buf, O_RDONLY); if (rc == 0) return 1; - else if (rc == -1 && errno == EACCES) - return -1; + + if (rc == -1 && errno == EACCES) + return -1; } } diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c index defa230b9..5ccae8655 100644 --- a/login-utils/utmpdump.c +++ b/login-utils/utmpdump.c @@ -222,15 +222,14 @@ static FILE *dump(FILE *in, const char *filename, int follow, FILE *out) #ifdef HAVE_INOTIFY_INIT if (follow_by_inotify(in, filename, out) == 0) return NULL; /* file already closed */ - else #endif - /* fallback for systems without inotify or with non-free - * inotify instances */ - for (;;) { - while (fread(&ut, sizeof(ut), 1, in) == 1) - print_utline(&ut, out); - sleep(1); - } + /* fallback for systems without inotify or with non-free + * inotify instances */ + for (;;) { + while (fread(&ut, sizeof(ut), 1, in) == 1) + print_utline(&ut, out); + sleep(1); + } return in; } diff --git a/misc-utils/cal.c b/misc-utils/cal.c index feff1e805..ec37a88d2 100644 --- a/misc-utils/cal.c +++ b/misc-utils/cal.c @@ -618,8 +618,8 @@ static int leap_year(const struct cal_control *ctl, int32_t year) { if (year <= ctl->reform_year) return !(year % 4); - else - return ( !(year % 4) && (year % 100) ) || !(year % 400); + + return ( !(year % 4) && (year % 100) ) || !(year % 400); } static void init_monthnames(struct cal_control *ctl) diff --git a/misc-utils/findmnt-verify.c b/misc-utils/findmnt-verify.c index 2b6f5e7fa..1d255426d 100644 --- a/misc-utils/findmnt-verify.c +++ b/misc-utils/findmnt-verify.c @@ -407,7 +407,7 @@ static int verify_fstype(struct verify_context *vfy) && mnt_fs_get_option(vfy->fs, "move", NULL, NULL) == 1) return verify_warn(vfy, _("\"none\" FS type is recommended for bind or move oprations only")); - else if (strcmp(type, "auto") == 0) + if (strcmp(type, "auto") == 0) isauto = 1; else if (strcmp(type, "swap") == 0) isswap = 1; diff --git a/misc-utils/getopt.c b/misc-utils/getopt.c index 3fa158eb3..01a2df6dd 100644 --- a/misc-utils/getopt.c +++ b/misc-utils/getopt.c @@ -392,8 +392,8 @@ int main(int argc, char *argv[]) */ printf(" --\n"); return EXIT_SUCCESS; - } else - parse_error(_("missing optstring argument")); + } + parse_error(_("missing optstring argument")); } add_longopt(&ctl, NULL, 0); /* init */ diff --git a/misc-utils/kill.c b/misc-utils/kill.c index 19182b4a3..9cfb03cb9 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -505,7 +505,7 @@ int main(int argc, char **argv) #endif if (ct && nerrs == 0) return EXIT_SUCCESS; /* full success */ - else if (ct == nerrs) + if (ct == nerrs) return EXIT_FAILURE; /* all failed */ return KILL_EXIT_SOMEOK; /* partial success */ diff --git a/misc-utils/rename.c b/misc-utils/rename.c index a9378af59..d17b25abe 100644 --- a/misc-utils/rename.c +++ b/misc-utils/rename.c @@ -96,8 +96,8 @@ static int ask(char *name) buf[1] = '\0'; if (rpmatch(buf) == RPMATCH_YES) return 0; - else - return 1; + + return 1; } static int do_symlink(char *from, char *to, char *s, int verbose, int noact, diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index af24efc14..ef95946e2 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -428,8 +428,7 @@ static void server_loop(const char *socket_path, const char *pidfile_path, if (ns < 0) { if ((errno == EAGAIN) || (errno == EINTR)) continue; - else - err(EXIT_FAILURE, "accept"); + err(EXIT_FAILURE, "accept"); } len = read(ns, &op, 1); if (len != 1) { diff --git a/sys-utils/eject.c b/sys-utils/eject.c index 2f3b200bf..f1087f3e8 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -298,13 +298,12 @@ static char *find_device(const char *name) if ((*name == '.' || *name == '/') && access(name, F_OK) == 0) return xstrdup(name); - else { - char buf[PATH_MAX]; - snprintf(buf, sizeof(buf), "/dev/%s", name); - if (access(buf, F_OK) == 0) - return xstrdup(buf); - } + char buf[PATH_MAX]; + + snprintf(buf, sizeof(buf), "/dev/%s", name); + if (access(buf, F_OK) == 0) + return xstrdup(buf); return NULL; } diff --git a/sys-utils/hwclock-rtc.c b/sys-utils/hwclock-rtc.c index 0caf6be10..fb9486848 100644 --- a/sys-utils/hwclock-rtc.c +++ b/sys-utils/hwclock-rtc.c @@ -258,48 +258,48 @@ static int synchronize_to_clock_tick_rtc(const struct hwclock_control *ctl) if (rtc_fd == -1) { warn(_("cannot open rtc device")); return ret; - } else { - /* Turn on update interrupts (one per second) */ - int rc = ioctl(rtc_fd, RTC_UIE_ON, 0); + } - if (rc != -1) { - /* - * Just reading rtc_fd fails on broken hardware: no - * update interrupt comes and a bootscript with a - * hwclock call hangs - */ - fd_set rfds; - struct timeval tv; + /* Turn on update interrupts (one per second) */ + int rc = ioctl(rtc_fd, RTC_UIE_ON, 0); - /* - * Wait up to ten seconds for the next update - * interrupt - */ - FD_ZERO(&rfds); - FD_SET(rtc_fd, &rfds); - tv.tv_sec = 10; - tv.tv_usec = 0; - rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv); - if (0 < rc) - ret = 0; - else if (rc == 0) { - warnx(_("select() to %s to wait for clock tick timed out"), - rtc_dev_name); - } else - warn(_("select() to %s to wait for clock tick failed"), - rtc_dev_name); - /* Turn off update interrupts */ - rc = ioctl(rtc_fd, RTC_UIE_OFF, 0); - if (rc == -1) - warn(_("ioctl() to %s to turn off update interrupts failed"), - rtc_dev_name); + if (rc != -1) { + /* + * Just reading rtc_fd fails on broken hardware: no + * update interrupt comes and a bootscript with a + * hwclock call hangs + */ + fd_set rfds; + struct timeval tv; + + /* + * Wait up to ten seconds for the next update + * interrupt + */ + FD_ZERO(&rfds); + FD_SET(rtc_fd, &rfds); + tv.tv_sec = 10; + tv.tv_usec = 0; + rc = select(rtc_fd + 1, &rfds, NULL, NULL, &tv); + if (0 < rc) + ret = 0; + else if (rc == 0) { + warnx(_("select() to %s to wait for clock tick timed out"), + rtc_dev_name); + } else + warn(_("select() to %s to wait for clock tick failed"), + rtc_dev_name); + /* Turn off update interrupts */ + rc = ioctl(rtc_fd, RTC_UIE_OFF, 0); + if (rc == -1) + warn(_("ioctl() to %s to turn off update interrupts failed"), + rtc_dev_name); } else if (errno == ENOTTY || errno == EINVAL) { /* rtc ioctl interrupts are unimplemented */ ret = busywait_for_rtc_clock_tick(ctl, rtc_fd); } else warn(_("ioctl(%d, RTC_UIE_ON, 0) to %s failed"), rtc_fd, rtc_dev_name); - } return ret; } diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index 89d8a1fd9..1026adc23 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -876,7 +876,9 @@ static int save_adjtime(const struct hwclock_control *ctl, if (fp == NULL) { warn(_("cannot open %s"), ctl->adj_file_name); return EXIT_FAILURE; - } else if (fputs(content, fp) < 0 || close_stream(fp) != 0) { + } + + if (fputs(content, fp) < 0 || close_stream(fp) != 0) { warn(_("cannot update %s"), ctl->adj_file_name); return EXIT_FAILURE; } @@ -1053,7 +1055,9 @@ manipulate_clock(const struct hwclock_control *ctl, const time_t set_time, } if (ctl->show || ctl->get) { return display_time(startup_hclocktime); - } else if (ctl->set) { + } + + if (ctl->set) { set_hardware_clock_exact(ctl, set_time, startup_time); if (!ctl->noadjfile) adjust_drift_factor(ctl, adjtime, t2tv(set_time), diff --git a/sys-utils/ipcutils.c b/sys-utils/ipcutils.c index e5ead7ba6..674b6124d 100644 --- a/sys-utils/ipcutils.c +++ b/sys-utils/ipcutils.c @@ -145,8 +145,8 @@ int ipc_shm_get_info(int id, struct shm_data **shmds) if (id == p->shm_perm.id) { i = 1; break; - } else - continue; + } + continue; } p->next = xcalloc(1, sizeof(struct shm_data)); @@ -284,8 +284,8 @@ int ipc_sem_get_info(int id, struct sem_data **semds) get_sem_elements(p); i = 1; break; - } else - continue; + } + continue; } p->next = xcalloc(1, sizeof(struct sem_data)); @@ -397,8 +397,8 @@ int ipc_msg_get_info(int id, struct msg_data **msgds) p->q_qbytes = msgseg.msg_qbytes; i = 1; break; - } else - continue; + } + continue; } p->next = xcalloc(1, sizeof(struct msg_data)); diff --git a/sys-utils/lsipc.c b/sys-utils/lsipc.c index 5a1a3d7ac..debd9a9b1 100644 --- a/sys-utils/lsipc.c +++ b/sys-utils/lsipc.c @@ -221,12 +221,12 @@ static int column_name_to_id(const char *name, size_t namesz) if (i > COL_CTIME) { if (i >= LOWER && i <= UPPER) return i; - else { - warnx(_("column %s does not apply to the specified IPC"), name); - return -1; - } - } else - return i; + + warnx(_("column %s does not apply to the specified IPC"), name); + return -1; + } + + return i; } } warnx(_("unknown column: %s"), name); diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c index cab934317..eec8e273b 100644 --- a/sys-utils/lsns.c +++ b/sys-utils/lsns.c @@ -596,11 +596,10 @@ static int netnsid_xasputs(char **str, int netnsid) if (netnsid >= 0) return xasprintf(str, "%d", netnsid); #ifdef NETNSA_NSID_NOT_ASSIGNED - else if (netnsid == NETNSA_NSID_NOT_ASSIGNED) + if (netnsid == NETNSA_NSID_NOT_ASSIGNED) return xasprintf(str, "%s", "unassigned"); #endif - else - return 0; + return 0; } static int read_namespaces(struct lsns *ls) diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c index 607849066..c8c7d5c42 100644 --- a/sys-utils/prlimit.c +++ b/sys-utils/prlimit.c @@ -397,7 +397,9 @@ static int get_range(char *str, rlim_t *soft, rlim_t *hard, int *found) *found |= PRLIMIT_SOFT | PRLIMIT_HARD; return 0; - } else if (*str == ':') { /* <:hard> */ + } + + if (*str == ':') { /* <:hard> */ str++; if (strcmp(str, INFINITY_STR) != 0) { diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c index 0d352e453..6211aacb5 100644 --- a/sys-utils/unshare.c +++ b/sys-utils/unshare.c @@ -593,7 +593,7 @@ int main(int argc, char *argv[]) err(EXIT_FAILURE, _("waitpid failed")); if (WIFEXITED(status)) return WEXITSTATUS(status); - else if (WIFSIGNALED(status)) + if (WIFSIGNALED(status)) kill(getpid(), WTERMSIG(status)); err(EXIT_FAILURE, _("child exit failed")); } diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index bc0d0d069..003349fad 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -385,7 +385,9 @@ static char *get_mm_stat(struct zram *z, size_t idx, int bytes) ul_path_read_string(sysfs, &str, name); return str; - } else if (ul_path_read_u64(sysfs, &num, name) == 0) + } + + if (ul_path_read_u64(sysfs, &num, name) == 0) return size_to_human_string(SIZE_SUFFIX_1LETTER, num); return NULL; diff --git a/term-utils/agetty.c b/term-utils/agetty.c index 49151e085..f88a8da51 100644 --- a/term-utils/agetty.c +++ b/term-utils/agetty.c @@ -1701,7 +1701,9 @@ static int wait_for_term_input(int fd) if (FD_ISSET(fd, &rfds)) { return 1; - } else if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) { + } + + if (netlink_fd >= 0 && FD_ISSET(netlink_fd, &rfds)) { if (!process_netlink()) continue; diff --git a/term-utils/scriptlive.c b/term-utils/scriptlive.c index b17dc9ef3..ee2573a72 100644 --- a/term-utils/scriptlive.c +++ b/term-utils/scriptlive.c @@ -126,11 +126,11 @@ static int process_next_step(struct scriptlive *ss) ul_pty_set_mainloop_time(ss->pty, &target); break; - } else { - /* no delay -- immediately write */ - rc = replay_emit_step_data(ss->setup, ss->step, fd); - fdatasync(fd); } + + /* no delay -- immediately write */ + rc = replay_emit_step_data(ss->setup, ss->step, fd); + fdatasync(fd); } while (rc == 0); return rc; diff --git a/term-utils/setterm.c b/term-utils/setterm.c index 456abc59e..22afc7616 100644 --- a/term-utils/setterm.c +++ b/term-utils/setterm.c @@ -247,11 +247,11 @@ static char *find_optional_arg(char **av, char *oa, int *oi) char *arg; if (oa) return oa; - else { - arg = av[*oi]; - if (!arg || arg[0] == '-') - return NULL; - } + + arg = av[*oi]; + if (!arg || arg[0] == '-') + return NULL; + (*oi)++; return arg; } @@ -265,29 +265,28 @@ static int parse_blank(char **av, char *oa, int *oi) return BLANKEDSCREEN; if (!strcmp(arg, "force")) return BLANKSCREEN; - else if (!strcmp(arg, "poke")) + if (!strcmp(arg, "poke")) return UNBLANKSCREEN; - else { - int ret; - ret = strtos32_or_err(arg, _("argument error")); - if (ret < 0 || BLANK_MAX < ret) - errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg); - return ret; - } + int ret; + + ret = strtos32_or_err(arg, _("argument error")); + if (ret < 0 || BLANK_MAX < ret) + errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg); + return ret; } static int parse_powersave(const char *arg) { if (strcmp(arg, "on") == 0) return VESA_BLANK_MODE_SUSPENDV; - else if (strcmp(arg, "vsync") == 0) + if (strcmp(arg, "vsync") == 0) return VESA_BLANK_MODE_SUSPENDV; - else if (strcmp(arg, "hsync") == 0) + if (strcmp(arg, "hsync") == 0) return VESA_BLANK_MODE_SUSPENDH; - else if (strcmp(arg, "powerdown") == 0) + if (strcmp(arg, "powerdown") == 0) return VESA_BLANK_MODE_POWERDOWN; - else if (strcmp(arg, "off") == 0) + if (strcmp(arg, "off") == 0) return VESA_BLANK_MODE_OFF; errx(EXIT_FAILURE, "%s: %s", _("argument error"), arg); } diff --git a/text-utils/more.c b/text-utils/more.c index bbced5c38..69a0b89f6 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -895,10 +895,9 @@ static void ttyin(struct more_control *ctl, char buf[], int nmax, char pchar) erase_one_column(ctl); } continue; - } else { - if (!ctl->erase_line) - ctl->prompt_len = maxlen; } + if (!ctl->erase_line) + ctl->prompt_len = maxlen; } else if (c == ctl->output_tty.c_cc[VKILL] && !slash) { if (ctl->hard_tty) { show(ctl, c); @@ -1340,8 +1339,8 @@ static void search(struct more_control *ctl, char buf[], int n) puts(ctl->line_buf); } break; - } else - more_poll(ctl, 1); + } + more_poll(ctl, 1); } /* Move ctrl+c signal handling back to more_key_command(). */ signal(SIGINT, SIG_DFL); diff --git a/text-utils/pg.c b/text-utils/pg.c index 7eef9b88b..5d01ebff3 100644 --- a/text-utils/pg.c +++ b/text-utils/pg.c @@ -987,42 +987,43 @@ static void pgfile(FILE *f, const char *name) *b = '\0'; dline = pagelen; break; - } else { - if (nobuf) - fseeko(f, fpos, SEEK_SET); - canjump = 1; - p = fgets(b, READBUF, f); - if (nobuf) - if ((fpos = ftello(f)) == -1) - warn("%s", name); - canjump = 0; } + + if (nobuf) + fseeko(f, fpos, SEEK_SET); + canjump = 1; + p = fgets(b, READBUF, f); + if (nobuf) + if ((fpos = ftello(f)) == -1) + warn("%s", name); + canjump = 0; + if (p == NULL || *b == '\0') { if (ferror(f)) warn("%s", name); eofline = fline; eof = 1; break; - } else { - if (!nobuf) - fputs(b, fbuf); - fwrite_all(&pos, sizeof pos, 1, find); - if (!fflag) { - oldpos = pos; - p = b; - while (*(p = endline(ttycols, - p)) - != '\0') { - pos = oldpos + (p - b); - fwrite_all(&pos, - sizeof pos, - 1, find); - fline++; - bline++; - } - } - fline++; } + + if (!nobuf) + fputs(b, fbuf); + fwrite_all(&pos, sizeof pos, 1, find); + if (!fflag) { + oldpos = pos; + p = b; + while (*(p = endline(ttycols, + p)) + != '\0') { + pos = oldpos + (p - b); + fwrite_all(&pos, + sizeof pos, + 1, find); + fline++; + bline++; + } + } + fline++; } while (line > bline++); } else { /* eofline != 0 */ @@ -1057,7 +1058,9 @@ static void pgfile(FILE *f, const char *name) skip(1); } continue; - } else if (eof) { + } + + if (eof) { /* We are not searching. */ line = bline; } else if (*b != '\0') { diff --git a/text-utils/ul.c b/text-utils/ul.c index e8137edbd..39b69a597 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -69,8 +69,8 @@ static int put1wc(int c) { if (putwchar(c) == WEOF) return EOF; - else - return c; + + return c; } #define putwp(s) tputs(s, STDOUT_FILENO, put1wc) #else