diff --git a/docs/libglacier.html b/docs/libglacier.html index 1798cd8..8e88fed 100644 --- a/docs/libglacier.html +++ b/docs/libglacier.html @@ -40,26 +40,26 @@

$ ${EDITOR} config.mk

CAUTION
-

Before proceeding with ANY other step, make sure you define PREFIX in config.mk.

-

By default this variable is not defined. Results will be unexpected if the library is compiled without PREFIX defined.

+

Before proceeding with ANY other step, make sure you define PREFIX in config.mk.

+

By default this variable is not defined. Results will be unexpected if the library is compiled without PREFIX defined.

Build the library:

$ make lib

NOTE
-

libglacier is provided as a static library only.

+

libglacier is provided as a static library only.

If you wish to compile a shared library instead, you must edit the Makefile

3 - Using libglacier in a program

To use libglacier in a program, include the relevant header files:

CODE: Including libglacier header files
-

#include <glacier_config.h>

-

#include <glacier_data.h>

-

#include <glacier_log.h>

-

#include <glacier_pkgops.h>

-

#include <glacier_runtime.h>

-

#include <glacier_security.h>

+

#include <glacier/config.h>

+

#include <glacier/data.h>

+

#include <glacier/log.h>

+

#include <glacier/pkgops.h>

+

#include <glacier/runtime.h>

+

#include <glacier/security.h>

To compile libglacier into your program, add the flag -lglacier to your build process.

@@ -72,18 +72,18 @@

No parameters are accepted by init_config.

CODE: init_config used in a program
-

#include <glacier_config.h>

-

 

+

#include <glacier/config.h>

+

int

main()

{

-

        if (init_config() != 0) {

-

                errlog("failed to initialize libconfig"); -

                return(EXIT_FAILURE);

-

        }

-

        else {

-

                successlog("Initialized libconfig"); -

        } +

if (init_config() != 0) {

+

errlog("failed to initialize libconfig");

+

return(EXIT_FAILURE);

+

}

+

else {

+

successlog("Initialized libconfig");

+

}

}

init_config returns 0 on success, and 1 on failure.

@@ -93,28 +93,30 @@

No parameters are accepted by die_config.

CODE: die_config used in a program
-

#include <glacier_config.h>

-

 

+

#include <glacier/config.h>

+

int

main()

{

-

        die_config();

+

die_config();

}

die_config returns 0 on success, and 1 on failure.

+

4.3 load_all_from_config

load_all_from_config loads all expected settings from /etc/glacier.cfg.

No parameters are accepted by load_all_from_config.

CODE: load_all_from_config used in a program
-

#include <glacier_config.h>

-

 

+

#include <glacier/config.h>

+

int

main()

{

-

        init_config();

+

init_config();

}

+

load_all_from_config returns 0 on success, and 1 on failure.

5 - Data structure functions

Since Glacier is a package manager, libglacier provides functions for creating and handling dependency trees.

5.1 create_node

@@ -125,14 +127,16 @@ CODE: create_node used in a program
-

#include <glacier_data.h>

-

 

+

#include <glacier/data.h>

+

int

main()

{

-

        struct node package = create_node("Package");

+

struct node package = create_node("Package");

}

+

create_node returns a node structure.

+

5.2 add_child

add_child adds a specified child node to a parent node.

add_child accepts the following parameters:

@@ -142,8 +146,8 @@ CODE: add_child used in a program
-

#include <glacier_data.h>

-

 

+

#include <glacier/data.h>

+

int

main()

{

@@ -152,6 +156,8 @@

add_child(pack, dep1);

}

+

add_child returns 0 on success, and 1 on failure.

+

5.3 print_tree

print_tree prints a dependency tree specified at its root node.

print_tree accepts the following parameters:

@@ -161,8 +167,8 @@ CODE: print_tree used in a program
-

#include <glacier_data.h>

-

 

+

#include <glacier/data.h>

+

int

main()

{

@@ -172,22 +178,28 @@

print_tree(pack, 0);

}

+

print_tree returns 0 on success.

+

5.4 init_queue

init_queue initializes a queue data structure.

