summaryrefslogtreecommitdiff
path: root/escape.c
diff options
context:
space:
mode:
authorgayot_o <gayot_o@localhost>2013-11-19 02:43:27 +0000
committergayot_o <gayot_o@localhost>2013-11-19 02:45:46 +0000
commit459e2685158f1dc5a9cd3da1c3125889bc02f9d6 (patch)
treed4a205fed05e69d1184da0e76f1fb9ac49e06e43 /escape.c
parentb0155666fbbb6c4105c36ffcddb894d7d21e38ae (diff)
mplayer_server: first version of the server
Diffstat (limited to 'escape.c')
-rw-r--r--escape.c35
1 files changed, 35 insertions, 0 deletions
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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#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;
+}