From: Ben Pfaff Date: Mon, 21 Dec 2009 04:05:24 +0000 (-0800) Subject: str: New function ds_steal_cstr. X-Git-Tag: fc11-x64-build67~1 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f535d301fd8181ae3fbfeb023f4e016a91064d9;p=pspp-builds.git str: New function ds_steal_cstr. --- diff --git a/src/libpspp/str.c b/src/libpspp/str.c index 8243aa06..79f3c912 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -1222,6 +1222,17 @@ ds_cstr (const struct string *st_) return st->ss.string; } +/* Returns the value of ST as a null-terminated string and then + reinitialized ST as an empty string. The caller must free the + returned string with free(). */ +char * +ds_steal_cstr (struct string *st) +{ + char *s = ds_cstr (st); + ds_init_empty (st); + return s; +} + /* Reads characters from STREAM and appends them to ST, stopping after MAX_LENGTH characters, after appending a newline, or after an I/O error or end of file was encountered, whichever diff --git a/src/libpspp/str.h b/src/libpspp/str.h index a134079f..0b57f736 100644 --- a/src/libpspp/str.h +++ b/src/libpspp/str.h @@ -203,6 +203,7 @@ char *ds_xstrdup (const struct string *); size_t ds_capacity (const struct string *); char *ds_cstr (const struct string *); +char *ds_steal_cstr (struct string *); /* File input. */ bool ds_read_line (struct string *, FILE *, size_t max_length);