Remove ALPM_LOG_FUNC macro
[pacman-ng.git] / lib / libalpm / util.h
blob776cee4d84afe51117bfb5e46d8a2dea91006087
1 /*
2 * util.h
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
9 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef _ALPM_UTIL_H
25 #define _ALPM_UTIL_H
27 #include "config.h"
29 #include "alpm_list.h"
30 #include "package.h" /* pmpkg_t */
32 #include <stdio.h>
33 #include <string.h>
34 #include <stdarg.h>
35 #include <stddef.h> /* size_t */
36 #include <time.h>
37 #include <sys/stat.h> /* struct stat */
38 #include <archive.h> /* struct archive */
39 #include <math.h> /* fabs */
40 #include <float.h> /* DBL_EPSILON */
42 #ifdef ENABLE_NLS
43 #include <libintl.h> /* here so it doesn't need to be included elsewhere */
44 /* define _() as shortcut for gettext() */
45 #define _(str) dgettext ("libalpm", str)
46 #else
47 #define _(s) s
48 #endif
50 #define ALLOC_FAIL(s) do { _alpm_log(PM_LOG_ERROR, _("alloc failure: could not allocate %zd bytes\n"), s); } while(0)
52 #define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
53 #define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
54 /* This strdup macro is NULL safe- copying NULL will yield NULL */
55 #define STRDUP(r, s, action) do { if(s != NULL) { r = strdup(s); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
56 #define STRNDUP(r, s, l, action) do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
58 #define FREE(p) do { free(p); p = NULL; } while(0)
60 #define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)
62 #define RET_ERR_VOID(err) do { pm_errno = (err); \
63 _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
64 return; } while(0)
66 #define RET_ERR(err, ret) do { pm_errno = (err); \
67 _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
68 return (ret); } while(0)
70 #define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
72 /**
73 * Used as a buffer/state holder for _alpm_archive_fgets().
75 struct archive_read_buffer {
76 char *line;
77 char *line_offset;
78 size_t line_size;
79 size_t max_line_size;
81 char *block;
82 char *block_offset;
83 size_t block_size;
85 int ret;
88 int _alpm_makepath(const char *path);
89 int _alpm_makepath_mode(const char *path, mode_t mode);
90 int _alpm_copyfile(const char *src, const char *dest);
91 char *_alpm_strtrim(char *str);
92 int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn);
93 int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst);
94 int _alpm_rmrf(const char *path);
95 int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
96 int _alpm_run_chroot(const char *root, const char *path, char *const argv[]);
97 int _alpm_ldconfig(const char *root);
98 int _alpm_str_cmp(const void *s1, const void *s2);
99 char *_alpm_filecache_find(const char *filename);
100 const char *_alpm_filecache_setup(void);
101 int _alpm_lstat(const char *path, struct stat *buf);
102 int _alpm_test_md5sum(const char *filepath, const char *md5sum);
103 int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b);
104 int _alpm_splitname(const char *target, pmpkg_t *pkg);
105 unsigned long _alpm_hash_sdbm(const char *str);
106 long _alpm_parsedate(const char *line);
108 #ifndef HAVE_STRSEP
109 char *strsep(char **, const char *);
110 #endif
112 #ifndef HAVE_STRNDUP
113 char *strndup(const char *s, size_t n);
114 #endif
116 /* check exported library symbols with: nm -C -D <lib> */
117 #define SYMEXPORT __attribute__((visibility("default")))
118 #define SYMHIDDEN __attribute__((visibility("internal")))
120 #define UNUSED __attribute__((unused))
122 #endif /* _ALPM_UTIL_H */
124 /* vim: set ts=2 sw=2 noet: */