+char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat,
+ char *key, memcached_return *error)
+{
+ char buffer[SMALL_STRING_LEN];
+ size_t length;
+ char *ret;
+
+ *error= MEMCACHED_SUCCESS;
+
+ if (!memcmp("pid", key, strlen("pid")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pid);
+ else if (!memcmp("uptime", key, strlen("uptime")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->uptime);
+ else if (!memcmp("time", key, strlen("time")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->time);
+ else if (!memcmp("version", key, strlen("version")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%s", stat->version);
+ else if (!memcmp("pointer_size", key, strlen("pointer_size")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pointer_size);
+ else if (!memcmp("rusage_user", key, strlen("rusage_user")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", stat->rusage_user_seconds, stat->rusage_user_microseconds);
+ else if (!memcmp("rusage_system", key, strlen("rusage_system")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", stat->rusage_system_seconds, stat->rusage_system_microseconds);
+ else if (!memcmp("curr_items", key, strlen("curr_items")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_items);
+ else if (!memcmp("total_items", key, strlen("total_items")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_items);
+ else if (!memcmp("bytes", key, strlen("bytes")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes);
+ else if (!memcmp("curr_connections", key, strlen("curr_connections")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_connections);
+ else if (!memcmp("total_connections", key, strlen("total_connections")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_connections);
+ else if (!memcmp("connection_structures", key, strlen("connection_structures")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->connection_structures);
+ else if (!memcmp("cmd_get", key, strlen("cmd_get")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->cmd_get);
+ else if (!memcmp("cmd_set", key, strlen("cmd_set")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->cmd_set);
+ else if (!memcmp("get_hits", key, strlen("get_hits")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->get_hits);
+ else if (!memcmp("get_misses", key, strlen("get_misses")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->get_misses);
+ else if (!memcmp("evictions", key, strlen("evictions")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->evictions);
+ else if (!memcmp("bytes_read", key, strlen("bytes_read")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes_read);
+ else if (!memcmp("bytes_written", key, strlen("bytes_written")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes_written);
+ else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->limit_maxbytes);
+ else if (!memcmp("threads", key, strlen("threads")))
+ length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->threads);
+ else
+ {
+ *error= MEMCACHED_NOTFOUND;
+ return NULL;
+ }
+
+ if (ptr->call_malloc)
+ ret= ptr->call_malloc(ptr, length + 1);
+ else
+ ret= malloc(length + 1);
+ memcpy(ret, buffer, length);
+ ret[length]= '\0';
+
+ return ret;
+}
+