]> git.saurik.com Git - redis.git/blobdiff - src/sds.c
use timeout 0 by default, as this is a common source of problems.
[redis.git] / src / sds.c
index 2ec7c3cb76b3a2d6f5afdb3be8bd6aa793329a1c..2104eb36b9b9fe9475f1a2b8165b24a8e769481a 100644 (file)
--- a/src/sds.c
+++ b/src/sds.c
@@ -94,6 +94,13 @@ void sdsupdatelen(sds s) {
     sh->len = reallen;
 }
 
+void sdsclear(sds s) {
+    struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
+    sh->free += sh->len;
+    sh->len = 0;
+    sh->buf[0] = '\0';
+}
+
 static sds sdsMakeRoomFor(sds s, size_t addlen) {
     struct sdshdr *sh, *newsh;
     size_t free = sdsavail(s);
@@ -470,7 +477,8 @@ sds *sdssplitargs(char *line, int *argc) {
         while(*p && isspace(*p)) p++;
         if (*p) {
             /* get a token */
-            int inq=0; /* set to 1 if we are in "quotes" */
+            int inq=0;  /* set to 1 if we are in "quotes" */
+            int insq=0; /* set to 1 if we are in 'single quotes' */
             int done=0;
 
             if (current == NULL) current = sdsempty();
@@ -500,7 +508,23 @@ sds *sdssplitargs(char *line, int *argc) {
                         }
                         current = sdscatlen(current,&c,1);
                     } else if (*p == '"') {
-                        /* closing quote must be followed by a space */
+                        /* closing quote must be followed by a space or
+                         * nothing at all. */
+                        if (*(p+1) && !isspace(*(p+1))) goto err;
+                        done=1;
+                    } else if (!*p) {
+                        /* unterminated quotes */
+                        goto err;
+                    } else {
+                        current = sdscatlen(current,p,1);
+                    }
+                } else if (insq) {
+                    if (*p == '\\' && *(p+1) == '\'') {
+                        p++;
+                        current = sdscatlen(current,"'",1);
+                    } else if (*p == '\'') {
+                        /* closing quote must be followed by a space or
+                         * nothing at all. */
                         if (*(p+1) && !isspace(*(p+1))) goto err;
                         done=1;
                     } else if (!*p) {
@@ -521,6 +545,9 @@ sds *sdssplitargs(char *line, int *argc) {
                     case '"':
                         inq=1;
                         break;
+                    case '\'':
+                        insq=1;
+                        break;
                     default:
                         current = sdscatlen(current,p,1);
                         break;