From 0a468566890696f0864fa224653be8b3e609d47f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 19 Jul 2022 09:02:42 +0200 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 2 +- README.md | 1 + src/c-stdaux.h | 17 +++++++++++++++++ src/test-basic.c | 11 +++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b905f5683..d35e113865 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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" diff --git a/README.md b/README.md index 124c692e12..d56fbc05c5 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ common extended features of wide-spread compilers like gcc and clang. ### Project * **Website**: + * **Documentation**: * **Bug Tracker**: ### Requirements diff --git a/src/c-stdaux.h b/src/c-stdaux.h index 6eb0a22d03..f87362bece 100644 --- a/src/c-stdaux.h +++ b/src/c-stdaux.h @@ -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 * diff --git a/src/test-basic.c b/src/test-basic.c index e5e3f907ed..28eb458973 100644 --- a/src/test-basic.c +++ b/src/test-basic.c @@ -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); + } } /*