treewide: replace strcmp() == 0 with spa_streq()

This change is only done in source files for now, header files will be done
separately.
This commit is contained in:
Peter Hutterer 2021-05-18 11:36:13 +10:00
parent d8a9534a9a
commit 7697ed0757
130 changed files with 817 additions and 675 deletions

View file

@ -29,6 +29,8 @@
#include <fcntl.h>
#include <math.h>
#include <spa/utils/string.h>
#include "midifile.h"
#define DEFAULT_TEMPO 500000 /* 500ms per quarter note (120 BPM) is the default */
@ -263,10 +265,10 @@ midi_file_open(const char *filename, const char *mode, struct midi_file_info *in
if (mf == NULL)
return NULL;
if (strcmp(mode, "r") == 0) {
if (spa_streq(mode, "r")) {
if ((res = open_read(mf, filename, info)) < 0)
goto exit_free;
} else if (strcmp(mode, "w") == 0) {
} else if (spa_streq(mode, "w")) {
if ((res = open_write(mf, filename, info)) < 0)
goto exit_free;
} else {

View file

@ -42,6 +42,7 @@
#include <spa/param/audio/type-info.h>
#include <spa/param/props.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/utils/json.h>
#include <spa/debug/types.h>
@ -495,7 +496,7 @@ static unsigned int find_channel(const char *name)
int i;
for (i = 0; spa_type_audio_channel[i].name; i++) {
if (strcmp(name, spa_debug_type_short_name(spa_type_audio_channel[i].name)) == 0)
if (spa_streq(name, spa_debug_type_short_name(spa_type_audio_channel[i].name)))
return spa_type_audio_channel[i].type;
}
return SPA_AUDIO_CHANNEL_UNKNOWN;
@ -507,7 +508,7 @@ static int parse_channelmap(const char *channel_map, struct channelmap *map)
char **ch;
for (i = 0; i < (int) SPA_N_ELEMENTS(maps); i++) {
if (strcmp(maps[i].name, channel_map) == 0) {
if (spa_streq(maps[i].name, channel_map)) {
map->n_channels = maps[i].channels;
spa_memcpy(map->channels, &maps[i].values,
map->n_channels * sizeof(unsigned int));
@ -659,7 +660,7 @@ static int json_object_find(const char *obj, const char *key, char *value, size_
return -EINVAL;
while (spa_json_get_string(&it[1], k, sizeof(k)-1) > 0) {
if (strcmp(k, key) == 0) {
if (spa_streq(k, key)) {
if (spa_json_get_string(&it[1], value, len) <= 0)
continue;
return 0;
@ -677,13 +678,13 @@ static int metadata_property(void *object,
struct data *data = object;
if (subject == PW_ID_CORE) {
if (key == NULL || strcmp(key, "default.audio.sink") == 0) {
if (key == NULL || spa_streq(key, "default.audio.sink")) {
if (value == NULL ||
json_object_find(value, "name",
data->default_sink, sizeof(data->default_sink)) < 0)
data->default_sink[0] = '\0';
}
if (key == NULL || strcmp(key, "default.audio.source") == 0) {
if (key == NULL || spa_streq(key, "default.audio.source")) {
if (value == NULL ||
json_object_find(value, "name",
data->default_source, sizeof(data->default_source)) < 0)
@ -717,7 +718,7 @@ static void registry_event_global(void *userdata, uint32_t id,
if (!data->list_targets)
return;
if (strcmp(type, PW_TYPE_INTERFACE_Metadata) == 0) {
if (spa_streq(type, PW_TYPE_INTERFACE_Metadata)) {
if (data->metadata != NULL)
return;
@ -729,7 +730,7 @@ static void registry_event_global(void *userdata, uint32_t id,
data->sync = pw_core_sync(data->core, 0, data->sync);
} else if (strcmp(type, PW_TYPE_INTERFACE_Node) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
name = spa_dict_lookup(props, PW_KEY_NODE_NAME);
desc = spa_dict_lookup(props, PW_KEY_NODE_DESCRIPTION);
media_class = spa_dict_lookup(props, PW_KEY_MEDIA_CLASS);
@ -1714,7 +1715,7 @@ int main(int argc, char *argv[])
target_default = NULL;
spa_list_for_each(target, &data.targets, link) {
if (target_default == NULL ||
strcmp(default_name, target->name) == 0 ||
spa_streq(default_name, target->name) ||
(default_name[0] == '\0' &&
target->prio > target_default->prio))
target_default = target;

View file

@ -36,6 +36,7 @@
#define spa_debug(...) fprintf(stdout,__VA_ARGS__);fputc('\n', stdout)
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/debug/pod.h>
#include <spa/utils/keys.h>
#include <spa/utils/json.h>
@ -1129,57 +1130,57 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er
struct proxy_data *pd;
struct pw_proxy *proxy;
if (strcmp(global->type, PW_TYPE_INTERFACE_Core) == 0) {
if (spa_streq(global->type, PW_TYPE_INTERFACE_Core)) {
events = &core_events;
client_version = PW_VERSION_CORE;
destroy = (pw_destroy_t) pw_core_info_free;
info_func = info_core;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Module) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Module)) {
events = &module_events;
client_version = PW_VERSION_MODULE;
destroy = (pw_destroy_t) pw_module_info_free;
info_func = info_module;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Device) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Device)) {
events = &device_events;
client_version = PW_VERSION_DEVICE;
destroy = (pw_destroy_t) pw_device_info_free;
info_func = info_device;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Node) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Node)) {
events = &node_events;
client_version = PW_VERSION_NODE;
destroy = (pw_destroy_t) pw_node_info_free;
info_func = info_node;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Port) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Port)) {
events = &port_events;
client_version = PW_VERSION_PORT;
destroy = (pw_destroy_t) pw_port_info_free;
info_func = info_port;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Factory) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Factory)) {
events = &factory_events;
client_version = PW_VERSION_FACTORY;
destroy = (pw_destroy_t) pw_factory_info_free;
info_func = info_factory;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Client) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Client)) {
events = &client_events;
client_version = PW_VERSION_CLIENT;
destroy = (pw_destroy_t) pw_client_info_free;
info_func = info_client;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Link) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Link)) {
events = &link_events;
client_version = PW_VERSION_LINK;
destroy = (pw_destroy_t) pw_link_info_free;
info_func = info_link;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Session) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Session)) {
events = &session_events;
client_version = PW_VERSION_SESSION;
destroy = (pw_destroy_t) session_info_free;
info_func = info_session;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_Endpoint) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_Endpoint)) {
events = &endpoint_events;
client_version = PW_VERSION_ENDPOINT;
destroy = (pw_destroy_t) endpoint_info_free;
info_func = info_endpoint;
} else if (strcmp(global->type, PW_TYPE_INTERFACE_EndpointStream) == 0) {
} else if (spa_streq(global->type, PW_TYPE_INTERFACE_EndpointStream)) {
events = &endpoint_stream_events;
client_version = PW_VERSION_ENDPOINT_STREAM;
destroy = (pw_destroy_t) endpoint_stream_info_free;
@ -1255,7 +1256,7 @@ static bool do_info(struct data *data, const char *cmd, char *args, char **error
*error = spa_aprintf("%s <object-id>|all", cmd);
return false;
}
if (strcmp(a[0], "all") == 0) {
if (spa_streq(a[0], "all")) {
pw_map_for_each(&rd->globals, do_global_info_all, NULL);
}
else {
@ -1469,9 +1470,9 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char
static const struct spa_type_info *find_type_info(const struct spa_type_info *info, const char *name)
{
while (info && info->name) {
if (strcmp(info->name, name) == 0)
if (spa_streq(info->name, name))
return info;
if (strcmp(spa_debug_type_short_name(info->name), name) == 0)
if (spa_streq(spa_debug_type_short_name(info->name), name))
return info;
if (info->type != 0 && info->type == (uint32_t)atoi(name))
return info;
@ -1513,16 +1514,16 @@ static bool do_enum_params(struct data *data, const char *cmd, char *args, char
return false;
}
if (strcmp(global->type, PW_TYPE_INTERFACE_Node) == 0)
if (spa_streq(global->type, PW_TYPE_INTERFACE_Node))
pw_node_enum_params((struct pw_node*)global->proxy, 0,
param_id, 0, 0, NULL);
else if (strcmp(global->type, PW_TYPE_INTERFACE_Port) == 0)
else if (spa_streq(global->type, PW_TYPE_INTERFACE_Port))
pw_port_enum_params((struct pw_port*)global->proxy, 0,
param_id, 0, 0, NULL);
else if (strcmp(global->type, PW_TYPE_INTERFACE_Device) == 0)
else if (spa_streq(global->type, PW_TYPE_INTERFACE_Device))
pw_device_enum_params((struct pw_device*)global->proxy, 0,
param_id, 0, 0, NULL);
else if (strcmp(global->type, PW_TYPE_INTERFACE_Endpoint) == 0)
else if (spa_streq(global->type, PW_TYPE_INTERFACE_Endpoint))
pw_endpoint_enum_params((struct pw_endpoint*)global->proxy, 0,
param_id, 0, 0, NULL);
else {
@ -1696,13 +1697,13 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char **
}
spa_debug_pod(0, NULL, pod);
if (strcmp(global->type, PW_TYPE_INTERFACE_Node) == 0)
if (spa_streq(global->type, PW_TYPE_INTERFACE_Node))
pw_node_set_param((struct pw_node*)global->proxy,
param_id, 0, pod);
else if (strcmp(global->type, PW_TYPE_INTERFACE_Device) == 0)
else if (spa_streq(global->type, PW_TYPE_INTERFACE_Device))
pw_device_set_param((struct pw_device*)global->proxy,
param_id, 0, pod);
else if (strcmp(global->type, PW_TYPE_INTERFACE_Endpoint) == 0)
else if (spa_streq(global->type, PW_TYPE_INTERFACE_Endpoint))
pw_endpoint_set_param((struct pw_endpoint*)global->proxy,
param_id, 0, pod);
else {

View file

@ -27,6 +27,7 @@
#include <getopt.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/debug/pod.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
@ -505,7 +506,7 @@ static int draw_graph(struct data *d, const char *path)
/* draw the footer */
dot_str_add(&d->dot_str, "}\n");
if (strcmp(path, "-") == 0) {
if (spa_streq(path, "-")) {
/* wire the dot graph into to stdout */
fputs(d->dot_str, stdout);
} else {
@ -634,7 +635,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
draw_t draw;
struct global *g;
if (strcmp(type, PW_TYPE_INTERFACE_Port) == 0) {
if (spa_streq(type, PW_TYPE_INTERFACE_Port)) {
events = &port_events;
info_destroy = (pw_destroy_t)pw_port_info_free;
info_update = (info_update_t)pw_port_info_update;
@ -642,7 +643,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_PORT;
object_type = INTERFACE_Port;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Node) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
events = &node_events;
info_destroy = (pw_destroy_t)pw_node_info_free;
info_update = (info_update_t)pw_node_info_update;
@ -650,7 +651,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_NODE;
object_type = INTERFACE_Node;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Link) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Link)) {
events = &link_events;
info_destroy = (pw_destroy_t)pw_link_info_free;
info_update = (info_update_t)pw_link_info_update;
@ -658,7 +659,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_LINK;
object_type = INTERFACE_Link;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Client) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Client)) {
events = &client_events;
info_destroy = (pw_destroy_t)pw_client_info_free;
info_update = (info_update_t)pw_client_info_update;
@ -666,7 +667,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_CLIENT;
object_type = INTERFACE_Client;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Device) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Device)) {
events = &device_events;
info_destroy = (pw_destroy_t)pw_device_info_free;
info_update = (info_update_t)pw_device_info_update;
@ -674,7 +675,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_DEVICE;
object_type = INTERFACE_Device;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Factory) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Factory)) {
events = &factory_events;
info_destroy = (pw_destroy_t)pw_factory_info_free;
info_update = (info_update_t)pw_factory_info_update;
@ -682,7 +683,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_FACTORY;
object_type = INTERFACE_Factory;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Module) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Module)) {
events = &module_events;
info_destroy = (pw_destroy_t)pw_module_info_free;
info_update = (info_update_t)pw_module_info_update;
@ -690,7 +691,7 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
client_version = PW_VERSION_MODULE;
object_type = INTERFACE_Module;
}
else if (strcmp(type, PW_TYPE_INTERFACE_Core) == 0) {
else if (spa_streq(type, PW_TYPE_INTERFACE_Core)) {
/* sync to notify we are done with globals */
pw_core_sync(d->core, 0, 0);
return;

View file

@ -31,6 +31,7 @@
#include <math.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/pod/iter.h>
#include <spa/debug/types.h>
#include <spa/utils/json.h>
@ -280,8 +281,8 @@ static void put_value(struct data *d, const char *key, const char *val)
if (val == NULL)
put_literal(d, key, "null");
else if (strcmp(val, "true") == 0 ||
strcmp(val, "false") == 0)
else if (spa_streq(val, "true") ||
spa_streq(val, "false"))
put_literal(d, key, val);
else if ((li = strtol(val, &end, 10)) != LONG_MIN &&
errno != -ERANGE && *end == '\0')
@ -1109,7 +1110,7 @@ static void metadata_dump(struct object *o)
put_int(d, "subject", e->subject);
put_value(d, "key", e->key);
put_value(d, "type", e->type);
if (e->type != NULL && strcmp(e->type, "Spa:String:JSON") == 0)
if (e->type != NULL && spa_streq(e->type, "Spa:String:JSON"))
json_dump(d, "value", e->value);
else
put_value(d, "value", e->value);
@ -1124,7 +1125,7 @@ static struct metadata_entry *metadata_find(struct object *o, uint32_t subject,
struct metadata_entry *e;
spa_list_for_each(e, &o->data_list, link) {
if ((e->subject == subject) &&
(key == NULL || strcmp(e->key, key) == 0))
(key == NULL || spa_streq(e->key, key)))
return e;
}
return NULL;
@ -1208,7 +1209,7 @@ static const struct class *find_class(const char *type, uint32_t version)
{
size_t i;
for (i = 0; i < SPA_N_ELEMENTS(classes); i++) {
if (strcmp(classes[i]->type, type) == 0 &&
if (spa_streq(classes[i]->type, type) &&
classes[i]->version <= version)
return classes[i];
}

View file

@ -29,6 +29,7 @@
#include <regex.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/utils/defs.h>
#include <pipewire/pipewire.h>
@ -245,11 +246,11 @@ static int port_matches(struct data *data, struct object *n, struct object *p, c
uint32_t id = atoi(name);
if (p->id == id)
return 1;
if (strcmp(port_name(buffer, sizeof(buffer), n, p), name) == 0)
if (spa_streq(port_name(buffer, sizeof(buffer), n, p), name))
return 1;
if (strcmp(port_path(buffer, sizeof(buffer), n, p), name) == 0)
if (spa_streq(port_path(buffer, sizeof(buffer), n, p), name))
return 1;
if (strcmp(port_alias(buffer, sizeof(buffer), n, p), name) == 0)
if (spa_streq(port_alias(buffer, sizeof(buffer), n, p), name))
return 1;
return 0;
}
@ -444,22 +445,22 @@ static void registry_event_global(void *data, uint32_t id, uint32_t permissions,
return;
spa_zero(extra);
if (strcmp(type, PW_TYPE_INTERFACE_Node) == 0) {
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
t = OBJECT_NODE;
} else if (strcmp(type, PW_TYPE_INTERFACE_Port) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Port)) {
t = OBJECT_PORT;
if ((str = spa_dict_lookup(props, PW_KEY_PORT_DIRECTION)) == NULL)
return;
if (strcmp(str, "in") == 0)
if (spa_streq(str, "in"))
extra[0] = PW_DIRECTION_INPUT;
else if (strcmp(str, "out") == 0)
else if (spa_streq(str, "out"))
extra[0] = PW_DIRECTION_OUTPUT;
else
return;
if ((str = spa_dict_lookup(props, PW_KEY_NODE_ID)) == NULL)
return;
extra[1] = atoi(str);
} else if (strcmp(type, PW_TYPE_INTERFACE_Link) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Link)) {
t = OBJECT_LINK;
if ((str = spa_dict_lookup(props, PW_KEY_LINK_OUTPUT_PORT)) == NULL)
return;

View file

@ -28,6 +28,7 @@
#include <getopt.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/utils/defs.h>
#include <pipewire/pipewire.h>
@ -67,7 +68,7 @@ static int metadata_property(void *data, uint32_t id,
struct data *d = data;
if ((d->opt_id == SPA_ID_INVALID || d->opt_id == id) &&
(d->opt_key == NULL || strcmp(d->opt_key, key) == 0)) {
(d->opt_key == NULL || spa_streq(d->opt_key, key))) {
if (key == NULL) {
fprintf(stdout, "remove: id:%u all keys\n", id);
} else if (value == NULL) {

View file

@ -27,6 +27,7 @@
#include <getopt.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/debug/pod.h>
#include <spa/debug/format.h>
#include <spa/debug/types.h>
@ -576,34 +577,34 @@ static void registry_event_global(void *data, uint32_t id,
pw_destroy_t destroy;
print_func_t print_func = NULL;
if (strcmp(type, PW_TYPE_INTERFACE_Node) == 0) {
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
events = &node_events;
client_version = PW_VERSION_NODE;
destroy = (pw_destroy_t) pw_node_info_free;
print_func = print_node;
} else if (strcmp(type, PW_TYPE_INTERFACE_Port) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Port)) {
events = &port_events;
client_version = PW_VERSION_PORT;
destroy = (pw_destroy_t) pw_port_info_free;
print_func = print_port;
} else if (strcmp(type, PW_TYPE_INTERFACE_Module) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Module)) {
events = &module_events;
client_version = PW_VERSION_MODULE;
destroy = (pw_destroy_t) pw_module_info_free;
} else if (strcmp(type, PW_TYPE_INTERFACE_Device) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Device)) {
events = &device_events;
client_version = PW_VERSION_DEVICE;
destroy = (pw_destroy_t) pw_device_info_free;
print_func = print_device;
} else if (strcmp(type, PW_TYPE_INTERFACE_Factory) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Factory)) {
events = &factory_events;
client_version = PW_VERSION_FACTORY;
destroy = (pw_destroy_t) pw_factory_info_free;
} else if (strcmp(type, PW_TYPE_INTERFACE_Client) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Client)) {
events = &client_events;
client_version = PW_VERSION_CLIENT;
destroy = (pw_destroy_t) pw_client_info_free;
} else if (strcmp(type, PW_TYPE_INTERFACE_Link) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Link)) {
events = &link_events;
client_version = PW_VERSION_LINK;
destroy = (pw_destroy_t) pw_link_info_free;

View file

@ -27,6 +27,7 @@
#include <getopt.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/pod/parser.h>
#include <spa/debug/pod.h>
@ -143,7 +144,7 @@ static int find_follower(struct data *d, uint32_t id, const char *name)
{
int i;
for (i = 0; i < d->n_followers; i++) {
if (d->followers[i].id == id && strcmp(d->followers[i].name, name) == 0)
if (d->followers[i].id == id && spa_streq(d->followers[i].name, name))
return i;
}
return -1;

View file

@ -29,6 +29,7 @@
#include <ncurses.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/pod/parser.h>
#include <spa/debug/pod.h>
@ -360,7 +361,7 @@ static void registry_event_global(void *data, uint32_t id,
struct data *d = data;
struct pw_proxy *proxy;
if (strcmp(type, PW_TYPE_INTERFACE_Node) == 0) {
if (spa_streq(type, PW_TYPE_INTERFACE_Node)) {
struct node *n;
const char *str;
@ -372,7 +373,7 @@ static void registry_event_global(void *data, uint32_t id,
if ((n = add_node(d, id, str)) == NULL) {
pw_log_warn("can add node %u: %m", id);
}
} else if (strcmp(type, PW_TYPE_INTERFACE_Profiler) == 0) {
} else if (spa_streq(type, PW_TYPE_INTERFACE_Profiler)) {
if (d->profiler != NULL) {
fprintf(stderr, "Ignoring profiler %d: already attached\n", id);
return;