btrfs-progs: simplify empty stirngs check

We can do a strlen(str) == 0 in a simpler way.

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2015-11-06 16:53:55 +01:00
parent 49e0f3e646
commit 4e01c34b8b
6 changed files with 14 additions and 14 deletions

View File

@ -1449,7 +1449,7 @@ static struct btrfs_root * link_subvol(struct btrfs_root *root,
int ret;
len = strlen(base);
if (len < 1 || len > BTRFS_NAME_LEN)
if (len == 0 || len > BTRFS_NAME_LEN)
return NULL;
path = btrfs_alloc_path();

View File

@ -1217,7 +1217,7 @@ int main(int ac, char **av)
if (inode) {
struct btrfs_trans_handle *trans;
if (!strlen(field))
if (*field == 0)
print_usage(1);
trans = btrfs_start_transaction(root, 1);
@ -1233,13 +1233,13 @@ int main(int ac, char **av)
goto out_close;
}
if (metadata_block) {
if (!strlen(field))
if (*field == 0)
print_usage(1);
ret = corrupt_metadata_block(root, metadata_block, field);
goto out_close;
}
if (corrupt_di) {
if (!key.objectid || !strlen(field))
if (!key.objectid || *field == 0)
print_usage(1);
ret = corrupt_dir_item(root, &key, field);
goto out_close;
@ -1276,7 +1276,7 @@ int main(int ac, char **av)
goto out_close;
}
if (key.objectid || key.offset || key.type) {
if (!strlen(field))
if (*field == 0)
print_usage(1);
ret = corrupt_key(root, &key, field);
goto out_close;

View File

@ -233,7 +233,7 @@ static int match_search_item_kernel(__u8 *fsid, char *mnt, char *label,
if (!strncmp(uuidbuf, search, search_len))
return 1;
if (strlen(label) && strcmp(label, search) == 0)
if (*label && strcmp(label, search) == 0)
return 1;
if (strcmp(mnt, search) == 0)
@ -403,7 +403,7 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
return ret;
uuid_unparse(fs_info->fsid, uuidbuf);
if (label && strlen(label))
if (label && *label)
printf("Label: '%s' ", label);
else
printf("Label: none ");
@ -823,7 +823,7 @@ static int cmd_filesystem_show(int argc, char **argv)
if (argc > optind) {
search = argv[optind];
if (strlen(search) == 0)
if (*search == 0)
usage(cmd_filesystem_show_usage);
type = check_arg_type(search);

View File

@ -169,7 +169,7 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
BUG_ON(r->cur_subvol.path);
BUG_ON(r->cur_subvol_path[0]);
if (strlen(r->dest_dir_path) == 0) {
if (*r->dest_dir_path == 0) {
strncpy_null(r->cur_subvol_path, path);
} else {
ret = path_cat_out(r->cur_subvol_path, r->dest_dir_path, path);
@ -229,7 +229,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
BUG_ON(r->cur_subvol.path);
BUG_ON(r->cur_subvol_path[0]);
if (strlen(r->dest_dir_path) == 0) {
if (*r->dest_dir_path == 0) {
strncpy_null(r->cur_subvol_path, path);
} else {
ret = path_cat_out(r->cur_subvol_path, r->dest_dir_path, path);
@ -326,7 +326,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
}
}*/
if (strlen(parent_subvol->path) == 0)
if (*parent_subvol->path == 0)
args_v2.fd = dup(r->mnt_fd);
else
args_v2.fd = openat(r->mnt_fd, parent_subvol->path,
@ -1135,7 +1135,7 @@ static int do_receive(struct btrfs_receive *r, const char *tomnt,
* Ok we're inside of a subvol off of the root subvol, we need to
* actually set full_root_path.
*/
if (strlen(root_subvol_path))
if (*root_subvol_path)
r->full_root_path = root_subvol_path;
if (r->dest_dir_chroot) {

View File

@ -101,7 +101,7 @@ void table_dump(struct string_table *tab)
continue;
len = strlen(tab->cells[idx]) - 1;
if (len < 1 || tab->cells[idx][0] == '*')
if (len == 0 || tab->cells[idx][0] == '*')
continue;
if (len > sizes[i])

View File

@ -1516,7 +1516,7 @@ int btrfs_register_all_devices(void)
list_for_each_entry(fs_devices, all_uuids, list) {
list_for_each_entry(device, &fs_devices->devices, dev_list) {
if (strlen(device->name) != 0) {
if (*device->name) {
err = btrfs_register_one_device(device->name);
if (err < 0)
return err;