From 739803c06403481f32534a4ab5f5735fa1b52e6f Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 14 Mar 2012 14:58:26 +0100 Subject: [PATCH] sds.c: sdsAllocSize() function added. --- src/sds.c | 6 ++++++ src/sds.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/sds.c b/src/sds.c index 82d12e23..bc6aa6b2 100644 --- a/src/sds.c +++ b/src/sds.c @@ -123,6 +123,12 @@ sds sdsRemoveFreeSpace(sds s) { return sh->buf; } +size_t sdsAllocSize(sds s) { + struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr))); + + return sizeof(*sh)+sh->len+sh->free+1; +} + /* Increment the sds length and decrements the left free space at the * end of the string accordingly to 'incr'. Also set the null term * in the new end of the string. diff --git a/src/sds.h b/src/sds.h index b00551b4..0648381b 100644 --- a/src/sds.h +++ b/src/sds.h @@ -94,5 +94,7 @@ sds sdsmapchars(sds s, char *from, char *to, size_t setlen); /* Low level functions exposed to the user API */ sds sdsMakeRoomFor(sds s, size_t addlen); void sdsIncrLen(sds s, int incr); +sds sdsRemoveFreeSpace(sds s); +size_t sdsAllocSize(sds s); #endif -- 2.45.2