- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
char *real_escape_string(const byte *src, int size)
{
    char *escaped;
    char *pos;
    if (memchr(src, '\0', size - 1) || memchr(src, '\n', size) || memchr(src, '\r', size)) {
	fprintf(stderr, "cannot handle this string\n");
	return NULL;
    }
    pos = escaped = malloc(sizeof(char) * (size * 2 + 1));
    if (escaped == NULL) {
	fprintf(stderr, "malloc failed: %m\n");
	return NULL;
    }
    for (int i = 0; i < size; ++i) {
	if (!isalnum(src[i])) {
	    *escaped++ = '\\';
	}
	*escaped++ = src[i];
    }
    *escaped = '\0';
    return pos;
}
                                 
        
Комментарии (0) RSS
Добавить комментарий