cosmopolitan/third_party/xxhash/tests/multiInclude.c
Justine Tunney f531acc8f9
Make improvements
- Invent openatemp() API
- Invent O_UNLINK open flag
- Introduce getenv_secure() API
- Remove `git pull` from cosmocc
- Fix utimes() when path is NULL
- Fix mktemp() to never return NULL
- Fix utimensat() UTIME_OMIT on XNU
- Improve utimensat() code for RHEL5
- Turn `argv[0]` C:/ to /C/ on Windows
- Introduce tmpnam() and tmpnam_r() APIs
- Fix more const issues with internal APIs
- Permit utimes() on WIN32 in O_RDONLY mode
- Fix fdopendir() to check fd is a directory
- Fix recent crash regression in landlock make
- Fix futimens(AT_FDCWD, NULL) to return EBADF
- Use workaround so `make -j` doesn't fork bomb
- Rename dontdiscard to __wur (just like glibc)
- Fix st_size for WIN32 symlinks containing UTF-8
- Introduce stdio ext APIs needed by GNU coreutils
- Fix lstat() on WIN32 for symlinks to directories
- Move some constants from normalize.inc to limits.h
- Fix segv with memchr() and memcmp() overlapping page
- Implement POSIX fflush() behavior for reader streams
- Implement AT_SYMLINK_NOFOLLOW for utimensat() on WIN32
- Don't change read-only status of existing files on WIN32
- Correctly handle `0x[^[:xdigit:]]` case in strtol() functions
2023-09-06 12:34:59 -07:00

85 lines
2.6 KiB
C

// clang-format off
/*
* Multi-include test program
* Validates that xxhash.h can be included multiple times and in any order
*
* Copyright (C) 2020 Yann Collet
*
* GPL v2 License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* You can contact the author at:
* - xxHash homepage: https://www.xxhash.com
* - xxHash source repository: https://github.com/Cyan4973/xxHash
*/
#include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/fmt/fmt.h"
#include "libc/stdio/dprintf.h"
#include "libc/stdio/stdio.h"
#include "libc/temp.h"
#include "third_party/musl/tempnam.h" /* printf */
/* Normal include, gives access to public symbols */
#include "third_party/xxhash/xxhash.h"
/* Multiple consecutive inclusions are handled properly. */
#include "third_party/xxhash/xxhash.h"
/*
* Advanced include, gives access to experimental symbols
* This test ensures that xxhash.h can be included multiple times
* and in any order. The tested order is more difficult:
* without care, the declaration of experimental symbols could be skipped.
*/
#define XXH_STATIC_LINKING_ONLY
#include "third_party/xxhash/xxhash.h"
/*
* Inlining: redefine all identifiers, keep them private to the unit.
* Note: Without specific efforts, the identifier names would collide.
*
* To be linked with and without xxhash.o
* to test the symbol's presence and naming collisions.
*/
#define XXH_INLINE_ALL
#include "third_party/xxhash/xxhash.h"
/*
* Multiple consecutive inclusions with XXH_INLINE_ALL are handled properly.
*/
#define XXH_INLINE_ALL
#include "third_party/xxhash/xxhash.h"
void hash_advanced(void)
{
XXH3_state_t state; /* this type is part of experimental API */
XXH3_64bits_reset(&state);
const char input[] = "Hello World !";
XXH3_64bits_update(&state, input, sizeof(input));
XXH64_hash_t const h = XXH3_64bits_digest(&state);
printf("hash '%s': %08x%08x \n", input, (unsigned)(h >> 32), (unsigned)h);
}
int main(void)
{
hash_advanced();
}