46 sstr_t str = va_arg (ap, sstr_t); |
47 sstr_t str = va_arg (ap, sstr_t); |
47 while (str.ptr != NULL) { |
48 while (str.ptr != NULL) { |
48 s.ptr = strncat (s.ptr, str.ptr, s.length); |
49 s.ptr = strncat (s.ptr, str.ptr, s.length); |
49 str = va_arg (ap, sstr_t); |
50 str = va_arg (ap, sstr_t); |
50 } |
51 } |
|
52 va_end(ap); |
51 |
53 |
52 return s; |
54 return s; |
53 } |
55 } |
54 |
56 |
55 sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...) { |
57 sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...) { |
60 s.ptr = strncat (s.ptr, c1.ptr, s.length); |
62 s.ptr = strncat (s.ptr, c1.ptr, s.length); |
61 for (int i=0;i<n-1;i++) { |
63 for (int i=0;i<n-1;i++) { |
62 sstr_t str = va_arg (ap, sstr_t); |
64 sstr_t str = va_arg (ap, sstr_t); |
63 s.ptr = strncat (s.ptr, str.ptr, s.length); |
65 s.ptr = strncat (s.ptr, str.ptr, s.length); |
64 } |
66 } |
|
67 va_end(ap); |
65 |
68 |
66 return s; |
69 return s; |
67 } |
70 } |
68 |
71 |
69 sstr_t sstrsubs (sstr_t s, size_t start) { |
72 sstr_t sstrsubs (sstr_t s, size_t start) { |
87 return strncmp(s1.ptr, s2.ptr, s1.length>s2.length ? s2.length: s1.length); |
90 return strncmp(s1.ptr, s2.ptr, s1.length>s2.length ? s2.length: s1.length); |
88 } |
91 } |
89 |
92 |
90 sstr_t sstrdub(sstr_t s) { |
93 sstr_t sstrdub(sstr_t s) { |
91 sstr_t newstring; |
94 sstr_t newstring; |
92 newstring.ptr = malloc(s.length + 1); |
95 newstring.ptr = (char*) malloc(s.length + 1); |
93 newstring.length = s.length; |
96 if (newstring.ptr != NULL) { |
94 newstring.ptr[newstring.length] = 0; |
97 newstring.length = s.length; |
|
98 newstring.ptr[newstring.length] = 0; |
95 |
99 |
96 memcpy(newstring.ptr, s.ptr, s.length); |
100 memcpy(newstring.ptr, s.ptr, s.length); |
|
101 } |
97 |
102 |
98 return newstring; |
103 return newstring; |
99 } |
104 } |