Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-10-24 00:37:50 -0500
committerDan McGee <dan@archlinux.org>2007-10-24 00:37:50 -0500
commit581769b72d882fdc05bdbdc588db97187329e5b5 (patch)
treef5aac2f8e61b70240621261e4032d2c30f43eff3
parentaa545f6798e526dfd23779b488a86296d1f52d12 (diff)
Add strndup implemention for environments that are missing it
Signed-off-by: Dan McGee <dan@archlinux.org>
-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: */