X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fstr.c;h=db17cea6dead784c3e8612ccbfa98efafeb8d1e5;hb=084280e4bfd6b94c26320e72553a9a38201610a3;hp=bb49d0f3ac088424964dca9cfbe3a3568ec163d3;hpb=d807ad29cc0d3caa4f0e04ee4b75c70a225cfeaf;p=pspp-builds.git diff --git a/src/str.c b/src/str.c index bb49d0f3..db17cea6 100644 --- a/src/str.c +++ b/src/str.c @@ -194,6 +194,31 @@ st_pad_copy (char *dest, const char *src, size_t n) dest[n - 1] = 0; } } + +/* Copies SRC to DST, truncating DST to N-1 characters if + necessary. Always appends a null character. */ +void +st_trim_copy (char *dst, const char *src, size_t n) +{ + size_t len = strlen (src); + assert (n > 0); + if (len + 1 < n) + memcpy (dst, src, len + 1); + else + { + memcpy (dst, src, n - 1); + dst[n - 1] = '\0'; + } +} + + +/* Converts each character in S to uppercase. */ +void +st_uppercase (char *s) +{ + for (; *s != '\0'; s++) + *s = toupper ((unsigned char) *s); +} /* Initializes ST with initial contents S. */ void