X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flibpspp%2Fstr.c;h=79f3c912e9b649cf39d3ab9a0b37510e25867bf5;hb=d0b91eae59319ab2756d0d43b9cb15eb9cd3c234;hp=afe32de9f2049bfcc5a80ac7a95b36b348be4cb7;hpb=3bbb4370239deb29ebbf813d258aef6249e2a431;p=pspp diff --git a/src/libpspp/str.c b/src/libpspp/str.c index afe32de9f2..79f3c912e9 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -1214,13 +1215,24 @@ ds_capacity (const struct string *st) char * ds_cstr (const struct string *st_) { - struct string *st = (struct string *) st_; + struct string *st = CONST_CAST (struct string *, st_); if (st->ss.string == NULL) ds_extend (st, 1); st->ss.string[st->ss.length] = '\0'; 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