[pulseaudio-discuss] [PATCH 1/4] modules: use pa_streq instead of strcmp

Arti Trivedi Bora tbaarti at gmail.com
Tue Jun 5 12:58:13 PDT 2012


---
 src/modules/alsa/alsa-mixer.c                      |   12 ++++++------
 src/modules/bluetooth/module-bluetooth-proximity.c |    2 +-
 src/modules/dbus/module-dbus-protocol.c            |    6 +++---
 src/modules/gconf/module-gconf.c                   |    4 ++--
 src/modules/jack/module-jackdbus-detect.c          |    2 +-
 src/modules/macosx/module-coreaudio-detect.c       |    2 +-
 src/modules/module-augment-properties.c            |    4 ++--
 src/modules/module-detect.c                        |    2 +-
 src/modules/module-device-manager.c                |   12 ++++++------
 src/modules/module-ladspa-sink.c                   |    6 +++---
 src/modules/module-tunnel.c                        |    4 ++--
 src/modules/module-zeroconf-discover.c             |   10 +++++-----
 src/modules/oss/oss-util.c                         |    2 +-
 src/modules/raop/module-raop-discover.c            |    2 +-
 src/modules/raop/raop_client.c                     |    4 ++--
 src/modules/reserve-monitor.c                      |    4 ++--
 src/modules/reserve.c                              |   10 +++++-----
 src/modules/rtp/rtp.c                              |    8 ++++----
 src/modules/rtp/rtsp_client.c                      |    2 +-
 src/modules/rtp/sap.c                              |    2 +-
 src/modules/x11/module-x11-publish.c               |    4 ++--
 21 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/src/modules/alsa/alsa-mixer.c b/src/modules/alsa/alsa-mixer.c
index 8b54f75..0af968a 100644
--- a/src/modules/alsa/alsa-mixer.c
+++ b/src/modules/alsa/alsa-mixer.c
@@ -2207,22 +2207,22 @@ static int jack_parse_state(
         return -1;
     }
 
-    if (!strcmp(rvalue,"yes"))
+    if (pa_streq(rvalue,"yes"))
 	pa = PA_PORT_AVAILABLE_YES;
-    else if (!strcmp(rvalue,"no"))
+    else if (pa_streq(rvalue,"no"))
 	pa = PA_PORT_AVAILABLE_NO;
-    else if (!strcmp(rvalue,"unknown"))
+    else if (pa_streq(rvalue,"unknown"))
 	pa = PA_PORT_AVAILABLE_UNKNOWN;
     else {
         pa_log("[%s:%u] state must be 'yes','no' or 'unknown' in '%s'", filename, line, section);
         return -1;
     }
 
-    if (!strcmp(lvalue, "state.unplugged"))
+    if (pa_streq(lvalue, "state.unplugged"))
         j->state_unplugged = pa;
     else {
         j->state_plugged = pa;
-        pa_assert(!strcmp(lvalue, "state.plugged"));
+        pa_assert(pa_streq(lvalue, "state.plugged"));
     }
 
     return 0;
