X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=79f3c912e9b649cf39d3ab9a0b37510e25867bf5;hb=13d91b755ed1045e2c1183874b3752b07489b922;hp=c954a722c89987d371eee5084a9b52c452af0ee8;hpb=07db00919d6f067fd5dd6c6c1c2c2fba4f42cf21;p=pspp-builds.git diff --git a/src/libpspp/str.c b/src/libpspp/str.c index c954a722..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 @@ -1442,3 +1453,25 @@ ds_relocate (struct string *st) free ((char *) rel); } } + + + + +/* Operations on uint8_t "strings" */ + +/* Copies buffer SRC, of SRC_SIZE bytes, to DST, of DST_SIZE bytes. + DST is truncated to DST_SIZE bytes or padded on the right with + copies of PAD as needed. */ +void +u8_buf_copy_rpad (uint8_t *dst, size_t dst_size, + const uint8_t *src, size_t src_size, + char pad) +{ + if (src_size >= dst_size) + memmove (dst, src, dst_size); + else + { + memmove (dst, src, src_size); + memset (&dst[src_size], pad, dst_size - src_size); + } +}