aboutsummaryrefslogtreecommitdiff
path: root/packages/patches/strtokcpy-0.41.0-test10.patch
blob: aa16779329ae7a516ae146bbb70a5ef85e53bf59 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
Index: s_path.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/s_path.c,v
retrieving revision 1.11
diff -u -u -r1.11 s_path.c
--- s_path.c	8 Sep 2006 23:45:31 -0000	1.11
+++ s_path.c	17 Dec 2007 14:54:32 -0000
@@ -64,21 +64,29 @@
 
 /*******************  Utility functions used below ******************/
 
-/* copy until delimiter and return position after delimiter in string */
-/* if it was the last substring, return NULL */
+/*!
+ * \brief copy until delimiter
+ * 
+ * \arg to destination buffer
+ * \arg to_len destination buffer length
+ * \arg from source buffer
+ * \arg delim string delimiter to stop copying on
+ *
+ * \return position after delimiter in string.  If it was the last
+ *         substring, return NULL.
+ */
+static const char *strtokcpy(char *to, size_t to_len, const char *from, char delim)
+{
+    unsigned int i = 0;
+
+	for (; i < (to_len - 1) && from[i] && from[i] != delim; i++)
+		to[i] = from[i];
+	to[i] = '\0';
 
-static const char* strtokcpy(char *to, const char *from, int delim)
-{
-    int size = 0;
-
-    while (from[size] != (char)delim && from[size] != '\0')
-        size++;
+	if (i && from[i] != '\0')
+		return from + i + 1;
 
-    strncpy(to,from,size);
-    to[size] = '\0';
-    if (from[size] == '\0') return NULL;
-    if (size) return from+size+1;
-    else return NULL;
+	return NULL;
 }
 
 /* add a single item to a namelist.  If "allowdup" is true, duplicates
@@ -126,7 +134,7 @@
     npos = s;
     do
     {
-        npos = strtokcpy(temp, npos, SEPARATOR);
+        npos = strtokcpy(temp, sizeof(temp), npos, SEPARATOR);
         if (! *temp) continue;
         nl = namelist_append(nl, temp, 0);
     }