+#include "gl/minmax.h"
+#include "gl/xalloc.h"
+
+/* Copies the contents of string value SRC with width SRC_WIDTH
+ to string value DST with width DST_WIDTH. If SRC_WIDTH is
+ greater than DST_WIDTH, then only the first DST_WIDTH bytes
+ are copied; if DST_WIDTH is greater than SRC_WIDTH, then DST
+ is padded on the right with PAD bytes.
+
+ SRC and DST must be string values; that is, SRC_WIDTH and
+ DST_WIDTH must both be positive.
+
+ It is important that SRC_WIDTH and DST_WIDTH be the actual
+ widths with which SRC and DST were initialized. Passing,
+ e.g., smaller values in order to copy only a prefix of SRC or
+ modify only a prefix of DST will not work in every case. */
+void
+value_copy_rpad (union value *dst, int dst_width,
+ const union value *src, int src_width,
+ char pad)
+{
+ u8_buf_copy_rpad (value_str_rw (dst, dst_width), dst_width,
+ value_str (src, src_width), src_width,
+ pad);
+}
+
+/* Copies the contents of null-terminated string SRC to string
+ value DST with width DST_WIDTH. If SRC is more than DST_WIDTH
+ bytes long, then only the first DST_WIDTH bytes are copied; if
+ DST_WIDTH is greater than the length of SRC, then DST is
+ padded on the right with PAD bytes.
+
+ DST must be a string value; that is, DST_WIDTH must be
+ positive.
+
+ It is important that DST_WIDTH be the actual width with which
+ DST was initialized. Passing, e.g., a smaller value in order
+ to modify only a prefix of DST will not work in every case. */
+void
+value_copy_str_rpad (union value *dst, int dst_width, const uint8_t *src,
+ char pad)
+{
+ value_copy_buf_rpad (dst, dst_width, src, u8_strlen (src), pad);
+}
+
+/* Copies the SRC_LEN bytes at SRC to string value DST with width
+ DST_WIDTH. If SRC_LEN is greater than DST_WIDTH, then only
+ the first DST_WIDTH bytes are copied; if DST_WIDTH is greater
+ than SRC_LEN, then DST is padded on the right with PAD bytes.
+
+ DST must be a string value; that is, DST_WIDTH must be
+ positive.
+
+ It is important that DST_WIDTH be the actual width with which
+ DST was initialized. Passing, e.g., a smaller value in order
+ to modify only a prefix of DST will not work in every case. */
+void
+value_copy_buf_rpad (union value *dst, int dst_width,
+ const uint8_t *src, size_t src_len, char pad)