+ REMOVED FEATURE +
+

The queue data structure was removed in a recent update (March 2025). This function is no longer available in the current version of libglacier.

+

init_queue accepts the following parameters:

CODE: init_queue used in a program
-

#include <glacier_data.h>

-

 

+

#include <glacier/data.h>

+

int

main()

{

-

hi

+

/* Queue implementation removed */

+

}

-

6 - Logging Functions

The logging functions libglacier provides are designed to allow a uniform style of output.

The following logging functions are included:

@@ -207,109 +219,283 @@

Logging functions do not require a newline character ('\n'), they will automatically place one after the message.

+

All logging functions return 0 on success, and 1 on failure.

CODE: Logging functions used in a program
-

#include <glacier_log.h>

-

 

+

#include <glacier/log.h>

+

int

main()

{

-

        infolog("This is an info message");

-

        warnlog("This is a warning message");

-

        errlog("This is an error message");

-

        successlog("This is a success message");

+

infolog("This is an info message");

+

warnlog("This is a warning message");

+

errlog("This is an error message");

+

successlog("This is a success message");

}

-

7 - Package Operation Functions

This section describes the numerous functions related to operations on packages.

7.1 mkworkspace

mkworkspace creates a Glacier workspace at /tmp/glacier-workspace.

mkworkspace accepts no parameters.

+ CODE: mkworkspace used in a program +
+

#include <glacier/pkgops.h>

+

+

int

+

main()

+

{

+

mkworkspace();

+

}

+

mkworkspace returns the following values:

- CODE: mkworkspace used in a program -
-

#include <glacier_pkgops.h>

-

 

-

int

-

main()

-

{

-

        mkworkspace();

-

}

-
+

Calling mkworkspace creates the workspace if it doesn't already exist.

+

7.2 prepare_pkg

prepare_pkg copies a package archive from the local package database to the workspace, and untars it.

prepare_pkg accepts the following parameters:

+ CODE: prepare_pkg used in a program +
+

#include <glacier/pkgops.h>

+

+

int

+

main()

+

{

+

prepare_pkg("/glacier/localdb/epkgs-x86_64-musl/foo.tar");

+

}

+

prepare_pkg returns the following values:

- CODE: prepare_pkg used in a program -
-

#include <glacier_pkgops.h>

-

 

-

int

-

main()

-

{

-

        prepare_pkg("/glacier/localdb/epkgs-x86_64-musl/foo.tar");

-

}

-
-

 

CAUTION:

This example presented is not the best. Instead of manually specifying the package directory, you should be calling the system profile.

+

7.3 run_make_task

run_make_task runs a specified make task in a package's current working directory.

run_make_task accepts the following parameters:

+ CODE: run_make_task used in a program +
+

#include <glacier/pkgops.h>

+

+

int

+

main()

+

{

+

prepare_pkg("/glacier/localdb/epkgs-x86_64-musl/foo.tar");

+

run_make_task("installpkg");

+

}

+

run_make_task returns the following values:

- CODE: run_make_task used in a program -
-

#include <glacier_pkgops.h>

-

 

-

int

-

main()

-

{

-

        prepare_pkg("/glacier/localdb/epkgs-x86_64-musl/foo.tar");

-

        run_make_task("installpkg");

- -

}

-

8 - Runtime Functions

The functions described here are used for various runtime checks.

8.1 runtime_exists

runtime_exists checks if necessary runtime files exist and are in their correct locations.

-

runtime_exists accepts no parameters. -

runtime_exists returns no values.

+

runtime_exists accepts no parameters.

CODE: runtime_exists used in a program
-

#include <glacier_runtime.h>

-

 

+

#include <glacier/runtime.h>

+

int

main()

{

-

        runtime_exists();

+

runtime_exists();

}

-

8.2 +

runtime_exists returns no values.

+
+

8.2 is_process_root

+

is_process_root verifies if the process has root privileges to perform package operations.

+

is_process_root accepts no parameters.

+ CODE: is_process_root used in a program +
+

#include <glacier/runtime.h>

+

+

int

+

main()

+

