From 459e2685158f1dc5a9cd3da1c3125889bc02f9d6 Mon Sep 17 00:00:00 2001 From: gayot_o Date: Tue, 19 Nov 2013 02:43:27 +0000 Subject: mplayer_server: first version of the server --- escape.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 escape.c (limited to 'escape.c') diff --git a/escape.c b/escape.c new file mode 100644 index 0000000..be801e2 --- /dev/null +++ b/escape.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +#include "request.h" + +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; +} -- cgit v1.2.3