ucx/string.c

changeset 87
bd444539cced
parent 71
303dabadff1c
child 95
ecfdc1c4a552
equal deleted inserted replaced
86:55bf819cbc88 87:bd444539cced
159 } 159 }
160 160
161 sstr_t sstrdup(sstr_t s) { 161 sstr_t sstrdup(sstr_t s) {
162 sstr_t newstring; 162 sstr_t newstring;
163 newstring.ptr = (char*) malloc(s.length + 1); 163 newstring.ptr = (char*) malloc(s.length + 1);
164 if (newstring.ptr != NULL) { 164 if (newstring.ptr) {
165 newstring.length = s.length; 165 newstring.length = s.length;
166 newstring.ptr[newstring.length] = 0; 166 newstring.ptr[newstring.length] = 0;
167 167
168 memcpy(newstring.ptr, s.ptr, s.length); 168 memcpy(newstring.ptr, s.ptr, s.length);
169 } else {
170 newstring.length = 0;
169 } 171 }
170 172
171 return newstring; 173 return newstring;
172 } 174 }

mercurial