summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.h
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-19 12:00:39 -0600
committerDan McGee <dan@archlinux.org>2011-01-21 09:14:47 -0600
commitaff3e63c451ead18571a8abed56e911f71906fe6 (patch)
treef04a34a1de11facfc854f567387db8dff030e12f /lib/libalpm/util.h
parentb40c8e292244c497ddb557428b8bd152ed7f0482 (diff)
downloadpacman-aff3e63c451ead18571a8abed56e911f71906fe6.tar.xz
Add strndup fallback function to libalpm util
The same fallback we are currently using in the pacman frontend. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.h')
-rw-r--r--lib/libalpm/util.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index be5c1d9b..015e9bf5 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -50,6 +50,7 @@
#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
/* This strdup macro is NULL safe- copying NULL will yield NULL */
#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)
+#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)
#define FREE(p) do { free(p); p = NULL; } while(0)
@@ -101,6 +102,10 @@ long _alpm_parsedate(const char *line);
char *strsep(char **, const char *);
#endif
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif
+
/* check exported library symbols with: nm -C -D <lib> */
#define SYMEXPORT __attribute__((visibility("default")))
#define SYMHIDDEN __attribute__((visibility("internal")))