]>
Commit | Line | Data |
---|---|---|
221cc3ce MT |
1 | /*############################################################################# |
2 | # # | |
3 | # Pakfire - The IPFire package management system # | |
4 | # Copyright (C) 2013 Pakfire development team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
21 | #ifndef PAKFIRE_UTIL_H | |
22 | #define PAKFIRE_UTIL_H | |
23 | ||
be11aa6e MT |
24 | #ifdef PAKFIRE_PRIVATE |
25 | ||
a566ff7f | 26 | #include <stdio.h> |
ab96da22 | 27 | #include <time.h> |
a566ff7f | 28 | |
88124868 MT |
29 | #include <archive.h> |
30 | ||
9bddb328 | 31 | |
31480bee | 32 | #include <pakfire/package.h> |
ab96da22 | 33 | |
72e05cd7 | 34 | const char* pakfire_dep2str(struct pakfire* pakfire, Id id); |
ac4c607b MT |
35 | Id pakfire_parse_dep(struct pakfire* pakfire, const char* s); |
36 | void pakfire_parse_deps(struct pakfire* pakfire, struct pakfire_package* pkg, | |
31480bee | 37 | void (*func)(struct pakfire_package* pkg, const char* dep), const char* deps); |
9bddb328 | 38 | |
a7d38ba6 MT |
39 | #define pakfire_string_format(s, fmt, ...) snprintf(s, sizeof(s) - 1, fmt, __VA_ARGS__) |
40 | #define pakfire_string_set(s, value) pakfire_string_format(s, "%s", value) | |
5c76be2c | 41 | |
714c91a2 | 42 | int pakfire_string_startswith(const char* s, const char* prefix); |
be11aa6e | 43 | int pakfire_string_endswith(const char* s, const char* suffix); |
f4d93071 | 44 | int pakfire_string_matches(const char* s, const char* pattern); |
5c76be2c | 45 | char* pakfire_unquote_in_place(char* s); |
89dbb9ac | 46 | int pakfire_string_partition(const char* s, const char* delim, char** s1, char** s2); |
8de06755 | 47 | char* pakfire_string_replace(const char* s, const char* pattern, const char* repl); |
603ca1e0 | 48 | char** pakfire_split_string(const char* s, char delim); |
1eb7f40b | 49 | char* pakfire_string_join(char** list, const char* delim); |
be11aa6e | 50 | |
cc90545a | 51 | int pakfire_format_size(char* dst, size_t length, double value); |
68d26a6a | 52 | int pakfire_format_speed(char* dst, size_t length, double value); |
2843d2da MT |
53 | char* pakfire_format_date(time_t t); |
54 | ||
5f2ed202 MT |
55 | #define pakfire_strftime_now(dest, format) \ |
56 | __pakfire_strftime_now(dest, sizeof(dest) - 1, format) | |
57 | int __pakfire_strftime_now(char* dest, size_t length, const char* format) | |
58 | __attribute__((format(strftime, 3, 0)));; | |
59 | ||
8c22118b | 60 | int pakfire_path_exists(const char* path); |
a5e9cd4b | 61 | time_t pakfire_path_age(const char* path); |
8c22118b | 62 | |
05e8d3c9 | 63 | char* pakfire_basename(const char* path); |
41a7a52f | 64 | char* pakfire_dirname(const char* path); |
05e8d3c9 | 65 | |
2843d2da MT |
66 | char* pakfire_remove_trailing_newline(char* str); |
67 | ||
a566ff7f MT |
68 | int pakfire_read_file_into_buffer(FILE* f, char** buffer, size_t* len); |
69 | ||
01f8f6b0 | 70 | #define pakfire_hexlify(digest) __pakfire_hexlify(digest, sizeof(digest)) |
fa106e1b | 71 | char* __pakfire_hexlify(const unsigned char* digest, const size_t length); |
01f8f6b0 MT |
72 | #define pakfire_unhexlify(dst, src) __pakfire_unhexlify(dst, sizeof(dst), src) |
73 | int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src); | |
7ab0465c | 74 | |
99865093 MT |
75 | #define pakfire_path_join(dest, first, second) \ |
76 | __pakfire_path_join(dest, sizeof(dest) - 1, first, second) | |
77 | ||
78 | int __pakfire_path_join(char* dest, size_t length, | |
384d009a | 79 | const char* first, const char* second); |
36790d86 | 80 | const char* pakfire_path_relpath(const char* root, const char* path); |
2843d2da | 81 | |
a29c7190 | 82 | int pakfire_mkparentdir(const char* path, mode_t mode); |
4d47c163 | 83 | int pakfire_mkdir(const char* path, mode_t mode); |
62b60e37 | 84 | FILE* pakfire_mktemp(char* path); |
e75d1e3c MT |
85 | char* pakfire_mkdtemp(char* path); |
86 | int pakfire_rmtree(const char* path, int flags); | |
62b60e37 | 87 | |
ab96da22 MT |
88 | char* pakfire_generate_uuid(); |
89 | ||
457feacb MT |
90 | int pakfire_tty_is_noninteractive(void); |
91 | ||
f5aee1e4 MT |
92 | // Digests |
93 | ||
94 | size_t pakfire_digest_length(enum pakfire_digests digest); | |
95 | ||
88124868 MT |
96 | // Archive Stuff |
97 | ||
98 | int pakfire_archive_copy_data(struct archive* src, struct archive* dst, | |
99 | struct archive_entry* entry); | |
ac4c607b | 100 | int pakfire_archive_copy_data_to_buffer(struct pakfire* pakfire, struct archive* a, |
53f5745e | 101 | struct archive_entry* entry, char** data, size_t* data_size); |
88124868 | 102 | |
0351af83 MT |
103 | // JSON Stuff |
104 | ||
ac4c607b | 105 | struct json_object* pakfire_json_parse_from_file(struct pakfire* pakfire, const char* path); |
0351af83 | 106 | |
563e9600 MT |
107 | // Time Stuff |
108 | ||
109 | struct timespec timespec_add(const struct timespec* t1, const struct timespec* t2); | |
110 | ||
111 | struct timespec timespec_from_ms(int milliseconds); | |
112 | ||
113 | int timespec_lt(struct timespec* t1, struct timespec* t2); | |
114 | ||
6582a143 MT |
115 | // Resource Limits |
116 | ||
117 | #define PAKFIRE_RLIMIT_NOFILE_MAX (512 * 1024) | |
118 | ||
ac4c607b MT |
119 | int pakfire_rlimit_set(struct pakfire* pakfire, int limit); |
120 | int pakfire_rlimit_reset_nofile(struct pakfire* pakfire); | |
6582a143 | 121 | |
be11aa6e MT |
122 | #endif |
123 | ||
221cc3ce | 124 | #endif /* PAKFIRE_UTIL_H */ |