Squashed 'src/c-stdaux/' changes from 1407a1fb2754..da7209900ef0

da7209900ef0 api: add c_memcmp()
2369947a563b build: use v1 ci-sphinx
d46a3eeaf30d build: mention documentation in README.md

git-subtree-dir: src/c-stdaux
git-subtree-split: da7209900ef065024db92b180dd8bc70440af9b4
This commit is contained in:
Thomas Haller 2022-07-19 09:02:42 +02:00
parent 9d1772bd73
commit 0a46856689
4 changed files with 30 additions and 1 deletions

View File

@ -25,6 +25,6 @@ jobs:
macos: true
ci-docs:
name: Documentation CI
uses: bus1/cabuild/.github/workflows/ci-sphinx.yml@main
uses: bus1/cabuild/.github/workflows/ci-sphinx.yml@v1
with:
source: "./src/docs"

View File

@ -11,6 +11,7 @@ common extended features of wide-spread compilers like gcc and clang.
### Project
* **Website**: <https://c-util.github.io/c-stdaux>
* **Documentation**: <https://c-stdaux.readthedocs.io>
* **Bug Tracker**: <https://github.com/c-util/c-stdaux/issues>
### Requirements

View File

@ -675,6 +675,23 @@ static inline void *c_memcpy(void *dst, const void *src, size_t n) {
return dst;
}
/**
* c_memcmp() - Compare memory areas
* @s1: Pointer to one area
* @s2: Pointer to other area
* @n: Length of area to compare
*
* Compare the memory of size ``n`` of ``s1`` and ``s2``, just as ``memcmp(3)``
* does, except this function allows either to be ``NULL`` if ``n`` is zero.
*
* Return: Comparison result for ordering is returned.
*/
static inline int c_memcmp(const void *s1, const void *s2, size_t n) {
if (n > 0)
return memcmp(s1, s2, n);
return 0;
}
/**
* DOC: Common Destructors
*

View File

@ -357,6 +357,17 @@ static void test_misc(int non_constant_expr) {
c_memcpy(NULL, NULL, 0);
}
/*
* Test c_memcmp() with.
*/
{
uint64_t v1 = (uint64_t)-1, v2 = (uint64_t)0;
c_assert(c_memcmp(NULL, NULL, 0) == 0);
c_assert(c_memcmp(&v1, &v2, 0) == 0);
c_assert(c_memcmp(&v1, &v2, 8) != 0);
}
}
/*