X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fstr.c;h=081ffea5a74d36290c05450b3d5e52e04cd8fa90;hb=16aa47dbdde420fe82032f7d2e166fdf4e974df5;hp=fe9ad814680590df36575e9e18fc482c48631cf3;hpb=3c2526641a2e88ff6dec7ea6ae5ffc063daf6957;p=pspp diff --git a/src/str.c b/src/str.c index fe9ad81468..081ffea5a7 100644 --- a/src/str.c +++ b/src/str.c @@ -25,7 +25,6 @@ #include #include "alloc.h" #include "error.h" -#include "pool.h" /* sprintf() wrapper functions for convenience. */ @@ -79,8 +78,8 @@ nvsprintf (char *buf, const char *format, va_list args) void buf_reverse (char *p, size_t nbytes) { - unsigned char *h = p, *t = &h[nbytes - 1]; - unsigned char temp; + char *h = p, *t = &h[nbytes - 1]; + char temp; nbytes /= 2; while (nbytes--) @@ -249,6 +248,21 @@ str_copy_trunc (char *dst, size_t dst_size, const char *src) } } +/* Copies buffer SRC, of SRC_LEN bytes, + to DST, which is in a buffer DST_SIZE bytes long. + Truncates DST to DST_SIZE - 1 characters, if necessary. */ +void +str_copy_buf_trunc (char *dst, size_t dst_size, + const char *src, size_t src_size) +{ + size_t dst_len; + assert (dst_size > 0); + + dst_len = src_size < dst_size ? src_size : dst_size - 1; + memcpy (dst, src, dst_len); + dst[dst_len] = '\0'; +} + /* Converts each character in S to uppercase. */ void str_uppercase (char *s)