Global: refactor strncmp to ffStrStartsWith

This commit is contained in:
李通洲
2023-06-19 15:38:37 +08:00
parent 805fb13b13
commit da76c6efbe
9 changed files with 20 additions and 16 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
#include "displayserver_linux.h"
#include "util/stringUtils.h"
#include <stdlib.h>
#include <string.h>
@@ -105,9 +106,9 @@ static void waylandOutputGeometryListener(void *data,
static void waylandOutputNameListener(void *data, FF_MAYBE_UNUSED struct wl_output *output, const char *name)
{
WaylandDisplay* display = data;
if(strncmp(name, "eDP-", strlen("eDP-")) == 0)
if(ffStrStartsWith(name, "eDP-"))
display->type = FF_DISPLAY_TYPE_BUILTIN;
else if(strncmp(name, "HDMI-", strlen("HDMI-")) == 0 || strncmp(name, "DP-", strlen("DP-")) == 0)
else if(ffStrStartsWith(name, "HDMI-") || ffStrStartsWith(name, "DP-"))
display->type = FF_DISPLAY_TYPE_EXTERNAL;
}
#endif
+2 -1
View File
@@ -1,5 +1,6 @@
#include "gamepad.h"
#include "common/io/io.h"
#include "util/stringUtils.h"
#include <dirent.h>
#include <ctype.h>
@@ -16,7 +17,7 @@ const char* ffDetectGamepad(FF_MAYBE_UNUSED const FFinstance* instance, FFlist*
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
{
if(strncmp(entry->d_name, "js", 2) != 0)
if(!ffStrStartsWith(entry->d_name, "js"))
continue;
if(!isdigit(entry->d_name[2]))
continue;
+1 -1
View File
@@ -139,7 +139,7 @@ static void getBestBus(FFDBusData* data, FFMediaResult* result)
const char* busName;
data->lib->ffdbus_message_iter_get_basic(&arrayIterator, &busName);
if(strncmp(busName, FF_DBUS_MPRIS_PREFIX, sizeof(FF_DBUS_MPRIS_PREFIX) - 1) != 0)
if(!ffStrStartsWith(busName, FF_DBUS_MPRIS_PREFIX))
FF_DBUS_ITER_CONTINUE(data, &arrayIterator)
if(getBusProperties(data, busName, result))
+2 -3
View File
@@ -46,9 +46,8 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
return "clGetDeviceInfo returned NULL or empty string";
const char* versionPretty = version;
const char* prefix = "OpenCL ";
if(strncasecmp(version, prefix, sizeof(prefix) - 1) == 0)
versionPretty = version + sizeof(prefix) - 1;
if(ffStrStartsWithIgnCase(version, "OpenCL "))
versionPretty = version + strlen("OpenCL ");
ffStrbufSetS(&result->version, versionPretty);
ffStrbufEnsureFree(&result->device, 128);
+2 -3
View File
@@ -78,12 +78,11 @@ static void parseOSXSoftwareLicense(FFOSResult* os)
char* line = NULL;
size_t len = 0;
const char* searchStr = "\\f0\\b SOFTWARE LICENSE AGREEMENT FOR macOS ";
const size_t searchLen = strlen(searchStr);
while(getline(&line, &len, rtf) != EOF)
{
if (strncmp(line, searchStr, searchLen) == 0)
if (ffStrStartsWith(line, searchStr))
{
ffStrbufAppendS(&os->codename, line + searchLen);
ffStrbufAppendS(&os->codename, line + strlen(searchStr));
ffStrbufTrimRight(&os->codename, '\n');
ffStrbufTrimRight(&os->codename, '\\');
break;
+2 -1
View File
@@ -5,6 +5,7 @@
#include "common/properties.h"
#include "common/settings.h"
#include "detection/os/os.h"
#include "util/stringUtils.h"
#include <dirent.h>
@@ -170,7 +171,7 @@ static uint32_t getXBPSImpl(FFstrbuf* baseDir)
struct dirent *entry;
while((entry = readdir(dir)) != NULL)
{
if(entry->d_type != DT_REG || strncasecmp(entry->d_name, "pkgdb-", 6) != 0)
if(entry->d_type != DT_REG || !ffStrStartsWithIgnCase(entry->d_name, "pkgdb-"))
continue;
ffStrbufAppendC(baseDir, '/');
+2 -1
View File
@@ -1,6 +1,7 @@
#include "wifi.h"
#include "common/processing.h"
#include "common/properties.h"
#include "util/stringUtils.h"
#include <net/if.h>
#include <stdio.h>
@@ -14,7 +15,7 @@ const char* ffDetectWifi(FF_MAYBE_UNUSED const FFinstance* instance, FFlist* res
for(struct if_nameindex* i = infs; !(i->if_index == 0 && i->if_name == NULL); ++i)
{
if (strncmp(i->if_name, "wlan", strlen("wlan")) != 0) continue;
if (!ffStrStartsWith(i->if_name, "wlan")) continue;
FF_STRBUF_AUTO_DESTROY ifconfig = ffStrbufCreate();
if (ffProcessAppendStdOut(&ifconfig, (char* const[]) {
"ifconfig",
+3 -2
View File
@@ -1,4 +1,5 @@
#include "wifi.h"
#include "util/stringUtils.h"
#include <stdio.h>
#include <stdlib.h>
@@ -257,8 +258,8 @@ static const char* detectWifiWithIoctls(FF_MAYBE_UNUSED const FFinstance* instan
if(ioctl(sock, SIOCGIWNAME, &iwr) >= 0)
{
if(strncasecmp(iwr.u.name, "IEEE ", 5) == 0)
ffStrbufSetS(&item->conn.protocol, iwr.u.name + 5);
if(ffStrStartsWithIgnCase(iwr.u.name, "IEEE "))
ffStrbufSetS(&item->conn.protocol, iwr.u.name + strlen("IEEE "));
else
ffStrbufSetS(&item->conn.protocol, iwr.u.name);
}
+3 -2
View File
@@ -1,6 +1,7 @@
#include "logo/logo.h"
#include "common/jsonconfig.h"
#include "util/stringUtils.h"
void ffInitLogoOptions(FFLogoOptions* options)
{
@@ -63,10 +64,10 @@ logoType:
{},
});
}
else if(strncasecmp(subKey, "color-", strlen("color-")) && key[13] != '\0' && key[14] == '\0') // matches "--logo-color-*"
else if(ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*"
{
//Map the number to an array index, so that '1' -> 0, '2' -> 1, etc.
int index = (int)key[13] - 49;
int index = (int)subKey[6] - '0' - 1;
//Match only --logo-color-[1-9]
if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS)