Skip to content

Commit be323fc

Browse files
committed
replace strcmp() == 0 with streq()
1 parent 9ec1cdf commit be323fc

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

src/flutter-pi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,7 +1897,7 @@ static bool parse_cmd_args(int argc, char **argv, struct cmd_args *result_out) {
18971897

18981898
case 'p':
18991899
for (unsigned i = 0; i < n_pixfmt_infos; i++) {
1900-
if (strcmp(optarg, pixfmt_infos[i].arg_name) == 0) {
1900+
if (streq(optarg, pixfmt_infos[i].arg_name)) {
19011901
result_out->has_pixel_format = true;
19021902
result_out->pixel_format = pixfmt_infos[i].format;
19031903
goto valid_format;

src/locales.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ struct locales *locales_new(void) {
322322
i++;
323323
}
324324

325-
if (strcmp(fl_locales[0]->language_code, "C") == 0) {
325+
if (streq(fl_locales[0]->language_code, "C")) {
326326
LOG_LOCALES_ERROR("Warning: The system has no configured locale. The default \"C\" locale may or may not be supported by the app.\n"
327327
);
328328
}

src/modesetting.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,12 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
648648
goto fail_maybe_free_supported_formats;
649649
}
650650

651-
if (strcmp(info->name, "type") == 0) {
651+
if (streq(info->name, "type")) {
652652
assert(has_type == false);
653653
has_type = true;
654654

655655
type = props->prop_values[j];
656-
} else if (strcmp(info->name, "rotation") == 0) {
656+
} else if (streq(info->name, "rotation")) {
657657
assert(has_rotation == false);
658658
has_rotation = true;
659659

@@ -672,7 +672,7 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
672672
}
673673

674674
committed_rotation.u64 = props->prop_values[j];
675-
} else if (strcmp(info->name, "zpos") == 0) {
675+
} else if (streq(info->name, "zpos")) {
676676
assert(has_zpos == false);
677677
has_zpos = true;
678678

@@ -706,23 +706,23 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
706706
min_zpos = max_zpos = hardcoded_zpos;
707707
}
708708
}
709-
} else if (strcmp(info->name, "SRC_X") == 0) {
709+
} else if (streq(info->name, "SRC_X")) {
710710
comitted_src_x = props->prop_values[j];
711-
} else if (strcmp(info->name, "SRC_Y") == 0) {
711+
} else if (streq(info->name, "SRC_Y")) {
712712
comitted_src_y = props->prop_values[j];
713-
} else if (strcmp(info->name, "SRC_W") == 0) {
713+
} else if (streq(info->name, "SRC_W")) {
714714
comitted_src_w = props->prop_values[j];
715-
} else if (strcmp(info->name, "SRC_H") == 0) {
715+
} else if (streq(info->name, "SRC_H")) {
716716
comitted_src_h = props->prop_values[j];
717-
} else if (strcmp(info->name, "CRTC_X") == 0) {
717+
} else if (streq(info->name, "CRTC_X")) {
718718
comitted_crtc_x = props->prop_values[j];
719-
} else if (strcmp(info->name, "CRTC_Y") == 0) {
719+
} else if (streq(info->name, "CRTC_Y")) {
720720
comitted_crtc_y = props->prop_values[j];
721-
} else if (strcmp(info->name, "CRTC_W") == 0) {
721+
} else if (streq(info->name, "CRTC_W")) {
722722
comitted_crtc_w = props->prop_values[j];
723-
} else if (strcmp(info->name, "CRTC_H") == 0) {
723+
} else if (streq(info->name, "CRTC_H")) {
724724
comitted_crtc_h = props->prop_values[j];
725-
} else if (strcmp(info->name, "IN_FORMATS") == 0) {
725+
} else if (streq(info->name, "IN_FORMATS")) {
726726
drmModePropertyBlobRes *blob;
727727

728728
blob = drmModeGetPropertyBlob(drm_fd, props->prop_values[j]);
@@ -768,26 +768,26 @@ static int fetch_plane(int drm_fd, uint32_t plane_id, struct drm_plane *plane_ou
768768
}
769769

770770
drmModeFreePropertyBlob(blob);
771-
} else if (strcmp(info->name, "alpha") == 0) {
771+
} else if (streq(info->name, "alpha")) {
772772
has_alpha = true;
773773
assert(info->flags == DRM_MODE_PROP_RANGE);
774774
assert(info->values[0] == 0);
775775
assert(info->values[1] == 0xFFFF);
776776
assert(props->prop_values[j] <= 0xFFFF);
777777

778778
committed_alpha = (uint16_t) props->prop_values[j];
779-
} else if (strcmp(info->name, "pixel blend mode") == 0) {
779+
} else if (streq(info->name, "pixel blend mode")) {
780780
has_blend_mode = true;
781781
assert(info->flags == DRM_MODE_PROP_ENUM);
782782

783783
for (int i = 0; i < info->count_enums; i++) {
784-
if (strcmp(info->enums[i].name, "None") == 0) {
784+
if (streq(info->enums[i].name, "None")) {
785785
ASSERT_EQUALS(info->enums[i].value, kNone_DrmBlendMode);
786786
supported_blend_modes[kNone_DrmBlendMode] = true;
787-
} else if (strcmp(info->enums[i].name, "Pre-multiplied") == 0) {
787+
} else if (streq(info->enums[i].name, "Pre-multiplied")) {
788788
ASSERT_EQUALS(info->enums[i].value, kPremultiplied_DrmBlendMode);
789789
supported_blend_modes[kPremultiplied_DrmBlendMode] = true;
790-
} else if (strcmp(info->enums[i].name, "Coverage") == 0) {
790+
} else if (streq(info->enums[i].name, "Coverage")) {
791791
ASSERT_EQUALS(info->enums[i].value, kCoverage_DrmBlendMode);
792792
supported_blend_modes[kCoverage_DrmBlendMode] = true;
793793
} else {

src/platformchannel.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,9 @@ int platch_decode(const uint8_t *buffer, size_t size, enum platch_codec codec, s
884884
return EBADMSG;
885885

886886
for (int i = 0; i < root_jsvalue.size; i++) {
887-
if ((strcmp(root_jsvalue.keys[i], "method") == 0) && (root_jsvalue.values[i].type == kJsonString)) {
887+
if ((streq(root_jsvalue.keys[i], "method")) && (root_jsvalue.values[i].type == kJsonString)) {
888888
object_out->method = root_jsvalue.values[i].string_value;
889-
} else if (strcmp(root_jsvalue.keys[i], "args") == 0) {
889+
} else if (streq(root_jsvalue.keys[i], "args")) {
890890
object_out->json_arg = root_jsvalue.values[i];
891891
} else
892892
return EBADMSG;
@@ -1487,7 +1487,7 @@ bool jsvalue_equals(struct json_value *a, struct json_value *b) {
14871487
case kJsonTrue:
14881488
case kJsonFalse: return true;
14891489
case kJsonNumber: return a->number_value == b->number_value;
1490-
case kJsonString: return strcmp(a->string_value, b->string_value) == 0;
1490+
case kJsonString: return streq(a->string_value, b->string_value);
14911491
case kJsonArray:
14921492
if (a->size != b->size)
14931493
return false;
@@ -1514,7 +1514,7 @@ bool jsvalue_equals(struct json_value *a, struct json_value *b) {
15141514
while (j < a->size) {
15151515
while (_keyInBAlsoInA[j] && (j < a->size))
15161516
j++; // skip all keys with _keyInBAlsoInA set to true.
1517-
if (strcmp(key, b->keys[j]) != 0)
1517+
if (!streq(key, b->keys[j]))
15181518
j++; // if b->keys[j] is not equal to "key", continue searching
15191519
else {
15201520
_keyInBAlsoInA[j] = true;
@@ -1541,7 +1541,7 @@ bool jsvalue_equals(struct json_value *a, struct json_value *b) {
15411541
struct json_value *jsobject_get(struct json_value *object, char *key) {
15421542
int i;
15431543
for (i = 0; i < object->size; i++)
1544-
if (strcmp(object->keys[i], key) == 0)
1544+
if (streq(object->keys[i], key))
15451545
break;
15461546

15471547
if (i != object->size)
@@ -1570,7 +1570,7 @@ bool stdvalue_equals(struct std_value *a, struct std_value *b) {
15701570
case kStdString:
15711571
ASSERT_NOT_NULL(a->string_value);
15721572
ASSERT_NOT_NULL(b->string_value);
1573-
return strcmp(a->string_value, b->string_value) == 0;
1573+
return streq(a->string_value, b->string_value);
15741574
case kStdFloat64: return a->float64_value == b->float64_value;
15751575
case kStdUInt8Array:
15761576
if (a->size != b->size)

src/plugins/audioplayers/player.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void audio_player_on_media_error(struct audio_player *self, GError *error, gchar
233233

234234
void audio_player_on_media_state_change(struct audio_player *self, GstObject *src, GstState *old_state, GstState *new_state) {
235235
(void) old_state;
236-
if (strcmp(GST_OBJECT_NAME(src), "playbin") == 0) {
236+
if (streq(GST_OBJECT_NAME(src), "playbin")) {
237237
if (*new_state >= GST_STATE_READY) {
238238
if (!self->is_initialized) {
239239
self->is_initialized = true;
@@ -431,7 +431,7 @@ void audio_player_set_position(struct audio_player *self, int64_t position) {
431431

432432
void audio_player_set_source_url(struct audio_player *self, char *url) {
433433
ASSERT_NOT_NULL(url);
434-
if (self->url == NULL || strcmp(self->url, url)) {
434+
if (self->url == NULL || !streq(self->url, url)) {
435435
if (self->url != NULL) {
436436
free(self->url);
437437
self->url = NULL;
@@ -449,5 +449,5 @@ void audio_player_set_source_url(struct audio_player *self, char *url) {
449449
}
450450

451451
bool audio_player_is_id(struct audio_player *self, char *player_id) {
452-
return strcmp(self->player_id, player_id) == 0;
452+
return streq(self->player_id, player_id);
453453
}

src/plugins/audioplayers/plugin.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ static int on_local_method_call(char *channel, struct platch_obj *object, Flutte
5656
return platch_respond_native_error_std(responsehandle, ENOMEM);
5757
}
5858

59-
if (strcmp(method, "pause") == 0) {
59+
if (streq(method, "pause")) {
6060
audio_player_pause(player);
61-
} else if (strcmp(method, "resume") == 0) {
61+
} else if (streq(method, "resume")) {
6262
audio_player_resume(player);
63-
} else if (strcmp(method, "stop") == 0) {
63+
} else if (streq(method, "stop")) {
6464
audio_player_pause(player);
6565
audio_player_set_position(player, 0);
66-
} else if (strcmp(method, "release") == 0) {
66+
} else if (streq(method, "release")) {
6767
audio_player_pause(player);
6868
audio_player_set_position(player, 0);
69-
} else if (strcmp(method, "seek") == 0) {
69+
} else if (streq(method, "seek")) {
7070
tmp = stdmap_get_str(args, "position");
7171
if (tmp == NULL || !STDVALUE_IS_INT(*tmp)) {
7272
return platch_respond_illegal_arg_std(responsehandle, "Expected `arg['position']` to be an int.");
7373
}
7474

7575
int64_t position = STDVALUE_AS_INT(*tmp);
7676
audio_player_set_position(player, position);
77-
} else if (strcmp(method, "setSourceUrl") == 0) {
77+
} else if (streq(method, "setSourceUrl")) {
7878
tmp = stdmap_get_str(args, "url");
7979
if (tmp == NULL || !STDVALUE_IS_STRING(*tmp)) {
8080
return platch_respond_illegal_arg_std(responsehandle, "Expected `arg['url']` to be a string.");
@@ -97,25 +97,25 @@ static int on_local_method_call(char *channel, struct platch_obj *object, Flutte
9797
}
9898

9999
audio_player_set_source_url(player, url);
100-
} else if (strcmp(method, "getDuration") == 0) {
100+
} else if (streq(method, "getDuration")) {
101101
result = audio_player_get_duration(player);
102-
} else if (strcmp(method, "setVolume") == 0) {
102+
} else if (streq(method, "setVolume")) {
103103
tmp = stdmap_get_str(args, "volume");
104104
if (tmp != NULL && STDVALUE_IS_FLOAT(*tmp)) {
105105
audio_player_set_volume(player, STDVALUE_AS_FLOAT(*tmp));
106106
} else {
107107
return platch_respond_illegal_arg_std(responsehandle, "Expected `arg['volume']` to be a float.");
108108
}
109-
} else if (strcmp(method, "getCurrentPosition") == 0) {
109+
} else if (streq(method, "getCurrentPosition")) {
110110
result = audio_player_get_position(player);
111-
} else if (strcmp(method, "setPlaybackRate") == 0) {
111+
} else if (streq(method, "setPlaybackRate")) {
112112
tmp = stdmap_get_str(args, "playback_rate");
113113
if (tmp != NULL && STDVALUE_IS_FLOAT(*tmp)) {
114114
audio_player_set_playback_rate(player, STDVALUE_AS_FLOAT(*tmp));
115115
} else {
116116
return platch_respond_illegal_arg_std(responsehandle, "Expected `arg['playback_rate']` to be a float.");
117117
}
118-
} else if (strcmp(method, "setReleaseMode") == 0) {
118+
} else if (streq(method, "setReleaseMode")) {
119119
tmp = stdmap_get_str(args, "release_mode");
120120
if (tmp != NULL && STDVALUE_IS_STRING(*tmp)) {
121121
char *release_mode = STDVALUE_AS_STRING(*tmp);
@@ -124,7 +124,7 @@ static int on_local_method_call(char *channel, struct platch_obj *object, Flutte
124124
} else {
125125
return platch_respond_illegal_arg_std(responsehandle, "Expected `arg['release_mode']` to be a string.");
126126
}
127-
} else if (strcmp(method, "setPlayerMode") == 0) {
127+
} else if (streq(method, "setPlayerMode")) {
128128
// TODO check support for low latency mode:
129129
// https://gstreamer.freedesktop.org/documentation/additional/design/latency.html?gi-language=c
130130
} else {

src/plugins/gstreamer_video_player/plugin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static struct gstplayer *get_player_by_evch(const char *const event_channel_name
7777
cpset_lock(&plugin.players);
7878
for_each_pointer_in_cpset(&plugin.players, player) {
7979
meta = gstplayer_get_userdata_locked(player);
80-
if (strcmp(meta->event_channel_name, event_channel_name) == 0) {
80+
if (streq(meta->event_channel_name, event_channel_name)) {
8181
cpset_unlock(&plugin.players);
8282
return player;
8383
}

src/plugins/services.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <string.h>
66

77
#define ORIENTATION_FROM_STRING(str) \
8-
(strcmp(str, "DeviceOrientation.portraitUp") == 0 ? kPortraitUp : \
9-
strcmp(str, "DeviceOrientation.landscapeLeft") == 0 ? kLandscapeLeft : \
10-
strcmp(str, "DeviceOrientation.portraitDown") == 0 ? kPortraitDown : \
11-
strcmp(str, "DeviceOrientation.landscapeRight") == 0 ? kLandscapeRight : \
8+
(streq(str, "DeviceOrientation.portraitUp") ? kPortraitUp : \
9+
streq(str, "DeviceOrientation.landscapeLeft") ? kLandscapeLeft : \
10+
streq(str, "DeviceOrientation.portraitDown") ? kPortraitDown : \
11+
streq(str, "DeviceOrientation.landscapeRight") ? kLandscapeRight : \
1212
-1)
1313

1414
#define FLUTTER_NAVIGATION_CHANNEL "flutter/navigation"

src/vk_renderer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FILE_DESCR("vulkan renderer")
2020

2121
UNUSED static VkLayerProperties *get_layer_props(int n_layers, VkLayerProperties *layers, const char *layer_name) {
2222
for (int i = 0; i < n_layers; i++) {
23-
if (strcmp(layers[i].layerName, layer_name) == 0) {
23+
if (streq(layers[i].layerName, layer_name)) {
2424
return layers + i;
2525
}
2626
}
@@ -33,7 +33,7 @@ UNUSED static bool supports_layer(int n_layers, VkLayerProperties *layers, const
3333

3434
static VkExtensionProperties *get_extension_props(int n_extensions, VkExtensionProperties *extensions, const char *extension_name) {
3535
for (int i = 0; i < n_extensions; i++) {
36-
if (strcmp(extensions[i].extensionName, extension_name) == 0) {
36+
if (streq(extensions[i].extensionName, extension_name)) {
3737
return extensions + i;
3838
}
3939
}
@@ -122,7 +122,7 @@ static int score_physical_device(VkPhysicalDevice device, const char **required_
122122

123123
for (const char **cursor = required_device_extensions; *cursor != NULL; cursor++) {
124124
for (unsigned i = 0; i < n_available_extensions; i++) {
125-
if (strcmp(available_extensions[i].extensionName, *cursor) == 0) {
125+
if (streq(available_extensions[i].extensionName, *cursor)) {
126126
goto found;
127127
}
128128
}

src/window.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,12 +739,12 @@ static int select_mode(
739739
return ENOMEM;
740740
}
741741

742-
if (strcmp(modeline, desired_videomode) == 0) {
742+
if (streq(modeline, desired_videomode)) {
743743
// Probably a bit superfluos, but the refresh rate can still vary in the decimal places.
744744
if (mode == NULL || (mode_get_vrefresh(mode_iter) > mode_get_vrefresh(mode))) {
745745
mode = mode_iter;
746746
}
747-
} else if (strcmp(modeline_nohz, desired_videomode) == 0) {
747+
} else if (streq(modeline_nohz, desired_videomode)) {
748748
if (mode == NULL || (mode_get_vrefresh(mode_iter) > mode_get_vrefresh(mode))) {
749749
mode = mode_iter;
750750
}

0 commit comments

Comments
 (0)