83 new_sstr.length = length; |
83 new_sstr.length = length; |
84 return new_sstr; |
84 return new_sstr; |
85 } |
85 } |
86 |
86 |
87 int sstrcmp(sstr_t s1, sstr_t s2) { |
87 int sstrcmp(sstr_t s1, sstr_t s2) { |
88 return strncmp(s1.ptr, s2.ptr, s1.length>s2.length ? s2.length: s1.length); |
88 return memcmp(s1.ptr, s2.ptr, s1.length>s2.length ? s2.length: s1.length); |
89 } |
89 } |
90 |
90 |
91 sstr_t sstrdub(sstr_t s) { |
91 sstr_t sstrdub(sstr_t s) { |
92 sstr_t newstring; |
92 sstr_t newstring; |
93 newstring.ptr = malloc(s.length + 1); |
93 newstring.ptr = malloc(s.length + 1); |
94 newstring.length = s.length; |
94 newstring.length = s.length; |
95 newstring.ptr[newstring.length] = 0; |
95 newstring.ptr[newstring.length] = 0; |
96 |
96 |
97 memcpy(newstring.ptr, s.ptr, s.length); |
97 memcpy(newstring.ptr, s.ptr, s.length); |
98 |
98 |
99 return newstring; |
99 return newstring; |
100 } |
100 } |
101 |
101 |
102 |
102 |
103 // webserver extension |
103 // webserver extension |
123 } |
123 } |
124 } |
124 } |
125 return newstr; |
125 return newstr; |
126 } |
126 } |
127 |
127 |
128 sstr_t sstrdub_mp(UcxMempool *mp, sstr_t s) { |
128 sstr_t sstrdup_mp(UcxMempool *mp, sstr_t s) { |
129 sstr_t newstring; |
129 sstr_t newstring; |
130 newstring.ptr = ucx_mempool_malloc(mp, s.length + 1); |
130 newstring.ptr = ucx_mempool_malloc(mp, s.length + 1); |
131 newstring.length = s.length; |
131 newstring.length = s.length; |
132 newstring.ptr[newstring.length] = 0; |
132 newstring.ptr[newstring.length] = 0; |
133 |
133 |
134 /* TODO: sometimes memcpy and/or memmove destroy the source */ |
134 /* TODO: sometimes memcpy and/or memmove destroy the source */ |
135 //memcpy(newstring.ptr, s.ptr, s.length); |
135 memcpy(newstring.ptr, s.ptr, s.length); |
136 for(int i=0;i<s.length;i++) { |
|
137 newstring.ptr[i] = s.ptr[i]; |
|
138 } |
|
139 |
136 |
140 return newstring; |
137 return newstring; |
141 } |
138 } |