diff options
Diffstat (limited to 'src/jtutil')
-rw-r--r-- | src/jtutil/make.code.defn | 3 | ||||
-rw-r--r-- | src/jtutil/makefile | 8 | ||||
-rw-r--r-- | src/jtutil/misc.h | 19 | ||||
-rw-r--r-- | src/jtutil/miscstr.c | 63 | ||||
-rw-r--r-- | src/jtutil/test_strlcat.c | 96 |
5 files changed, 3 insertions, 186 deletions
diff --git a/src/jtutil/make.code.defn b/src/jtutil/make.code.defn index 29bf72e..bf8e033 100644 --- a/src/jtutil/make.code.defn +++ b/src/jtutil/make.code.defn @@ -3,8 +3,7 @@ # Source files in this directory SRCS = array.cc cpm_map.cc fuzzy.cc linear_map.cc norm.cc round.cc \ - miscstr.c miscfp.cc \ - error_exit.cc + miscfp.cc error_exit.cc # Subdirectories containing source files SUBDIRS = diff --git a/src/jtutil/makefile b/src/jtutil/makefile index 337a393..ff56b27 100644 --- a/src/jtutil/makefile +++ b/src/jtutil/makefile @@ -1,5 +1,5 @@ # Makefile for standalone test drivers in this directory -# $Header: /usr/local/svn/cvs-repositories/numrelcvs/AEIThorns/AHFinderDirect/src/jtutil/makefile,v 1.11 2003-03-12 20:03:57 jthorn Exp $ +# $Header: /usr/local/svn/cvs-repositories/numrelcvs/AEIThorns/AHFinderDirect/src/jtutil/makefile,v 1.12 2003-05-02 19:20:53 jthorn Exp $ # # CC, CXX = C and C++ compilers. Defaults are gcc and g++ if # variables aren't set from command line or environment. @@ -26,8 +26,7 @@ ALL_TESTS := test_array test_array2 \ test_cpm_map test_linear_map \ test_fuzzy test_round \ test_modulo test_norm \ - test_error_exit \ - test_strlcat + test_error_exit ################################################################################ @@ -58,9 +57,6 @@ test_norm : test_norm.o norm.o \ test_error_exit : test_error_exit.o error_exit.o $(CXX) $(CXXFLAGS) -o $@ $? -test_strlcat : test_strlcat.o miscstr.o - $(CXX) $(CXXFLAGS) -o $@ $? - .PHONY : clean clean : -rm -f *.o diff --git a/src/jtutil/misc.h b/src/jtutil/misc.h deleted file mode 100644 index 34bee35..0000000 --- a/src/jtutil/misc.h +++ /dev/null @@ -1,19 +0,0 @@ -/* misc.h -- misc C-compatible stuff */ -/* $Header$ */ - -/* - * prerequisites: - * <stdlib.h> or <string.h> or <stdio.h> // size_t - */ - -/* - * misc C-compatible string functions - * - * FIXME: - * Once Tom commits my patches to put Util_Strli{cat,cpy}() in the flesh, - * we won't need this. - */ -#ifdef __cplusplus - extern "C" -#endif -size_t AHFinderDirect_Strlcat(char* dst, const char* src, size_t dst_size); diff --git a/src/jtutil/miscstr.c b/src/jtutil/miscstr.c deleted file mode 100644 index 97aefeb..0000000 --- a/src/jtutil/miscstr.c +++ /dev/null @@ -1,63 +0,0 @@ -/* miscstr.c -- misc string routines */ -/* $Header$ */ - -#include <stdlib.h> -#include <string.h> - -#include "../include/stdc.h" - -#include "misc.h" - -/******************************************************************************/ - -/*@@ - @routine AHFinderDirect_Strlcat - @date 16.Feb.2003 - @author Jonathan Thornburg <jthorn@aei.mpg.de> - @desc This function implements the strcat() function - described in - http://www.openbsd.org/papers/strlcpy-paper.ps - - The strlcat(3) function appends the null-terminated string - src to the end of dst. It will append at most - size - strlen(dst) - 1 - characters, and always null-terminates the result. - (Hence this function never overflows the destination buffer.) - - strlcat(3) is a replacement for strncat(3). In comparison - to strncat(3), strlcat(3) is safer and easier to use: - it guarantees null termination of the destination buffer, - and the size parameter is easy to specify without danger - of off-by-one errors. - @enddesc - - @var dst - @vdesc A non-null pointer to the destination buffer. - @vtype char* dst - @endvar - - @var src - @vdesc A non-null pointer to the source string. - @vtype const char* dst - @endvar - - @var dst_size - @vdesc The size of the destination buffer. - @vtype size_t dst_size - @endvar - - @returntype size_t - @returndesc This function returns the length of the string it - tries to create, i.e. strlen(src) + strlen(dst() . - @endreturndesc - @@*/ -size_t AHFinderDirect_Strlcat(char* dst, const char* src, size_t dst_size) -{ -const size_t src_len = strlen(src); -const size_t dst_len = strlen(dst); -const int dst_remaining = dst_size - dst_len - 1; -if (dst_remaining > 0) - then strncat(dst, src, dst_remaining); - -return src_len + dst_len; -} diff --git a/src/jtutil/test_strlcat.c b/src/jtutil/test_strlcat.c deleted file mode 100644 index 0c69f57..0000000 --- a/src/jtutil/test_strlcat.c +++ /dev/null @@ -1,96 +0,0 @@ -/* test_strlcat -- test driver for Util_Strlcpy() */ -/* $Header$ */ - -#include <string.h> -#include <stdio.h> - -#include "../include/stdc.h" - -/* - * exceptionally, this (C++) header file is safe to #include from C, - * and contains a prototype for AHFinderDirect_Strlcat() . - */ -#include "util.hh" - -/******************************************************************************/ - -/* prototypes */ -size_t tryit(size_t dst_size, const char* src); -void nprint(int n_print, const char* buf); - -/* global data structures */ -static char buffer[100]; - -/******************************************************************************/ - -/* - * This program is a test driver for Util_Strlcpy() . - */ - -int main(void) -{ -size_t n; - -n = tryit(15, "world"); -printf("bufsize=15: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(11, "world"); -printf("bufsize=11: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(10, "world"); -printf("bufsize=10: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(9, "world"); -printf("bufsize=9: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(6, "world"); -printf("bufsize=6: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(5, "world"); -printf("bufsize=5: result=%d buffer=", (int) n); -nprint(20, buffer); - -n = tryit(4, "world"); -printf("bufsize=4: result=%d buffer=", (int) n); -nprint(20, buffer); - -return 0; -} - -/******************************************************************************/ - -size_t tryit(size_t dst_size, const char* src) -{ -const char hello[] = "hello\0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; -memcpy(buffer, hello, sizeof(hello)); -return AHFinderDirect_Strlcat(buffer, src, dst_size); -} - -/******************************************************************************/ - -/* print n_print characters of buf[], with visible indication of '\0' */ -void nprint(int n_print, const char* buf) -{ -int i; -int i_null = -1; - -printf("\""); - for (i = 0 ; i < n_print ; ++i) - { - if (buf[i] == '\0') - then { - if (i_null == -1) - then i_null = i; - printf("\\0"); - } - else printf("%c", buf[i]); - } -if (i_null >= 0) - then printf(" [null at i=%d]", i_null); -printf("\"\n"); -} |