summaryrefslogtreecommitdiffstats
path: root/strndup.h
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-31 23:12:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-31 23:14:56 -0700
commite84d8624bb1790ae46d3c7a7b642effb9090b65d (patch)
treecc565f9b92c7244f0ff5fb6429b5ce33faf0dab0 /strndup.h
parent5bbcc7f16ddb1315dbd4a7a43034cddf8c9f2a36 (diff)
downloadsubsurface-e84d8624bb1790ae46d3c7a7b642effb9090b65d.tar.gz
Add strndup.h header so we can use this useful function
It's missing on Windows... we had this helper in liquivision.c but since I used the function in git-access.c I figured I should just turn it into a little helper. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'strndup.h')
-rw-r--r--strndup.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/strndup.h b/strndup.h
new file mode 100644
index 000000000..84e18b60f
--- /dev/null
+++ b/strndup.h
@@ -0,0 +1,21 @@
+#ifndef STRNDUP_H
+#define STRNDUP_H
+#if __WIN32__
+static char *strndup (const char *s, size_t n)
+{
+ char *cpy;
+ size_t len = strlen(s);
+ if (n < len)
+ len = n;
+ if ((cpy = malloc(len + 1)) !=
+ NULL) {
+ cpy[len] =
+ '\0';
+ memcpy(cpy,
+ s,
+ len);
+ }
+ return cpy;
+}
+#endif
+#endif /* STRNDUP_H */