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
188
189int is_git_assumed_unchanged(char *filename);
190
211int path_store(char **destptr, size_t maxlen, const char *base, const char *path);
212
213#if defined(STASIS_DUMB_TERMINAL)
214#define STASIS_COLOR_RED ""
215#define STASIS_COLOR_GREEN ""
216#define STASIS_COLOR_YELLOW ""
217#define STASIS_COLOR_BLUE ""
218#define STASIS_COLOR_WHITE ""
219#define STASIS_COLOR_RESET ""
220#else
222#define STASIS_COLOR_RED "\x1b[1;91m"
224#define STASIS_COLOR_GREEN "\x1b[1;92m"
226#define STASIS_COLOR_YELLOW "\x1b[1;93m"
228#define STASIS_COLOR_BLUE "\x1b[1;94m"
230#define STASIS_COLOR_WHITE "\x1b[1;97m"
232#define STASIS_COLOR_RESET "\x1b[0;37m\x1b[0m"
233#endif
234
235#define STASIS_MSG_SUCCESS 0
237#define STASIS_MSG_NOP 1 << 0
239#define STASIS_MSG_ERROR 1 << 1
241#define STASIS_MSG_WARN 1 << 2
243#define STASIS_MSG_L1 1 << 3
245#define STASIS_MSG_L2 1 << 4
247#define STASIS_MSG_L3 1 << 5
249#define STASIS_MSG_RESTRICT 1 << 6
250
251void msg(unsigned type, char *fmt, ...);
252
253// Enter an interactive shell that ends the program on-exit
254void debug_shell();
255
275char *xmkstemp(FILE **fp, const char *mode);
276
291int isempty_dir(const char *path);
292
300int xml_pretty_print_in_place(const char *filename, const char *pretty_print_prog, const char *pretty_print_args);
301
309int fix_tox_conf(const char *filename, char **result, size_t maxlen);
310
311char *collapse_whitespace(char **s);
312
355int redact_sensitive(const char **to_redact, size_t to_redact_size, char *src, char *dest, size_t maxlen);
356
375struct StrList *listdir(const char *path);
376
381long get_cpu_count();
382
389int mkdirs(const char *_path, mode_t mode);
390
413char *find_version_spec(char *package_name);
414
415// mode flags for env_manipulate_pathstr
416#define PM_APPEND 1 << 0
417#define PM_PREPEND 1 << 1
418#define PM_ONCE 1 << 2
419
429int env_manipulate_pathstr(const char *key, char *path, int mode);
430
434int gen_file_extension_str(char *filename, size_t maxlen, const char *extension);
435
439char *remove_extras(char *s);
440
441void debug_hexdump(char *data, size_t len);
442
478int grow(size_t size_new, size_t *size_orig, char **data);
479
480int in_ascii_range(char c, char lower, char upper);
481
482#define GIT_HASH_LEN 40
483int is_git_sha(char const *hash);
484
485int check_python_package_dependencies(const char *srcdir, struct StrList **out_files, struct StrList **out_matches);
486
487void seconds_to_human_readable(int v, char *result, size_t maxlen);
488
489#define STR_TO_TIMEOUT_NEGATIVE (-1)
490#define STR_TO_TIMEOUT_INVALID_TIME_SCALE (-2)
491int str_to_timeout(char *s);
492
493const char *get_random_generator_file();
494int get_random_bytes(char *result, size_t maxlen);
495
501int non_format_len(const char *s);
502
503char *center_text(const char *s, size_t maxwidth);
504
521int is_file_compressed(const char *filename);
522#endif //STASIS_UTILS_H
Definition system.h:19
Definition strlist.h:16
int non_format_len(const char *s)
Definition utils.c:1223
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:799
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
int grow(size_t size_new, size_t *size_orig, char **data)
Definition utils.c:988
char * xmkstemp(FILE **fp, const char *mode)
Definition utils.c:501
int is_git_assumed_unchanged(char *filename)
Definition utils.c:1326
char * remove_extras(char *s)
Definition str.c:738
int fix_tox_conf(const char *filename, char **result, size_t maxlen)
Definition utils.c:675
long get_cpu_count()
Definition utils.c:858
int rmtree(char *_path)
Definition utils.c:35
char * expandpath(const char *_path)
Definition utils.c:77
int gen_file_extension_str(char *filename, size_t maxlen, const char *extension)
Definition utils.c:939
int env_manipulate_pathstr(const char *key, char *path, int mode)
Definition utils.c:892
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:766
char * git_rev_parse(const char *path, char *args)
Definition utils.c:395
int is_file_compressed(const char *filename)
Definition utils.c:1274
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:866
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:829
char * path_dirname(char *path)
Definition utils.c:150