summaryrefslogtreecommitdiff
path: root/data/ipkg/strndup.diff
blob: 88e742e7fda294fdd80581195a9d3acb7be301d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff -ru ipkg-0.99.163/ipkg_conf.c ipkg-0.99.163+iPhone/ipkg_conf.c
--- ipkg-0.99.163/ipkg_conf.c	2006-04-17 22:20:44.000000000 +0000
+++ ipkg-0.99.163+iPhone/ipkg_conf.c	2009-06-12 00:16:22.000000000 +0000
@@ -28,6 +28,26 @@
 #include "str_util.h"
 #include "xsystem.h"
 
+#ifndef HAVE_STRNDUP
+char *
+strndup (const char *string, size_t length)
+{
+    char *result;
+    
+    if ((int)strlen (string) < length)
+        return strdup (string);
+    
+    result = (char *)malloc (length + 1);
+    if (!result)
+        return NULL;
+    
+    memcpy (result, string, length);
+    result[length] = '\0';
+    
+    return result;
+}
+#endif
+
 static int ipkg_conf_parse_file(ipkg_conf_t *conf, const char *filename,
 				pkg_src_list_t *pkg_src_list,
 				nv_pair_list_t *tmp_dest_nv_pair_list,