diff options
author | Thomas Haller <thaller@redhat.com> | 2022-07-19 09:02:42 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-07-19 09:02:42 +0200 |
commit | 0a468566890696f0864fa224653be8b3e609d47f (patch) | |
tree | 4ff7abbe5a4ffb3cf8b266934e26e4a55b747baf | |
parent | 9d1772bd73ba53c8afd938617548b124eec42d07 (diff) | |
download | NetworkManager-0a468566890696f0864fa224653be8b3e609d47f.tar.gz |
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
-rw-r--r-- | .github/workflows/ci.yml | 2 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | src/c-stdaux.h | 17 | ||||
-rw-r--r-- | src/test-basic.c | 11 |
4 files changed, 30 insertions, 1 deletions
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" @@ -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 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 @@ -676,6 +676,23 @@ static inline void *c_memcpy(void *dst, const void *src, size_t n) { } /** + * 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 * * A set of destructors is provided which extends standard library 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); + } } /* |