diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 16:28:20 +0000 |
commit | dcc721a95bef6f0d8e6d8775b8efe33e5aecd562 (patch) | |
tree | 66a2774cd0ee294d019efd71d2544c70f42b2842 /tests/test_id.c | |
parent | Initial commit. (diff) | |
download | rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.tar.xz rsyslog-dcc721a95bef6f0d8e6d8775b8efe33e5aecd562.zip |
Adding upstream version 8.2402.0.upstream/8.2402.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_id.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/test_id.c b/tests/test_id.c new file mode 100644 index 0000000..326ad3f --- /dev/null +++ b/tests/test_id.c @@ -0,0 +1,39 @@ +#include <stdlib.h> +#include <sys/time.h> +#include <stdio.h> +#include <time.h> + +/* one provided by Aaaron Wiebe based on perl's hashing algorithm + * (so probably pretty generic). Not for excessively large strings! + */ +#if defined(__clang__) +#pragma GCC diagnostic ignored "-Wunknown-attributes" +#endif +static unsigned __attribute__((nonnull(1))) int +#if defined(__clang__) +__attribute__((no_sanitize("unsigned-integer-overflow"))) +#endif +hash_from_string(void *k) +{ + char *rkey = (char*) k; + unsigned hashval = 1; + + while (*rkey) + hashval = hashval * 33 + *rkey++; + + return hashval; +} + +int main(int argc, char *argv[]) +{ + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); + if(argc != 2) { + fprintf(stderr, "usage: test_id test-file-name\n"); + exit(1); + } + printf("%06ld_%04.4x", tv.tv_usec, hash_from_string(argv[1])); + + return 0; +} |