20 #ifndef __C_CREATEREPOLIB_MISC_H__
21 #define __C_CREATEREPOLIB_MISC_H__
29 #include <curl/curl.h>
30 #include "compression_wrapper.h"
31 #include "xml_parser.h"
40 #define CR_STATICSTRLEN(s) (sizeof(s)/sizeof(s[0]))
44 #define CR_ARRAYLEN(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
110 static inline int cr_is_primary(
const char *filename) {
111 if (!strncmp(filename,
"/etc/", 5))
113 if (!strcmp(filename,
"/usr/lib/sendmail"))
115 if (strstr(filename,
"bin/"))
152 const char *destination,
174 #define cr_compress_file(SRC, DST, COMTYPE, ERR) \
175 cr_compress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
203 #define cr_decompress_file(SRC, DST, COMTYPE, ERR) \
204 cr_decompress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
267 GLogLevelFlags log_level,
268 const gchar *message,
278 GLogLevelFlags log_level,
279 const gchar *message,
316 #define cr_cmp_nevra(A, B) (cr_cmp_evr((A)->epoch, (A)->version, (A)->release,\
317 (B)->epoch, (B)->version, (B)->release))
328 int cr_cmp_evr(
const char *e1,
const char *v1,
const char *r1,
329 const char *e2,
const char *v2,
const char *r2);
337 static inline gchar *
338 cr_safe_string_chunk_insert(GStringChunk *chunk,
const char *str)
340 if (!str)
return NULL;
341 return g_string_chunk_insert(chunk, str);
349 static inline gchar *
350 cr_safe_string_chunk_insert_and_free(GStringChunk *chunk,
char *str)
352 if (!str)
return NULL;
353 gchar *copy = g_string_chunk_insert(chunk, str);
364 static inline gchar *
365 cr_safe_string_chunk_insert_null(GStringChunk *chunk,
const char *str)
367 if (!str || *str ==
'\0')
return NULL;
368 return g_string_chunk_insert(chunk, str);
377 static inline gchar *
378 cr_safe_string_chunk_insert_const(GStringChunk *chunk,
const char *str)
380 if (!str)
return NULL;
381 return g_string_chunk_insert_const(chunk, str);
384 static inline gboolean
385 cr_key_file_get_boolean_default(GKeyFile *key_file,
386 const gchar *group_name,
388 gboolean default_value,
391 GError *tmp_err = NULL;
392 gboolean ret = g_key_file_get_boolean(key_file, group_name, key, &tmp_err);
394 g_propagate_error(error, tmp_err);
395 return default_value;
437 cr_cp(
const char *src,
440 const char *working_directory,
459 cr_rm(
const char *path,
461 const char *working_dir,
gchar * cr_append_pid_and_datetime(const char *str, const char *suffix)
cr_NEVRA * cr_str_to_nevra(const char *str)
char * cr_normalize_dir_path(const char *path)
gboolean cr_copy_file(const char *src, const char *dst, GError **err)
void cr_nevra_free(cr_NEVRA *nevra)
int cr_cmp_evr(const char *e1, const char *v1, const char *r1, const char *e2, const char *v2, const char *r2)
int cr_warning_cb(cr_XmlParserWarningType type, char *msg, void *cbdata, GError **err)
struct cr_HeaderRangeStruct cr_get_header_byte_range(const char *filename, GError **err)
cr_EVR * cr_str_to_evr(const char *string, GStringChunk *chunk)
struct cr_Version cr_str_to_version(const char *str)
void cr_null_log_fn(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
void cr_queue_free_full(GQueue *queue, GDestroyNotify free_f)
int cr_cmp_version_str(const char *str1, const char *str2)
void cr_evr_free(cr_EVR *evr)
gboolean cr_rm(const char *path, cr_RmFlags flags, const char *working_dir, GError **err)
void cr_log_fn(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
cr_NEVRA * cr_split_rpm_filename(const char *filename)
gboolean cr_better_copy_file(const char *src, const char *dst, GError **err)
gboolean cr_cp(const char *src, const char *dst, cr_CpFlags flags, const char *working_directory, GError **err)
gboolean cr_spawn_check_exit_status(gint exit_status, GError **error)
gchar * cr_cut_dirs(gchar *path, gint cut_dirs)
int cr_compress_file_with_stat(const char *src, const char *dst, cr_CompressionType comtype, cr_ContentStat *stat, GError **err)
char * cr_get_filename(const char *filepath)
gboolean cr_write_to_file(GError **err, gchar *filename, const char *format,...)
int cr_remove_dir(const char *path, GError **err)
const char * cr_flag_to_str(gint64 flags)
cr_NEVR * cr_str_to_nevr(const char *str)
int cr_decompress_file_with_stat(const char *src, const char *dst, cr_CompressionType comtype, cr_ContentStat *stat, GError **err)
int cr_download(CURL *handle, const char *url, const char *destination, GError **err)
gboolean cr_identical_files(const gchar *fn1, const gchar *fn2, gboolean *identical, GError **err)
void cr_nevr_free(cr_NEVR *nevr)
void cr_slist_free_full(GSList *list, GDestroyNotify free_f)