X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=8243aa0690aad24a9b519db9bd1838724d32d729;hb=cb72db62c20ecab427229110820c5b053d0663c4;hp=ccd7739c647b87d989b9cbc867810d915839770c;hpb=c9b92e317e7426db24fce2636134e1e46eb05d40;p=pspp-builds.git diff --git a/src/libpspp/str.c b/src/libpspp/str.c index ccd7739c..8243aa06 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -1214,7 +1215,7 @@ 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'; @@ -1441,3 +1442,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); + } +}