X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fstr.c;h=eaa9cdff9fd6f6eac8871ffaa964899900e67fee;hb=4f31116689eeda21658601c6ecf75a915b80103b;hp=fe9ad814680590df36575e9e18fc482c48631cf3;hpb=3c2526641a2e88ff6dec7ea6ae5ffc063daf6957;p=pspp diff --git a/src/str.c b/src/str.c index fe9ad81468..eaa9cdff9f 100644 --- a/src/str.c +++ b/src/str.c @@ -1,5 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. Written by Ben Pfaff . This program is free software; you can redistribute it and/or @@ -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) @@ -256,6 +270,14 @@ str_uppercase (char *s) for (; *s != '\0'; s++) *s = toupper ((unsigned char) *s); } + +/* Converts each character in S to lowercase. */ +void +str_lowercase (char *s) +{ + for (; *s != '\0'; s++) + *s = tolower ((unsigned char) *s); +} /* Initializes ST with initial contents S. */ void