Make libfsverity.h usable from C++

Signed-off-by: Eric Biggers <ebiggers@google.com>
This commit is contained in:
Eric Biggers
2020-06-05 17:29:10 -07:00
parent 566c7dc17a
commit c1acb01d49
2 changed files with 24 additions and 0 deletions
+8
View File
@@ -9,6 +9,10 @@
#ifndef LIBFSVERITY_H
#define LIBFSVERITY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
@@ -131,4 +135,8 @@ const char *libfsverity_get_hash_name(uint32_t alg_num);
*/
void libfsverity_set_error_callback(void (*cb)(const char *msg));
#ifdef __cplusplus
}
#endif
#endif /* LIBFSVERITY_H */
+16
View File
@@ -53,6 +53,20 @@ if nm libfsverity.so | grep ' T ' | grep -v " libfsverity_"; then
fail "Some exported symbols are not prefixed with \"libfsverity_\""
fi
log "Test using libfsverity from C++ program"
cat > /tmp/libfsverity_test.cc <<EOF
#include <libfsverity.h>
#include <iostream>
int main()
{
std::cout << libfsverity_get_digest_size(FS_VERITY_HASH_ALG_SHA256) << std::endl;
}
EOF
c++ -Wall -Werror /tmp/libfsverity_test.cc -Icommon -L. -lfsverity \
-o /tmp/libfsverity_test
[ "$(LD_LIBRARY_PATH=. /tmp/libfsverity_test)" = "32" ]
rm /tmp/libfsverity_test*
log "Build and test with gcc"
$MAKE CC=gcc check
@@ -106,3 +120,5 @@ $MAKE CC=gcc CFLAGS="-fanalyzer -Werror" all test_programs
log "Run shellcheck"
shellcheck scripts/*.sh 1>&2
log "All tests passed!"