Added libmemcachedutil containing utility functions
[awesomized/libmemcached] / libmemcached / memcached_string.c
index 1595ec6108b9f00b69ea3293de0cabeeb847e32f..5a6f190e5dd9f1fdbd526df01afffc991b1ce280 100644 (file)
@@ -41,10 +41,7 @@ memcached_string_st *memcached_string_create(memcached_st *ptr, memcached_string
 
   /* Saving malloc calls :) */
   if (string)
-  {
     memset(string, 0, sizeof(memcached_string_st));
-    string->is_allocated= MEMCACHED_NOT_ALLOCATED;
-  }
   else
   {
     if (ptr->call_malloc)
@@ -55,7 +52,7 @@ memcached_string_st *memcached_string_create(memcached_st *ptr, memcached_string
     if (string == NULL)
       return NULL;
     memset(string, 0, sizeof(memcached_string_st));
-    string->is_allocated= MEMCACHED_ALLOCATED;
+    string->is_allocated= true;
   }
   string->block_size= MEMCACHED_BLOCK_SIZE;
   string->root= ptr;
@@ -81,14 +78,12 @@ memcached_return memcached_string_append_character(memcached_string_st *string,
 {
   memcached_return rc;
 
-  WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
   rc=  memcached_string_check(string, 1);
 
   if (rc != MEMCACHED_SUCCESS)
     return rc;
 
-  *string->end= ' ';
+  *string->end= character;
   string->end++;
 
   return MEMCACHED_SUCCESS;
@@ -99,8 +94,6 @@ memcached_return memcached_string_append(memcached_string_st *string,
 {
   memcached_return rc;
 
-  WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
   rc= memcached_string_check(string, length);
 
   if (rc != MEMCACHED_SUCCESS)
@@ -116,30 +109,10 @@ memcached_return memcached_string_append(memcached_string_st *string,
   return MEMCACHED_SUCCESS;
 }
 
-size_t memcached_string_backspace(memcached_string_st *string, size_t remove)
-{
-  WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
-  if (string->end - string->string  > remove)
-  {
-    size_t difference;
-
-    difference= string->end - string->string;
-    string->end= string->string;
-
-    return difference;
-  }
-  string->end-= remove;
-
-  return remove;
-}
-
 char *memcached_string_c_copy(memcached_string_st *string)
 {
   char *c_ptr;
 
-  WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
-
   if (memcached_string_length(string) == 0)
     return NULL;
 
@@ -159,7 +132,6 @@ char *memcached_string_c_copy(memcached_string_st *string)
 
 memcached_return memcached_string_reset(memcached_string_st *string)
 {
-  WATCHPOINT_ASSERT(string->is_allocated != MEMCACHED_USED);
   string->end= string->string;
   
   return MEMCACHED_SUCCESS;
@@ -178,7 +150,7 @@ void memcached_string_free(memcached_string_st *ptr)
       free(ptr->string);
   }
 
-  if (ptr->is_allocated == MEMCACHED_ALLOCATED)
+  if (ptr->is_allocated)
   {
     if (ptr->root->call_free)
       ptr->root->call_free(ptr->root, ptr);
@@ -186,5 +158,5 @@ void memcached_string_free(memcached_string_st *ptr)
       free(ptr);
   }
   else
-    ptr->is_allocated= MEMCACHED_USED;
+    memset(ptr, 0, sizeof(memcached_string_st));
 }