2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
8 * Summary: Functions to manipulate the result structure.
13 memcached_result_st are used to internally represent the return values from
14 memcached. We use a structure so that long term as identifiers are added
15 to memcached we will be able to absorb new attributes without having
16 to addjust the entire API.
20 memcached_result_st
*memcached_result_create(memcached_st
*memc
,
21 memcached_result_st
*ptr
)
23 WATCHPOINT_ASSERT(memc
&& memc
->options
.is_initialized
);
25 /* Saving malloc calls :) */
28 memset(ptr
, 0, sizeof(memcached_result_st
));
32 ptr
= memc
->call_calloc(memc
, 1, sizeof(memcached_result_st
));
36 ptr
->options
.is_allocated
= true;
39 ptr
->options
.is_initialized
= true;
42 memcached_string_create(memc
, &ptr
->value
, 0);
43 WATCHPOINT_ASSERT_INITIALIZED(&ptr
->value
);
44 WATCHPOINT_ASSERT(ptr
->value
.string
== NULL
);
49 void memcached_result_reset(memcached_result_st
*ptr
)
52 memcached_string_reset(&ptr
->value
);
61 memcached_return_t
memcached_result_set_value(memcached_result_st
*ptr
, const char *value
, size_t length
)
63 return memcached_string_append(&ptr
->value
, value
, length
);
66 void memcached_result_free(memcached_result_st
*ptr
)
71 memcached_string_free(&ptr
->value
);
73 if (memcached_is_allocated(ptr
))
75 if (ptr
->root
!= NULL
)
77 ptr
->root
->call_free(ptr
->root
, ptr
);
86 ptr
->options
.is_initialized
= false;
91 char *memcached_result_value(memcached_result_st
*ptr
)
93 memcached_string_st
*sptr
= &ptr
->value
;
94 return memcached_string_value(sptr
);
97 size_t memcached_result_length(memcached_result_st
*ptr
)
99 memcached_string_st
*sptr
= &ptr
->value
;
100 return memcached_string_length(sptr
);