STASIS
A pipeline delivery generator
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1
2#ifndef STASIS_UTILS_H
3#define STASIS_UTILS_H
4#include <stdio.h>
5#include <stdlib.h>
6#include <dirent.h>
7#include <string.h>
8#include <unistd.h>
9#include <limits.h>
10#include <errno.h>
11#include "core.h"
12#include "log.h"
13#include "copy.h"
14#include "system.h"
15#include "strlist.h"
16#include "utils.h"
17#include "ini.h"
18
19#if defined(STASIS_OS_WINDOWS)
20#define PATH_ENV_VAR "path"
21#define DIR_SEP "\\"
22#define PATH_SEP ";"
23#define LINE_SEP "\r\n"
24#else
25#define PATH_ENV_VAR "PATH"
26#define DIR_SEP "/"
27#define PATH_SEP ":"
28#define LINE_SEP "\n"
29#endif
30
31#if defined(STASIS_OS_LINUX)
32#define STASIS_RANDOM_GENERATOR_FILE "/dev/urandom"
33#elif defined(STASIS_OS_DARWIN)
34#define STASIS_RANDOM_GENERATOR_FILE "/dev/random"
35#else
36#define STASIS_RANDOM_GENERATOR_FILE NULL
37#define NEED_SRAND 1
38#endif
39
40#define STASIS_XML_PRETTY_PRINT_PROG "xmllint"
41#define STASIS_XML_PRETTY_PRINT_ARGS "--format"
42
59int pushd(const char *path);
60
67int popd(void);
68
87char *expandpath(const char *_path);
88
101int rmtree(char *_path);
102
103
104char **file_readlines(const char *filename, size_t start, size_t limit, ReaderFn *readerFn);
105
113char *path_basename(char *path);
114
121char *path_dirname(char *path);
122
128char *find_program(const char *name);
129
135int touch(const char *filename);
136
165int git_clone(struct Process *proc, char *url, char *destdir, char *gitref);
166
172char *git_describe(const char *path);
173
180char *git_rev_parse(const char *path, char *args);
181
202int path_store(char **destptr, size_t maxlen, const char *base, const char *path);
203
204#if defined(STASIS_DUMB_TERMINAL)
205#define STASIS_COLOR_RED ""
206#define STASIS_COLOR_GREEN ""
207#define STASIS_COLOR_YELLOW ""
208#define STASIS_COLOR_BLUE ""
209#define STASIS_COLOR_WHITE ""
210#define STASIS_COLOR_RESET ""
211#else
213#define STASIS_COLOR_RED "\x1b[1;91m"
215#define STASIS_COLOR_GREEN "\x1b[1;92m"
217#define STASIS_COLOR_YELLOW "\x1b[1;93m"
219#define STASIS_COLOR_BLUE "\x1b[1;94m"
221#define STASIS_COLOR_WHITE "\x1b[1;97m"
223#define STASIS_COLOR_RESET "\x1b[0;37m\x1b[0m"
224#endif
225
226#define STASIS_MSG_SUCCESS 0
228#define STASIS_MSG_NOP 1 << 0
230#define STASIS_MSG_ERROR 1 << 1
232#define STASIS_MSG_WARN 1 << 2
234#define STASIS_MSG_L1 1 << 3
236#define STASIS_MSG_L2 1 << 4
238#define STASIS_MSG_L3 1 << 5
240#define STASIS_MSG_RESTRICT 1 << 6
241
242void msg(unsigned type, char *fmt, ...);
243
244// Enter an interactive shell that ends the program on-exit
245void debug_shell();
246
266char *xmkstemp(FILE **fp, const char *mode);
267
282int isempty_dir(const char *path);
283
291int xml_pretty_print_in_place(const char *filename, const char *pretty_print_prog, const char *pretty_print_args);
292
300int fix_tox_conf(const char *filename, char **result, size_t maxlen);
301
302char *collapse_whitespace(char **s);
303
346int redact_sensitive(const char **to_redact, size_t to_redact_size, char *src, char *dest, size_t maxlen);
347
366struct StrList *listdir(const char *path);
367
372long get_cpu_count();
373
380int mkdirs(const char *_path, mode_t mode);
381
404char *find_version_spec(char *package_name);
405
406// mode flags for env_manipulate_pathstr
407#define PM_APPEND 1 << 0
408#define PM_PREPEND 1 << 1
409#define PM_ONCE 1 << 2
410
420int env_manipulate_pathstr(const char *key, char *path, int mode);
421
425int gen_file_extension_str(char *filename, size_t maxlen, const char *extension);
426
430char *remove_extras(char *s);
431
432void debug_hexdump(char *data, int len);
433
469int grow(size_t size_new, size_t *size_orig, char **data);
470
471int in_ascii_range(char c, char lower, char upper);
472
473#define GIT_HASH_LEN 40
474int is_git_sha(char const *hash);
475
476int check_python_package_dependencies(const char *srcdir);
477
478void seconds_to_human_readable(int v, char *result, size_t maxlen);
479
480#define STR_TO_TIMEOUT_NEGATIVE (-1)
481#define STR_TO_TIMEOUT_INVALID_TIME_SCALE (-2)
482int str_to_timeout(char *s);
483
484const char *get_random_generator_file();
485int get_random_bytes(char *result, size_t maxlen);
486
492int non_format_len(const char *s);
493
494char *center_text(const char *s, size_t maxwidth);
495#endif //STASIS_UTILS_H
Definition system.h:19
Definition strlist.h:16
int path_store(char **destptr, size_t maxlen, const char *base, const char *path)
Definition utils.c:557
char * find_program(const char *name)
Definition utils.c:262
int redact_sensitive(const char **to_redact, size_t to_redact_size, char *src, char *dest, size_t maxlen)
Definition utils.c:798
int touch(const char *filename)
Definition utils.c:295
int git_clone(struct Process *proc, char *url, char *destdir, char *gitref)
Definition utils.c:309
char * xmkstemp(FILE **fp, const char *mode)
Definition utils.c:501
int fix_tox_conf(const char *filename, char **result, size_t maxlen)
Definition utils.c:674
long get_cpu_count()
Definition utils.c:857
int rmtree(char *_path)
Definition utils.c:35
char * expandpath(const char *_path)
Definition utils.c:77
int pushd(const char *path)
Definition utils.c:9
int isempty_dir(const char *path)
Definition utils.c:539
char * collapse_whitespace(char **s)
Definition utils.c:765
char * git_rev_parse(const char *path, char *args)
Definition utils.c:395
int xml_pretty_print_in_place(const char *filename, const char *pretty_print_prog, const char *pretty_print_args)
Definition utils.c:601
int popd(void)
Definition utils.c:24
int mkdirs(const char *_path, mode_t mode)
Definition utils.c:865
char * git_describe(const char *path)
Definition utils.c:372
char * path_basename(char *path)
Definition utils.c:135
struct StrList * listdir(const char *path)
Definition utils.c:828
char * path_dirname(char *path)
Definition utils.c:150