X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/b2b5ae80065ff52a77a3b8c08a89c895d151a52f..7fc98533392f455974d546c88bd4d41c85e6fe6d:/sds.c diff --git a/sds.c b/sds.c index 497d00f5..feb1a621 100644 --- a/sds.c +++ b/sds.c @@ -1,6 +1,6 @@ /* SDSLib, A C dynamic strings library * - * Copyright (c) 2006-2009, Salvatore Sanfilippo + * Copyright (c) 2006-2010, Salvatore Sanfilippo * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -159,7 +159,7 @@ sds sdscpy(sds s, char *t) { sds sdscatprintf(sds s, const char *fmt, ...) { va_list ap; char *buf, *t; - size_t buflen = 32; + size_t buflen = 16; while(1) { buf = zmalloc(buflen); @@ -335,3 +335,25 @@ cleanup: } #endif } + +void sdsfreesplitres(sds *tokens, int count) { + if (!tokens) return; + while(count--) + sdsfree(tokens[count]); + zfree(tokens); +} + +sds sdsfromlonglong(long long value) { + char buf[32], *p; + unsigned long long v; + + v = (value < 0) ? -value : value; + p = buf+31; /* point to the last character */ + do { + *p-- = '0'+(v%10); + v /= 10; + } while(v); + if (value < 0) *p-- = '-'; + p++; + return sdsnewlen(p,32-(p-buf)); +}