{

+

if (is_process_root() != 0) {

+

errlog("insufficient permissions to perform package operations");

+

return(EXIT_FAILURE);

+

}

+

}

+
+

is_process_root returns the following values:

+ +
+

8.3 get_system_profile

+

get_system_profile fetches the system profile, which contains information about the architecture and libc implementation.

+

get_system_profile accepts no parameters.

+ CODE: get_system_profile used in a program +
+

#include <glacier/runtime.h>

+

+

int

+

main()

+

{

+

char *profile = get_system_profile();

+

infolog(profile);

+

}

+
+

get_system_profile returns a pointer to a string containing the system profile (e.g., "x86_64-musl").

+

9 - Security Functions

+

These functions provide security checks for package integrity and signatures.

+

9.1 verify_signature

+

verify_signature checks if a package's signature is valid against the trusted keyring.

+ UPCOMING FEATURE +
+

This function is planned for a future release and is not yet implemented in the current version of libglacier.

+
+

verify_signature accepts the following parameters:

+ + CODE: verify_signature used in a program +
+

#include <glacier/security.h>

+

+

int

+

main()

+

{

+

if (verify_signature("package.tar", "package.tar.sig") != 0) {

+

errlog("invalid package signature");

+

return(EXIT_FAILURE);

+

}

+

return(EXIT_SUCCESS);

+

}

+
+

verify_signature returns the following values:

+ +
+

9.2 check_integrity

+

check_integrity verifies a package's SHA256 checksum against the expected value.

+ UPCOMING FEATURE +
+

This function is planned for a future release and is not yet implemented in the current version of libglacier.

+

Note that the underlying functions for calculating file hashes (hash_file(), stash_hash(), print_hash()) are already implemented.

+
+

check_integrity accepts the following parameters:

+ + CODE: check_integrity used in a program +
+

#include <glacier/security.h>

+

+

int

+

main()

+

{

+

char *expected = "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592";

+

if (check_integrity("package.tar", expected) != 0) {

+

errlog("package integrity check failed");

+

return(EXIT_FAILURE);

+

}

+

return(EXIT_SUCCESS);

+

}

+
+

check_integrity returns the following values:

+ +

10 - Advanced Usage

+

This section covers more advanced usage patterns for libglacier.

+

10.1 Custom dependency tree handling

+

While libglacier provides functions for creating and manipulating dependency trees, you might need to implement custom behaviors for resolving dependencies.

+ CODE: Custom dependency resolution +
+

#include <glacier/data.h>

+

#include <glacier/log.h>

+

+

int

+

resolve_dependencies(struct node *root)

+

{

+

/* Custom dependency resolution logic here */

+

for (int i = 0; i < root->num_children; i++) {

+

infolog(root->children[i]->data);

+

/* Process child dependencies recursively */

+

resolve_dependencies(root->children[i]);

+

}

+

return(0);

+

}

+

+

int

+

main()

+

{

+

struct node *root = create_node("base-package");

+

struct node *dep1 = create_node("dependency1");

+

struct node *dep2 = create_node("dependency2");

+

add_child(root, dep1);

+

add_child(root, dep2);

+

resolve_dependencies(root);

+

return(EXIT_SUCCESS);

+

}

+
+
+

10.2 Error handling best practices

+

When using libglacier, it's important to implement proper error handling. All functions that return integer status codes should be checked.

+ CODE: Proper error handling +
+

#include <glacier/config.h>

+

#include <glacier/log.h>

+

#include <glacier/pkgops.h>

+

+

int

+

main()

+

{

+

/* Initialize configuration */

+

if (init_config() != 0) {

+

errlog("failed to initialize configuration");

+

return(EXIT_FAILURE);

+

}

+

+

/* Create workspace */

+

if (mkworkspace() != 0) {

+

errlog("failed to create workspace");

+

die_config();

+

return(EXIT_FAILURE);

+

}

+

+

/* Always clean up resources */

+

die_config();

+

return(EXIT_SUCCESS);

+

}

+
+

+ NOTE: +
+

Always free resources and clean up configurations when your program exits, even on error paths.

+

This prevents memory leaks and ensures consistent behavior.

+