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
| /*
double_whitespaces:
Copy the "msg" buffer of size "size" into the "dest" buffer,
while doubling any blank character found in the source buffer.
*/
int double_whitespaces(char *msg, int size, char *dest) {
int ret;
char *ptr;
char *buf;
buf = malloc(size);
ptr = msg;
while (ptr < msg + size) {
if (*ptr == '%') // % char is forbidden
goto error;
if (*ptr == ' ') {
*buf++ = ' ';
*buf++ = ' ';
} else {
*buf++ = *ptr;
}
ptr++;
}
free(buf);
strcpy(dest, buf);
return 0;
error:
return -1;
} |
Partager