summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pacman/util.c22
-rw-r--r--src/pacman/util.h4
2 files changed, 26 insertions, 0 deletions
diff --git a/src/pacman/util.c b/src/pacman/util.c
index e182f38f..ecdb2ad8 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -515,4 +515,26 @@ int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list ar
return(ret);
}
+#ifndef HAVE_STRNDUP
+/* A quick and dirty implementation derived from glibc */
+static size_t strnlen(const char *s, size_t max)
+{
+ register const char *p;
+ for(p = s; *p && max--; ++p);
+ return(p - s);
+}
+
+char *strndup(const char *s, size_t n)
+{
+ size_t len = strnlen(s, n);
+ char *new = (char *) malloc(len + 1);
+
+ if (new == NULL)
+ return NULL;
+
+ new[len] = '\0';
+ return (char *) memcpy(new, s, len);
+}
+#endif
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 2814a780..4d17b179 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -53,6 +53,10 @@ int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format
int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
+#ifndef HAVE_STRNDUP
+char *strndup(const char *s, size_t n);
+#endif
+
#endif /* _PM_UTIL_H */
/* vim: set ts=2 sw=2 noet: */