libmp/include/util.h

51 lines
1.8 KiB
C

#pragma once
#include "pool.h"
#include <archive.h>
#include <libintl.h>
#include <netinet/in.h>
#include <stdbool.h>
#include <stdio.h>
#define _(x) gettext(x)
#define BINARY(b) \
(b & 128 ? '1' : '0'), (b & 64 ? '1' : '0'), (b & 32 ? '1' : '0'), (b & 16 ? '1' : '0'), (b & 8 ? '1' : '0'), \
(b & 4 ? '1' : '0'), (b & 2 ? '1' : '0'), (b & 1 ? '1' : '0')
bool contains(char *str, char s);
bool eq(char *s1, char *s2);
bool is_letter(char c);
bool is_digit(char c);
bool copy_from_buffer(void *dst, void *buffer, size_t size, ssize_t *total, ssize_t *used);
bool copy_to_buffer(void *buffer, void *src, size_t size, ssize_t *total, ssize_t *used);
char *get_md5(char *path);
bool copy_file(char *dst, char *src);
bool can_write(char *path);
bool can_read(char *path);
bool is_file(char *path);
bool is_dir(char *path);
bool exists(char *path, struct stat *st);
bool is_empty(char *p);
bool is_dir_empty(char *p);
bool rmrf(char *p);
int digits(int n);
bool package_parse(char *package, char *name, char *version);
bool __package_field_valid(char *field);
#define package_version_valid(x) __package_field_valid(x)
#define package_name_valid(x) __package_field_valid(x)
void pdebug(const char *func, const char *fmt, ...);
void pdebug_binary(char *data, size_t len);
bool parse_host(char *addr, char *host, uint16_t *port);
bool copy_blocks(struct archive *w, struct archive *r);
bool extract_archive(char *dst, char *src);
bool mkdir_ifnot(char *path, int mode);
int join_multiple(char *res, const char *base, const char *pth, const char *pth2);
int join(char *res, const char *base, const char *pth);
char *join_alloc(const char *base, const char *pth);