@@ -3183,7 +3183,7 @@ static void path_set_condense(pa_alsa_path_set *ps, snd_mixer_t *m) {
                     continue;
 
                 PA_LLIST_FOREACH(jb, p2->jacks) {
-                    if (jb->has_control && !strcmp(jb->alsa_name, ja->alsa_name) &&
+                    if (jb->has_control && pa_streq(jb->alsa_name, ja->alsa_name) &&
                        (ja->state_plugged == jb->state_plugged) &&
                        (ja->state_unplugged == jb->state_unplugged)) {
                         exists = TRUE;
diff --git a/src/modules/bluetooth/module-bluetooth-proximity.c b/src/modules/bluetooth/module-bluetooth-proximity.c
index 3247017..7d69e82 100644
--- a/src/modules/bluetooth/module-bluetooth-proximity.c
+++ b/src/modules/bluetooth/module-bluetooth-proximity.c
@@ -228,7 +228,7 @@ static struct bonding* bonding_new(struct userdata *u, const char *a) {
         goto fail;
     }
 
-    if (strcmp(class, "phone")) {
+    if (!pa_streq(class, "phone")) {
         pa_log_info("Found device '%s' of class '%s', ignoring.", a, class);
         goto fail;
     }
diff --git a/src/modules/dbus/module-dbus-protocol.c b/src/modules/dbus/module-dbus-protocol.c
index c24e1e0..f81c254 100644
--- a/src/modules/dbus/module-dbus-protocol.c
+++ b/src/modules/dbus/module-dbus-protocol.c
@@ -491,13 +491,13 @@ static int get_access_arg(pa_modargs *ma, pa_bool_t *local_access, pa_bool_t *re
     if (!(value = pa_modargs_get_value(ma, "access", NULL)))
         return 0;
 
-    if (!strcmp(value, "local")) {
+    if (pa_streq(value, "local")) {
         *local_access = TRUE;
         *remote_access = FALSE;
-    } else if (!strcmp(value, "remote")) {
+    } else if (pa_streq(value, "remote")) {
         *local_access = FALSE;
         *remote_access = TRUE;
-    } else if (!strcmp(value, "local,remote")) {
+    } else if (pa_streq(value, "local,remote")) {
         *local_access = TRUE;
         *remote_access = TRUE;
     } else
diff --git a/src/modules/gconf/module-gconf.c b/src/modules/gconf/module-gconf.c
index 3bad911..c951d90 100644
--- a/src/modules/gconf/module-gconf.c
+++ b/src/modules/gconf/module-gconf.c
@@ -173,8 +173,8 @@ static void load_module(
 
     if (!is_new) {
         if (m->items[i].index != PA_INVALID_INDEX &&
-            strcmp(m->items[i].name, name) == 0 &&
-            strcmp(m->items[i].args, args) == 0)
+            pa_streq(m->items[i].name, name) &&
+            pa_streq(m->items[i].args, args))
             return;
 
         unload_one_module(u, m, i);
diff --git a/src/modules/jack/module-jackdbus-detect.c b/src/modules/jack/module-jackdbus-detect.c
index 41933c7..10408ea 100644
--- a/src/modules/jack/module-jackdbus-detect.c
+++ b/src/modules/jack/module-jackdbus-detect.c
@@ -186,7 +186,7 @@ static DBusHandlerResult dbus_filter_handler(DBusConnection *c, DBusMessage *s,
                                    DBUS_TYPE_STRING, &new,
                                    DBUS_TYPE_INVALID))
             goto finish;
-        if (strcmp(name, JACK_SERVICE_NAME))
+        if (!pa_streq(name, JACK_SERVICE_NAME))
             goto finish;
 
         ensure_ports_stopped(u);
diff --git a/src/modules/macosx/module-coreaudio-detect.c b/src/modules/macosx/module-coreaudio-detect.c
index f4f2ee2..4652e6f 100644
--- a/src/modules/macosx/module-coreaudio-detect.c
+++ b/src/modules/macosx/module-coreaudio-detect.c
@@ -85,7 +85,7 @@ static int ca_device_added(struct pa_module *m, AudioObjectID id) {
     size = sizeof(tmp);
     err = AudioObjectGetPropertyData(id, &property_address, 0, NULL, &size, tmp);
 
-    if (!err && strcmp(tmp, "pulseaudio.org") == 0)
+    if (!err && pa_streq(tmp, "pulseaudio.org"))
         return 0;
 
     if (u->ioproc_frames)
diff --git a/src/modules/module-augment-properties.c b/src/modules/module-augment-properties.c
index 05f6f0a..f280eae 100644
--- a/src/modules/module-augment-properties.c
+++ b/src/modules/module-augment-properties.c
@@ -183,8 +183,8 @@ static void update_rule(struct rule *r) {
         if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) {
             while ((dir = readdir(desktopfiles_dir))) {
                 if (dir->d_type != DT_DIR
-                    || strcmp(dir->d_name, ".") == 0
-                    || strcmp(dir->d_name, "..") == 0)
+                    || pa_streq(dir->d_name, ".")
+                    || pa_streq(dir->d_name, ".."))
                     continue;
 
                 pa_xfree(fn);
diff --git a/src/modules/module-detect.c b/src/modules/module-detect.c
index bb4994c..d836315 100644
--- a/src/modules/module-detect.c
+++ b/src/modules/module-detect.c
@@ -142,7 +142,7 @@ static int detect_oss(pa_core *c, int just_one) {
         line[strcspn(line, "\r\n")] = 0;
 
         if (!b) {
-            b = strcmp(line, "Audio devices:") == 0 || strcmp(line, "Installed devices:") == 0;
+            b = pa_streq(line, "Audio devices:")  || pa_streq(line, "Installed devices:");
             continue;
         }
 
diff --git a/src/modules/module-device-manager.c b/src/modules/module-device-manager.c
index fe48d4f..25fbffe 100644
--- a/src/modules/module-device-manager.c
+++ b/src/modules/module-device-manager.c
@@ -537,7 +537,7 @@ static uint32_t get_role_index(const char* role) {
     pa_assert(role);
 
     for (uint32_t i = ROLE_NONE; i < NUM_ROLES; ++i)
-        if (strcmp(role, role_names[i]) == 0)
+        if (pa_streq(role, role_names[i]) == 0)
             return i;
 
     return PA_INVALID_INDEX;
@@ -551,7 +551,7 @@ static void update_highest_priority_device_indexes(struct userdata *u, const cha
     pa_assert(u);
     pa_assert(prefix);
 
-    sink_mode = (strcmp(prefix, "sink:") == 0);
+    sink_mode = (pa_streq(prefix, "sink:"));
 
     if (sink_mode)
         indexes = &u->preferred_sinks;
@@ -592,7 +592,7 @@ static void update_highest_priority_device_indexes(struct userdata *u, const cha
                             PA_IDXSET_FOREACH(sink, u->core->sinks, idx) {
                                 if ((pa_sink*) ignore_device == sink)
                                     continue;
-                                if (strcmp(sink->name, device_name) == 0) {
+                                if (pa_streq(sink->name, device_name)) {
                                     found = TRUE;
                                     idx = sink->index; /* Is this needed? */
                                     break;
@@ -604,7 +604,7 @@ static void update_highest_priority_device_indexes(struct userdata *u, const cha
                             PA_IDXSET_FOREACH(source, u->core->sources, idx) {
                                 if ((pa_source*) ignore_device == source)
                                     continue;
-                                if (strcmp(source->name, device_name) == 0) {
+                                if (pa_streq(source->name, device_name)) {
                                     found = TRUE;
                                     idx = source->index; /* Is this needed? */
                                     break;
@@ -1159,7 +1159,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
             if ((device_name = get_name(name, "sink:"))) {
                 pa_sink* s;
                 PA_IDXSET_FOREACH(s, u->core->sinks, idx) {
-                    if (strcmp(s->name, device_name) == 0) {
+                    if (pa_streq(s->name, device_name)) {
                         found_index = s->index;
                         break;
                     }
@@ -1168,7 +1168,7 @@ static int extension_cb(pa_native_protocol *p, pa_module *m, pa_native_connectio
             } else if ((device_name = get_name(name, "source:"))) {
                 pa_source* s;
                 PA_IDXSET_FOREACH(s, u->core->sources, idx) {
-                    if (strcmp(s->name, device_name) == 0) {
+                    if (pa_streq(s->name, device_name)) {
                         found_index = s->index;
                         break;
                     }
diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c
index be05715..500f8f6 100644
--- a/src/modules/module-ladspa-sink.c
+++ b/src/modules/module-ladspa-sink.c
@@ -562,7 +562,7 @@ int pa__init(pa_module*m) {
             goto fail;
         }
 
-        if (strcmp(d->Label, label) == 0)
+        if (pa_streq(d->Label, label))
             break;
     }
 
@@ -627,7 +627,7 @@ int pa__init(pa_module*m) {
 
 
             for (p = 0; p < d->PortCount; p++) {
-                if (strcmp(d->PortNames[p], pname) == 0) {
+                if (pa_streq(d->PortNames[p], pname)) {
                     if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p]) && LADSPA_IS_PORT_INPUT(d->PortDescriptors[p])) {
                         input_ladspaport[c] = p;
                     } else {
@@ -653,7 +653,7 @@ int pa__init(pa_module*m) {
                 goto fail;
             }
             for (p = 0; p < d->PortCount; p++) {
-                if (strcmp(d->PortNames[p], pname) == 0) {
+                if (pa_streq(d->PortNames[p], pname)) {
                     if (LADSPA_IS_PORT_AUDIO(d->PortDescriptors[p]) && LADSPA_IS_PORT_OUTPUT(d->PortDescriptors[p])) {
                         output_ladspaport[c] = p;
                     } else {
diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c
index 554eecf..e336d15 100644
--- a/src/modules/module-tunnel.c
+++ b/src/modules/module-tunnel.c
@@ -1136,7 +1136,7 @@ static void sink_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa_t
 
     pa_proplist_free(pl);
 
-    if (!u->sink_name || strcmp(name, u->sink_name))
+    if (!u->sink_name || !pa_streq(name, u->sink_name))
         return;
 
     pa_xfree(u->device_description);
@@ -1347,7 +1347,7 @@ static void source_info_cb(pa_pdispatch *pd, uint32_t command,  uint32_t tag, pa
 
     pa_proplist_free(pl);
 
-    if (!u->source_name || strcmp(name, u->source_name))
+    if (!u->source_name || !pa_streq(name, u->source_name))
         return;
 
     pa_xfree(u->device_description);
diff --git a/src/modules/module-zeroconf-discover.c b/src/modules/module-zeroconf-discover.c
index cd076aa..b17f6e5 100644
--- a/src/modules/module-zeroconf-discover.c
+++ b/src/modules/module-zeroconf-discover.c
@@ -163,17 +163,17 @@ static void resolver_cb(
             char *key, *value;
             pa_assert_se(avahi_string_list_get_pair(l, &key, &value, NULL) == 0);
 
-            if (strcmp(key, "device") == 0) {
+            if (pa_streq(key, "device")) {
                 pa_xfree(device);
                 device = value;
                 value = NULL;
-            } else if (strcmp(key, "rate") == 0)
+            } else if (pa_streq(key, "rate"))
                 ss.rate = (uint32_t) atoi(value);
-            else if (strcmp(key, "channels") == 0)
+            else if (pa_streq(key, "channels"))
                 ss.channels = (uint8_t) atoi(value);
-            else if (strcmp(key, "format") == 0)
+            else if (pa_streq(key, "format"))
                 ss.format = pa_parse_sample_format(value);
-            else if (strcmp(key, "channel_map") == 0) {
+            else if (pa_streq(key, "channel_map")) {
                 pa_channel_map_parse(&cm, value);
                 channel_map_set = TRUE;
             }
diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c
index 9412a87..3c7f0eb 100644
--- a/src/modules/oss/oss-util.c
+++ b/src/modules/oss/oss-util.c
@@ -359,7 +359,7 @@ int pa_oss_get_hw_description(const char *dev, char *name, size_t l) {
         line[strcspn(line, "\r\n")] = 0;
 
         if (!b) {
-            b = strcmp(line, "Audio devices:") == 0;
+            b = pa_streq(line, "Audio devices:");
             continue;
         }
 
diff --git a/src/modules/raop/module-raop-discover.c b/src/modules/raop/module-raop-discover.c
index 4ebe5fc..7499f63 100644
--- a/src/modules/raop/module-raop-discover.c
+++ b/src/modules/raop/module-raop-discover.c
@@ -166,7 +166,7 @@ static void resolver_cb(
             pa_assert_se(avahi_string_list_get_pair(l, &key, &value, NULL) == 0);
 
             pa_log_debug("Found key: '%s' with value: '%s'", key, value);
-            if (strcmp(key, "device") == 0) {
+            if (pa_streq(key, "device")) {
                 pa_xfree(device);
                 device = value;
                 value = NULL;
diff --git a/src/modules/raop/raop_client.c b/src/modules/raop/raop_client.c
index bbbce5b..b11cafb 100644
--- a/src/modules/raop/raop_client.c
+++ b/src/modules/raop/raop_client.c
@@ -303,11 +303,11 @@ static void rtsp_cb(pa_rtsp_client *rtsp, pa_rtsp_state state, pa_headerlist* he
                 while ((token = pa_split(aj, delimiters, &token_state))) {
                     if ((pc = strstr(token, "="))) {
                       *pc = 0;
-                      if (!strcmp(token, "type") && !strcmp(pc+1, "digital")) {
+                      if (pa_streq(token, "type") && pa_streq(pc+1, "digital")) {
                           c->jack_type = JACK_TYPE_DIGITAL;
                       }
                     } else {
-                        if (!strcmp(token,"connected"))
+                        if (pa_streq(token, "connected"))
                             c->jack_status = JACK_STATUS_CONNECTED;
                     }
                     pa_xfree(token);
diff --git a/src/modules/reserve-monitor.c b/src/modules/reserve-monitor.c
index ab453e6..2de9605 100644
--- a/src/modules/reserve-monitor.c
+++ b/src/modules/reserve-monitor.c
@@ -84,7 +84,7 @@ static DBusHandlerResult filter_handler(
 			    DBUS_TYPE_INVALID))
 			goto invalid;
 
-		if (strcmp(name, m->service_name) == 0) {
+		if (pa_streq(name, m->service_name)) {
 			m->busy = !!(new && *new);
 
 			/* If we ourselves own the device, then don't consider this 'busy' */
@@ -92,7 +92,7 @@ static DBusHandlerResult filter_handler(
 				const char *un;
 
 				if ((un = dbus_bus_get_unique_name(c)))
-					if (strcmp(new, un) == 0)
+					if (pa_streq(new, un))
 						m->busy = FALSE;
 			}
 
diff --git a/src/modules/reserve.c b/src/modules/reserve.c
index b4c168c..2e3bf23 100644
--- a/src/modules/reserve.c
+++ b/src/modules/reserve.c
@@ -183,10 +183,10 @@ static DBusHandlerResult object_handler(
 			    DBUS_TYPE_INVALID))
 			goto invalid;
 
-		if (strcmp(interface, "org.freedesktop.ReserveDevice1") == 0) {
+		if (pa_streq(interface, "org.freedesktop.ReserveDevice1")) {
 			const char *empty = "";
 
-			if (strcmp(property, "ApplicationName") == 0 && d->application_name) {
+			if (pa_streq(property, "ApplicationName") && d->application_name) {
 				if (!(reply = dbus_message_new_method_return(m)))
 					goto oom;
 
@@ -196,7 +196,7 @@ static DBusHandlerResult object_handler(
 					    d->application_name ? (const char**) &d->application_name : &empty))
 					goto oom;
 
-			} else if (strcmp(property, "ApplicationDeviceName") == 0) {
+			} else if (pa_streq(property, "ApplicationDeviceName")) {
 				if (!(reply = dbus_message_new_method_return(m)))
 					goto oom;
 
@@ -206,7 +206,7 @@ static DBusHandlerResult object_handler(
 					    d->application_device_name ? (const char**) &d->application_device_name : &empty))
 					goto oom;
 
-			} else if (strcmp(property, "Priority") == 0) {
+			} else if (pa_streq(property, "Priority")) {
 				if (!(reply = dbus_message_new_method_return(m)))
 					goto oom;
 
@@ -309,7 +309,7 @@ static DBusHandlerResult filter_handler(
 			    DBUS_TYPE_INVALID))
 			goto invalid;
 
-		if (strcmp(name, d->service_name) == 0 && d->owning) {
+		if (pa_streq(name, d->service_name) && d->owning) {
 			d->owning = 0;
 
 			if (!d->gave_up)  {
diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c
index 178717c..04e756d 100644
--- a/src/modules/rtp/rtp.c
+++ b/src/modules/rtp/rtp.c
@@ -398,13 +398,13 @@ const char* pa_rtp_format_to_string(pa_sample_format_t f) {
 pa_sample_format_t pa_rtp_string_to_format(const char *s) {
     pa_assert(s);
 
-    if (!(strcmp(s, "L16")))
+    if (pa_streq(s, "L16"))
         return PA_SAMPLE_S16BE;
-    else if (!strcmp(s, "L8"))
+    else if (pa_streq(s, "L8"))
         return PA_SAMPLE_U8;
-    else if (!strcmp(s, "PCMA"))
+    else if (pa_streq(s, "PCMA"))
         return PA_SAMPLE_ALAW;
-    else if (!strcmp(s, "PCMU"))
+    else if (pa_streq(s, "PCMU"))
         return PA_SAMPLE_ULAW;
     else
         return PA_SAMPLE_INVALID;
diff --git a/src/modules/rtp/rtsp_client.c b/src/modules/rtp/rtsp_client.c
index 71692c2..665b2ea 100644
--- a/src/modules/rtp/rtsp_client.c
+++ b/src/modules/rtp/rtsp_client.c
@@ -187,7 +187,7 @@ static void line_callback(pa_ioline *line, const char *s, void *userdata) {
         *s2p = '\0';
         s2p -= 1;
     }
-    if (c->waiting && 0 == strcmp("RTSP/1.0 200 OK", s2)) {
+    if (c->waiting && pa_streq("RTSP/1.0 200 OK", s2)) {
         c->waiting = 0;
         if (c->response_headers)
             pa_headerlist_free(c->response_headers);
diff --git a/src/modules/rtp/sap.c b/src/modules/rtp/sap.c
index 4d8bf66..f02d53f 100644
--- a/src/modules/rtp/sap.c
+++ b/src/modules/rtp/sap.c
@@ -212,7 +212,7 @@ int pa_sap_recv(pa_sap_context *c, pa_bool_t *goodbye) {
     e = buf + k;
     size -= (int) k;
 
-    if ((unsigned) size >= sizeof(MIME_TYPE) && !strcmp(e, MIME_TYPE)) {
+    if ((unsigned) size >= sizeof(MIME_TYPE) && pa_streq(e, MIME_TYPE)) {
         e += sizeof(MIME_TYPE);
         size -= (int) sizeof(MIME_TYPE);
     } else if ((unsigned) size < sizeof(PA_SDP_HEADER)-1 || strncmp(e, PA_SDP_HEADER, sizeof(PA_SDP_HEADER)-1)) {
diff --git a/src/modules/x11/module-x11-publish.c b/src/modules/x11/module-x11-publish.c
index 643b735..16ea977 100644
--- a/src/modules/x11/module-x11-publish.c
+++ b/src/modules/x11/module-x11-publish.c
@@ -103,7 +103,7 @@ static pa_hook_result_t servers_changed_cb(void *hook_data, void *call_data, voi
     pa_assert(u);
 
     screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper));
-    if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) {
+    if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || !pa_streq(t, u->id)) {
         pa_log_warn("PulseAudio information vanished from X11!");
         return PA_HOOK_OK;
     }
@@ -217,7 +217,7 @@ void pa__done(pa_module*m) {
         int screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper));
 
         /* Yes, here is a race condition */
-        if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id))
+        if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || !pa_streq(t, u->id))
             pa_log_warn("PulseAudio information vanished from X11!");
         else {
             pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID");
-- 
1.7.4.1



More information about the pulseaudio-discuss mailing list