Refactor: moves memrchr to global impl for potential future use

This commit is contained in:
李通洲
2026-02-10 18:16:58 +08:00
parent 61cdfcabf8
commit 996cdd3155
6 changed files with 42 additions and 26 deletions
+7 -1
View File
@@ -1115,7 +1115,6 @@ elseif(SunOS)
src/detection/displayserver/linux/xcb.c
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/common/solaris/memrchr.c
src/detection/gpu/gpu_sunos.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
@@ -1326,6 +1325,10 @@ endif()
if(NOT WIN32)
check_function_exists(pipe2 HAVE_PIPE2)
endif()
check_function_exists(memrchr HAVE_MEMRCHR)
if(NOT HAVE_MEMRCHR)
list(APPEND LIBFASTFETCH_SRC src/common/impl/memrchr.c)
endif()
if(ENABLE_SYSTEM_YYJSON)
find_package(yyjson)
@@ -1673,6 +1676,9 @@ if(ENABLE_LIBZFS)
)
endif()
endif()
if(NOT HAVE_MEMRCHR)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_CUSTOM_MEMRCHR=1)
endif()
if(LINUX)
target_link_libraries(libfastfetch
+19
View File
@@ -0,0 +1,19 @@
#include "common/memrchr.h"
#include <stddef.h>
#include <stdint.h>
void* memrchr(const void* s, int c, size_t n)
{
if (n == 0) return NULL;
const uint8_t uc = (uint8_t) c;
const uint8_t* p = (const uint8_t*) s + n;
while (n--)
{
if (*--p == uc) return (void*) p;
}
return NULL;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
// `memrchr` is a GNU extension and may not be declared by system headers even when the symbol exists.
// Declare it unconditionally; the build system provides a fallback implementation when missing.
void* memrchr(const void* s, int c, size_t n);
#ifdef __cplusplus
}
#endif
-15
View File
@@ -1,15 +0,0 @@
#if defined(__sun) && ! defined(__illumos__)
#include "memrchr.h"
void *memrchr(const void *s, int c, size_t n)
{
if(n == 0) return NULL;
const unsigned char *p = (const unsigned char *)s + n;
while (n--) {
if (*(--p) == (unsigned char) c)
return (void*) p;
}
return NULL;
}
#endif
-6
View File
@@ -1,6 +0,0 @@
#pragma once
#include <stddef.h>
#if defined(__sun) && !defined(__illumos__)
void *memrchr(const void *s, int c, size_t n);
#endif
+1 -4
View File
@@ -1,6 +1,7 @@
#include "gpu.h"
#include "common/io.h"
#include "common/properties.h"
#include "common/memrchr.h"
#include <stdlib.h>
#ifdef __FreeBSD__
@@ -24,10 +25,6 @@
#define FF_STR_INDIR(x) #x
#define FF_STR(x) FF_STR_INDIR(x)
#if defined(__sun) && ! defined(__illumos__)
#include "common/solaris/memrchr.h"
#endif
static const FFstrbuf* loadPciIds()
{
static FFstrbuf pciids;