lazysphere/lib/lslib.h

141 lines
3.4 KiB
C
Raw Normal View History

2023-05-06 04:39:44 +00:00
#ifndef SHARED_H
#define SHARED_H
#include <stdint.h>
#include <stdio.h>
2023-05-15 01:43:02 +00:00
#include <sys/stat.h>
#include <pwd.h>
#define ANSCII "\x1b["
#define NEXT ";"
#define RESET "0"
#define BOLD "1"
#define NORMAL "3"
#define BACKGROUND "4"
#define HIGHLIGHT "9"
#define BLACK "0"
#define RED "1"
#define GREEN "2"
#define YELLOW "3"
#define BLUE "4"
#define MAGENTA "5"
#define TURQUOISE "6"
#define WHITE "7"
#define COLOR "m"
typedef uint8_t bool;
#define true 1
#define false 0
#define UNUSED(x) (void)(x)
#define ARG_UNUSED 0
#define ARG_USED 1
#define ARG_IGNORE 2
#define ARG_INVALID 3
void check_arg (char* arg);
void global_help(void (*help)(void));
void parse_help (int argc, char** argv, void (*help)(void));
int parse_args (int argc, char** argv, void (*help)(void), int (*short_arg)(char, char*), int (*long_arg)(char*, char*));
FILE* get_file_s(const char* path, const char* type);
FILE* get_file(const char* path, const char* type);
int get_tty(void);
FILE* get_tty_stream(char* type);
void nuke_str(char* type);
char* get_path_buffer(void);
int push_path_buffer(const char* string);
void pop_path_buffer(int i);
char* get_path_buffer_2(void);
int push_path_buffer_2(const char* string);
void pop_path_buffer_2(int i);
long int get_number(const char* text);
long int get_blkm(const char* text);
mode_t get_mode(const char* text);
bool streql(const char* a, const char* b);
bool prefix(const char* pre, const char* str);
void print_file_size(size_t bytes, char buf[5]);
void print_date_time(time_t mills, char buf[13]);
void print_file_path(char* path);
bool is_dot_dir(const char* path);
const char* get_last_component(const char* path);
void die (void);
__attribute__ ((__format__(printf, 1, 2)))
void error_s(const char* format, ...);
__attribute__ ((__format__(printf, 1, 2)))
void error(const char* format, ...);
__attribute__ ((__format__(printf, 1, 2)))
void output(const char* format, ...);
typedef struct regex_t* re_t;
re_t re_compile(const char* pattern);
int re_matchp(re_t pattern, const char* text, int* matchlength);
int re_match(const char* pattern, const char* text, int* matchlength);
struct Stack {
size_t size;
size_t capacity;
void* data;
};
void stack_init(struct Stack* stack, size_t size);
void stack_push(struct Stack* stack, void* data, size_t len);
void* stack_pop(struct Stack* stack, size_t len);
void stack_free(struct Stack* stack);
void stack_push_int(struct Stack* stack, int value);
bool stack_pop_int(struct Stack* stack, int* value);
#define DEFAULT_SHELL "/bin/sh"
#define DEFAULT_PATH "/sbin:/usr/sbin:/bin:/usr/bin"
void setup_environment(const char *shell, bool new_env, bool clear_env, const struct passwd *pw);
void exec_shell(const char *shell, bool loginshell, const char **additional_args);
int check_password(const struct passwd *pw, char* plaintext);
int prompt_password(const struct passwd *pw, char* prompt);
void change_identity(const struct passwd* pw);
void* xalloc(size_t size);
void* xrealloc(void* ptr, size_t size);
void* xzalloc(size_t size);
void xsetenv(const char *name, const char *value);
void xsetuid(uid_t uid);
void xsetgid(gid_t gid);
struct passwd* xgetpwnam(char* name);
#define PASSWORD_INVALID 0
#define PASSWORD_VALID 1
#define PASSWORD_EMPTY 2
2023-05-06 04:39:44 +00:00
#endif