X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fstr.c;h=965e3b301b5c67326390383d5e23c66d77c50280;hb=8acca2de53c1852f38726f70fc6516b34732a79f;hp=cf0069dd3d4e46e5ba292cdbb352fd4d4b89e48b;hpb=f43378497b8400e9c22a3485c534693dc1bc9554;p=pspp-builds.git diff --git a/src/libpspp/str.c b/src/libpspp/str.c index cf0069dd..965e3b30 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -158,6 +158,22 @@ buf_copy_str_lpad (char *dst, size_t dst_size, const char *src) } } +/* Copies buffer SRC, of SRC_SIZE bytes, to DST, of DST_SIZE bytes. + DST is truncated to DST_SIZE bytes or padded on the left with + spaces as needed. */ +void +buf_copy_lpad (char *dst, size_t dst_size, + const char *src, size_t src_size) +{ + if (src_size >= dst_size) + memmove (dst, src, dst_size); + else + { + memset (dst, ' ', dst_size - src_size); + memmove (&dst[dst_size - src_size], src, src_size); + } +} + /* 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 spaces as needed. */ @@ -253,6 +269,15 @@ spprintf (char *dst, const char *format, ...) return dst + count; } + +/* Sets the SIZE bytes starting at BLOCK to C, + and returns the byte following BLOCK. */ +void * +mempset (void *block, int c, size_t size) +{ + memset (block, c, size); + return (char *) block + size; +} /* Substrings. */