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_UNUSED(x) (void)(x)
44 #define CR_STATICSTRLEN(s) (sizeof(s)/sizeof(s[0]))
48 #define CR_ARRAYLEN(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
114 static inline int cr_is_primary(
const char *filename) {
115 if (!strncmp(filename,
"/etc/", 5))
117 if (!strcmp(filename,
"/usr/lib/sendmail"))
119 if (strstr(filename,
"bin/"))
156 const char *destination,
178 #define cr_compress_file(SRC, DST, COMTYPE, ERR) \
179 cr_compress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
207 #define cr_decompress_file(SRC, DST, COMTYPE, ERR) \
208 cr_decompress_file_with_stat(SRC, DST, COMTYPE, NULL, ERR)
271 GLogLevelFlags log_level,
272 const gchar *message,
282 GLogLevelFlags log_level,
283 const gchar *message,
320 #define cr_cmp_nevra(A, B) (cr_cmp_evr((A)->epoch, (A)->version, (A)->release,\
321 (B)->epoch, (B)->version, (B)->release))
332 int cr_cmp_evr(
const char *e1,
const char *v1,
const char *r1,
333 const char *e2,
const char *v2,
const char *r2);
341 static inline gchar *
342 cr_safe_string_chunk_insert(GStringChunk *chunk,
const char *str)
344 if (!str)
return NULL;
345 return g_string_chunk_insert(chunk, str);
353 static inline gchar *
354 cr_safe_string_chunk_insert_and_free(GStringChunk *chunk,
char *str)
356 if (!str)
return NULL;
357 gchar *copy = g_string_chunk_insert(chunk, str);
368 static inline gchar *
369 cr_safe_string_chunk_insert_null(GStringChunk *chunk,
const char *str)
371 if (!str || *str ==
'\0')
return NULL;
372 return g_string_chunk_insert(chunk, str);
381 static inline gchar *
382 cr_safe_string_chunk_insert_const(GStringChunk *chunk,
const char *str)
384 if (!str)
return NULL;
385 return g_string_chunk_insert_const(chunk, str);
388 static inline gboolean
389 cr_key_file_get_boolean_default(GKeyFile *key_file,
390 const gchar *group_name,
392 gboolean default_value,
395 GError *tmp_err = NULL;
396 gboolean ret = g_key_file_get_boolean(key_file, group_name, key, &tmp_err);
398 g_propagate_error(error, tmp_err);
399 return default_value;
441 cr_cp(
const char *src,
444 const char *working_directory,
463 cr_rm(
const char *path,
465 const char *working_dir,