Always specify arguement type in function delcarations
[pacman-ng.git] / lib / libalpm / util.h
blob5464b239ce80c464ef9f38209a3c7eaea8d1e339
1 /*
2 * util.h
4 * Copyright (c) 2006-2010 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 <time.h>
36 #include <sys/stat.h> /* struct stat */
37 #include <archive.h> /* struct archive */
39 #ifdef ENABLE_NLS
40 #include <libintl.h> /* here so it doesn't need to be included elsewhere */
41 /* define _() as shortcut for gettext() */
42 #define _(str) dgettext ("libalpm", str)
43 #else
44 #define _(s) s
45 #endif
47 #define ALLOC_FAIL(s) do { _alpm_log(PM_LOG_ERROR, _("alloc failure: could not allocate %zd bytes\n"), s); } while(0)
49 #define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
50 #define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
51 /* This strdup macro is NULL safe- copying NULL will yield NULL */
52 #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)
54 #define FREE(p) do { free(p); p = NULL; } while(0)
56 #define ASSERT(cond, action) do { if(!(cond)) { action; } } while(0)
58 #define RET_ERR(err, ret) do { pm_errno = (err); \
59 _alpm_log(PM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerrorlast()); \
60 return(ret); } while(0)
62 int _alpm_makepath(const char *path);
63 int _alpm_makepath_mode(const char *path, mode_t mode);
64 int _alpm_copyfile(const char *src, const char *dest);
65 char *_alpm_strtrim(char *str);
66 int _alpm_lckmk(void);
67 int _alpm_lckrm(void);
68 int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn);
69 int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst);
70 int _alpm_rmrf(const char *path);
71 int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
72 int _alpm_run_chroot(const char *root, const char *path, char *const argv[]);
73 int _alpm_ldconfig(const char *root);
74 int _alpm_str_cmp(const void *s1, const void *s2);
75 char *_alpm_filecache_find(const char *filename);
76 const char *_alpm_filecache_setup(void);
77 int _alpm_lstat(const char *path, struct stat *buf);
78 int _alpm_test_md5sum(const char *filepath, const char *md5sum);
79 char *_alpm_archive_fgets(char *line, size_t size, struct archive *a);
80 int _alpm_splitname(const char *target, pmpkg_t *pkg);
81 unsigned long _alpm_hash_sdbm(const char *str);
83 #ifndef HAVE_STRSEP
84 char *strsep(char **, const char *);
85 #endif
87 /* check exported library symbols with: nm -C -D <lib> */
88 #define SYMEXPORT __attribute__((visibility("default")))
89 #define SYMHIDDEN __attribute__((visibility("internal")))
91 #endif /* _ALPM_UTIL_H */
93 /* vim: set ts=2 sw=2 noet: */