Style cleanup
[m6w6/libmemcached] / libmemcached / memcached_result.c
1 /*
2 memcached_result_st are used to internally represent the return values from
3 memcached. We use a structure so that long term as identifiers are added
4 to memcached we will be able to absorb new attributes without having
5 to addjust the entire API.
6 */
7 #include "common.h"
8
9 memcached_result_st *memcached_result_create(memcached_st *memc,
10 memcached_result_st *ptr)
11 {
12 WATCHPOINT_ASSERT(memc && memc->options.is_initialized);
13
14 /* Saving malloc calls :) */
15 if (ptr)
16 {
17 memset(ptr, 0, sizeof(memcached_result_st));
18 }
19 else
20 {
21 ptr= memc->call_malloc(memc, sizeof(memcached_result_st));
22
23 if (ptr == NULL)
24 return NULL;
25 ptr->options.is_allocated= true;
26 }
27
28 ptr->options.is_initialized= true;
29
30 ptr->root= memc;
31 memcached_string_create(memc, &ptr->value, 0);
32 WATCHPOINT_ASSERT_INITIALIZED(&ptr->value);
33 WATCHPOINT_ASSERT(ptr->value.string == NULL);
34
35 return ptr;
36 }
37
38 void memcached_result_reset(memcached_result_st *ptr)
39 {
40 ptr->key_length= 0;
41 memcached_string_reset(&ptr->value);
42 ptr->flags= 0;
43 ptr->cas= 0;
44 ptr->expiration= 0;
45 }
46
47 /*
48 NOTE turn into macro
49 */
50 memcached_return_t memcached_result_set_value(memcached_result_st *ptr, const char *value, size_t length)
51 {
52 return memcached_string_append(&ptr->value, value, length);
53 }
54
55 void memcached_result_free(memcached_result_st *ptr)
56 {
57 if (ptr == NULL)
58 return;
59
60 memcached_string_free(&ptr->value);
61
62 if (memcached_is_allocated(ptr))
63 {
64 free(ptr);
65 }
66 else
67 {
68 ptr->options.is_initialized= false;
69 }
70 }