Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utils: add functions to get the current version of the library #261

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ headers = files(
'sqsh_posix.h',
'sqsh_table.h',
'sqsh_tree.h',
'sqsh_utils.h',
'sqsh_xattr.h',
)

Expand Down
6 changes: 6 additions & 0 deletions include/sqsh.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* @file sqsh.h
*/

#ifndef SQSH_H
#define SQSH_H

#include "sqsh_archive.h"
#include "sqsh_common.h"
#include "sqsh_directory.h"
Expand All @@ -41,4 +44,7 @@
#include "sqsh_posix.h"
#include "sqsh_table.h"
#include "sqsh_tree.h"
#include "sqsh_utils.h"
#include "sqsh_xattr.h"

#endif /* SQSH_H */
110 changes: 110 additions & 0 deletions include/sqsh_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/******************************************************************************
* *
* Copyright (c) 2023-2024, Enno Boland <[email protected]> *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are *
* met: *
* *
* * Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
******************************************************************************/

/**
* @author Enno Boland ([email protected])
* @file sqsh_utils.h
*/

#ifndef SQSH_UTILS_H
#define SQSH_UTILS_H

#include "sqsh_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/***************************************
* utils/version.c
*/

/**
* @brief Get the version of the library that was used to compile the program as
* a string.
*
* @return Version string
*/
#define SQSH_VERSION "1.4.0"

/**
* @brief Get the major version of the library that was used to compile the
* program.
*
* @return Major version
*/
#define SQSH_VERSION_MAJOR 1

/**
* @brief Get the minor version of the library that was used to compile the
* program.
*
* @return Minor version
*/
#define SQSH_VERSION_MINOR 4

/**
* @brief Get the patch version of the library that was used to compile the
* program.
*
* @return Patch version
*/
#define SQSH_VERSION_PATCH 0

/**
* @brief Get the version of the currently running library as a string.
*
* @return Version string
*/
const char *sqsh_version(void);

/**
* @brief Get the major version of the currently running library.
*
* @return Major version
*/
uint16_t sqsh_version_major(void);

/**
* @brief Get the minor version of the currently running library.
*
* @return Minor version
*/
uint16_t sqsh_version_minor(void);

/**
* @brief Get the patch version of the currently running library.
*
* @return Patch version
*/
uint16_t sqsh_version_patch(void);

#ifdef __cplusplus
}
#endif
#endif /* SQSH_UTILS_H */
1 change: 1 addition & 0 deletions libsqsh/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ libsqsh_sources = files(
'tree/traversal.c',
'tree/walker.c',
'utils/error.c',
'utils/version.c',
'xattr/xattr_iterator.c',
)

Expand Down
54 changes: 54 additions & 0 deletions libsqsh/src/utils/version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/******************************************************************************
* *
* Copyright (c) 2023-2024, Enno Boland <[email protected]> *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are *
* met: *
* *
* * Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
******************************************************************************/

/**
* @author Enno Boland ([email protected])
* @file version.c
*/

#include <sqsh_utils.h>

const char *
sqsh_version(void) {
return SQSH_VERSION;
}

uint16_t
sqsh_version_major(void) {
return SQSH_VERSION_MAJOR;
}

uint16_t
sqsh_version_minor(void) {
return SQSH_VERSION_MINOR;
}

uint16_t
sqsh_version_patch(void) {
return SQSH_VERSION_PATCH;
}
55 changes: 55 additions & 0 deletions test/libsqsh/check_version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/******************************************************************************
* *
* Copyright (c) 2023-2024, Enno Boland <[email protected]> *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions are *
* met: *
* *
* * Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* * Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS *
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, *
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR *
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR *
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
******************************************************************************/

/**
* @author Enno Boland ([email protected])
* @file nasty.c
*/

#include <sqsh_utils.h>
#include <utest.h>

UTEST(version, version_defines_are_correct) {
char *version = getenv("VERSION");

ASSERT_NE(NULL, version);
ASSERT_STREQ(SQSH_VERSION, version);
ASSERT_STREQ(SQSH_VERSION, sqsh_version());

int major, minor, patch;
ASSERT_EQ(3, sscanf(version, "%d.%d.%d", &major, &minor, &patch));

ASSERT_EQ(SQSH_VERSION_MAJOR, major);
ASSERT_EQ(SQSH_VERSION_MAJOR, sqsh_version_major());
ASSERT_EQ(SQSH_VERSION_MINOR, minor);
ASSERT_EQ(SQSH_VERSION_MINOR, sqsh_version_minor());
ASSERT_EQ(SQSH_VERSION_PATCH, patch);
ASSERT_EQ(SQSH_VERSION_PATCH, sqsh_version_patch());
}

UTEST_MAIN()
3 changes: 2 additions & 1 deletion test/libsqsh/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
add_languages('cpp', native: false)

sqsh_test = [
'check_version.c',
'cpp-test.cpp',
'archive/compression_options.c',
'archive/inode_map.c',
Expand Down Expand Up @@ -101,5 +102,5 @@ foreach p : sqsh_test
link_with: [libsqsh.get_static_lib(), libmksqsh.get_static_lib()],
dependencies: [threads_dep, utest_dep, cextras_dep],
)
test(p, t, env: {})
test(p, t, env: {'VERSION': meson.project_version()})
endforeach
Loading