linuxinstall/src/utils.h

39 lines
1.0 KiB
C
Raw Normal View History

2024-02-15 19:42:22 +01:00
#pragma once
#include <stdint.h>
2024-02-17 23:59:38 +01:00
#include <stdbool.h>
2024-02-18 18:09:53 +01:00
#include <stdlib.h>
2024-02-15 19:42:22 +01:00
typedef enum {
SUCCESS,
2024-02-17 23:59:38 +01:00
FAILURE
2024-02-18 18:09:53 +01:00
} Result;
typedef enum {
LOG_LEVEL_DEBUG,
2024-02-17 23:59:38 +01:00
LOG_LEVEL_INFO,
LOG_LEVEL_WARNING,
LOG_LEVEL_ERROR,
2024-02-15 19:42:22 +01:00
} LogLevel;
2024-02-18 14:05:04 +01:00
extern LogLevel LOG_LEVEL;
2024-02-15 19:42:22 +01:00
2024-02-17 23:59:38 +01:00
void SetLogLevel(LogLevel level);
void Log(LogLevel level, const char* format, ...);
2024-02-18 18:09:53 +01:00
Result Format(char** _string, const char* fmt, ...);
Result Duplicate(const char* string, char** _duplicate);
Result Substring(const char* string, size_t start, size_t end, char** _substring);
2024-02-17 14:21:14 +01:00
2024-02-18 18:09:53 +01:00
Result FormatSize(uint64_t size, char** _size_str);
Result ParseSize(const char* size_str, uint64_t* _size);
2024-02-18 14:05:04 +01:00
2024-02-18 18:09:53 +01:00
Result RunExecutable(int* _exit_code, char** _stdout, char** _stderr, const char* executable, ...);
2024-02-17 14:38:52 +01:00
2024-02-18 18:09:53 +01:00
Result ReadFileDescriptor(int fd, char** _content);
Result WriteFileDescriptor(int fd, const char* content);
Result ReadFile(const char* path, char** _content);
Result WriteFile(const char* path, const char* content);
2024-02-18 18:09:53 +01:00
Result CopyFile(const char* source_path, const char* destination_path);