]>
git.ipfire.org Git - pakfire.git/blob - src/libpakfire/include/pakfire/util.h
1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2013 Pakfire development team #
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. #
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. #
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/>. #
19 #############################################################################*/
21 #ifndef PAKFIRE_UTIL_H
22 #define PAKFIRE_UTIL_H
24 #ifdef PAKFIRE_PRIVATE
32 #include <pakfire/package.h>
34 const char* pakfire_dep2str(struct pakfire
* pakfire
, Id id
);
35 Id
pakfire_str2dep(struct pakfire
* pakfire
, const char* s
);
36 void pakfire_str2deps(struct pakfire
* pakfire
, struct pakfire_package
* pkg
,
37 void (*func
)(struct pakfire_package
* pkg
, const char* dep
), const char* deps
);
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)
42 int pakfire_string_startswith(const char* s
, const char* prefix
);
43 int pakfire_string_endswith(const char* s
, const char* suffix
);
44 int pakfire_string_matches(const char* s
, const char* pattern
);
45 char* pakfire_unquote_in_place(char* s
);
46 int pakfire_string_partition(const char* s
, const char* delim
, char** s1
, char** s2
);
47 char* pakfire_string_replace(const char* s
, const char* pattern
, const char* repl
);
48 char** pakfire_split_string(const char* s
, char delim
);
49 char* pakfire_string_join(char** list
, const char* delim
);
51 int pakfire_format_size(char* dst
, size_t length
, double value
);
52 int pakfire_format_speed(char* dst
, size_t length
, double value
);
53 char* pakfire_format_date(time_t t
);
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)));;
60 int pakfire_path_exists(const char* path
);
61 time_t pakfire_path_age(const char* path
);
63 char* pakfire_basename(const char* path
);
64 char* pakfire_dirname(const char* path
);
66 char* pakfire_remove_trailing_newline(char* str
);
68 int pakfire_read_file_into_buffer(FILE* f
, char** buffer
, size_t* len
);
70 #define pakfire_hexlify(digest) __pakfire_hexlify(digest, sizeof(digest))
71 char* __pakfire_hexlify(const unsigned char* digest
, const size_t length
);
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
);
75 #define pakfire_path_join(dest, first, second) \
76 __pakfire_path_join(dest, sizeof(dest) - 1, first, second)
78 int __pakfire_path_join(char* dest
, size_t length
,
79 const char* first
, const char* second
);
80 const char* pakfire_path_relpath(const char* root
, const char* path
);
82 int pakfire_mkparentdir(const char* path
, mode_t mode
);
83 int pakfire_mkdir(const char* path
, mode_t mode
);
84 FILE* pakfire_mktemp(char* path
);
85 char* pakfire_mkdtemp(char* path
);
86 int pakfire_rmtree(const char* path
, int flags
);
88 char* pakfire_generate_uuid();
90 int pakfire_tty_is_noninteractive(void);
94 size_t pakfire_digest_length(enum pakfire_digests digest
);
98 int pakfire_archive_copy_data(struct archive
* src
, struct archive
* dst
,
99 struct archive_entry
* entry
);
100 int pakfire_archive_copy_data_to_buffer(struct pakfire
* pakfire
, struct archive
* a
,
101 struct archive_entry
* entry
, char** data
, size_t* data_size
);
105 struct json_object
* pakfire_json_parse_from_file(struct pakfire
* pakfire
, const char* path
);
109 struct timespec
timespec_add(const struct timespec
* t1
, const struct timespec
* t2
);
111 struct timespec
timespec_from_ms(int milliseconds
);
113 int timespec_lt(struct timespec
* t1
, struct timespec
* t2
);
117 #define PAKFIRE_RLIMIT_NOFILE_MAX (512 * 1024)
119 int pakfire_rlimit_set(struct pakfire
* pakfire
, int limit
);
120 int pakfire_rlimit_reset_nofile(struct pakfire
* pakfire
);
124 #endif /* PAKFIRE_UTIL_H */