2024-02-15 19:42:22 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
LOG_DEBUG,
|
|
|
|
LOG_INFO,
|
|
|
|
LOG_WARN,
|
|
|
|
LOG_ERROR,
|
|
|
|
} LogLevel;
|
|
|
|
|
2024-02-16 23:26:29 +01:00
|
|
|
/// @brief Formats a string using printf-style formatting.
|
|
|
|
/// @param fmt The format string.
|
|
|
|
/// @param ... The arguments to format into the string.
|
|
|
|
/// @return The formatted string or NULL if an error occurred. The result must be freed with free().
|
2024-02-15 19:42:22 +01:00
|
|
|
char* format(const char* fmt, ...);
|
|
|
|
|
2024-02-16 23:26:29 +01:00
|
|
|
/// @brief Logs a message to the console.
|
|
|
|
/// @param level The log level of the message.
|
|
|
|
/// @param fmt The format string of the message.
|
|
|
|
/// @param ... The arguments to format into the message.
|
2024-02-16 02:22:24 +01:00
|
|
|
void log_message(LogLevel level, const char* fmt, ...);
|
2024-02-15 19:42:22 +01:00
|
|
|
|
2024-02-16 23:26:29 +01:00
|
|
|
/// @brief Executes a command and returns the exit code as well as the output and error streams.
|
|
|
|
/// @param outb The output stream of the command. May be NULL if the output is not needed.
|
|
|
|
/// @param errb The error stream of the command. May be NULL if the error is not needed.
|
|
|
|
/// @param file The file to execute.
|
|
|
|
/// @param ... The arguments to pass to the file.
|
|
|
|
/// @return The exit code of the command.
|
2024-02-16 02:22:24 +01:00
|
|
|
int execute(char** outb, char** errb, const char* file, ...);
|
2024-02-15 19:42:22 +01:00
|
|
|
|
2024-02-16 23:26:29 +01:00
|
|
|
/// @brief Reads the contents of a file into a string. The result might contain null bytes.
|
|
|
|
/// @param fd The file descriptor of the file to read.
|
|
|
|
/// @return The contents of the file or NULL if an error occurred. The result must be freed with free().
|
|
|
|
char* read_file(int fd);
|