X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fpool.c;h=dbdd71b6cbbf250fbb91248e6c8cc820da13e4f0;hb=3bbb4370239deb29ebbf813d258aef6249e2a431;hp=896a27ed21703538b4bbf2a727c6de8075f20c44;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp-builds.git diff --git a/src/libpspp/pool.c b/src/libpspp/pool.c index 896a27ed..dbdd71b6 100644 --- a/src/libpspp/pool.c +++ b/src/libpspp/pool.c @@ -16,13 +16,14 @@ #include #include "pool.h" +#include #include -#include "alloc.h" #include #include "message.h" -#include "size_max.h" #include "str.h" +#include "xalloc.h" + /* Fast, low-overhead memory block suballocator. */ struct pool { @@ -363,6 +364,19 @@ pool_strdup (struct pool *pool, const char *string) return pool_clone_unaligned (pool, string, strlen (string) + 1); } +/* Duplicates the SIZE bytes of STRING, plus a trailing 0 byte, + and returns a pointer to the duplicate. For use only with + strings, because the returned pointere may not be aligned + properly for other types. */ +char * +pool_strdup0 (struct pool *pool, const char *string, size_t size) +{ + char *new_string = pool_alloc_unaligned (pool, size + 1); + memcpy (new_string, string, size); + new_string[size] = '\0'; + return new_string; +} + /* Formats FORMAT with the given ARGS in memory allocated from POOL and returns the formatted string. */ char *