mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-10 07:00:08 +01:00
Refactor: moves memrchr to global impl for potential future use
This commit is contained in:
1 parent
61cdfcabf8
commit
996cdd3155
6 files changed
+42
-26
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user