X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fstrings.c;h=393d8e7cab3e4b6e968cc395aec3cf67ec8b2a50;hp=5fa68caf75346edb5ad0a366544c790b3e9aeec1;hb=5eb177874dea59107a1a2ea44f5d8f5bb99550b2;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/strings.c b/ncurses/tinfo/strings.c index 5fa68caf..393d8e7c 100644 --- a/ncurses/tinfo/strings.c +++ b/ncurses/tinfo/strings.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2000 Free Software Foundation, Inc. * + * Copyright (c) 2000-2007,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -36,7 +36,7 @@ #include -MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") +MODULE_ID("$Id: strings.c,v 1.8 2012/02/22 22:34:31 tom Exp $") /**************************************************************************** * Useful string functions (especially for mvcur) @@ -44,8 +44,7 @@ MODULE_ID("$Id: strings.c,v 1.3 2000/12/10 02:55:08 tom Exp $") #if !HAVE_STRSTR NCURSES_EXPORT(char *) -_nc_strstr -(const char *haystack, const char *needle) +_nc_strstr(const char *haystack, const char *needle) { size_t len1 = strlen(haystack); size_t len2 = strlen(needle); @@ -53,7 +52,7 @@ _nc_strstr while ((len1 != 0) && (len1-- >= len2)) { if (!strncmp(haystack, needle, len2)) { - result = haystack; + result = (char *) haystack; break; } haystack++; @@ -63,16 +62,18 @@ _nc_strstr #endif /* - * Initialize the descriptor so we can append to it. + * Initialize the descriptor so we can append to it. Note that 'src' may + * be a null pointer (see _nc_str_null), so the corresponding strcat and + * strcpy calls have to allow for this. */ NCURSES_EXPORT(string_desc *) -_nc_str_init -(string_desc * dst, char *src, size_t len) +_nc_str_init(string_desc * dst, char *src, size_t len) { if (dst != 0) { dst->s_head = src; dst->s_tail = src; dst->s_size = len - 1; + dst->s_init = dst->s_size; if (src != 0) *src = 0; } @@ -83,8 +84,7 @@ _nc_str_init * Initialize the descriptor for only tracking the amount of memory used. */ NCURSES_EXPORT(string_desc *) -_nc_str_null -(string_desc * dst, size_t len) +_nc_str_null(string_desc * dst, size_t len) { return _nc_str_init(dst, 0, len); } @@ -93,8 +93,7 @@ _nc_str_null * Copy a descriptor */ NCURSES_EXPORT(string_desc *) -_nc_str_copy -(string_desc * dst, string_desc * src) +_nc_str_copy(string_desc * dst, string_desc * src) { *dst = *src; return dst; @@ -111,7 +110,7 @@ _nc_safe_strcat(string_desc * dst, const char *src) if (len < dst->s_size) { if (dst->s_tail != 0) { - strcpy(dst->s_tail, src); + _nc_STRCPY(dst->s_tail, src, dst->s_size); dst->s_tail += len; } dst->s_size -= len; @@ -132,10 +131,10 @@ _nc_safe_strcpy(string_desc * dst, const char *src) if (len < dst->s_size) { if (dst->s_head != 0) { - strcpy(dst->s_head, src); + _nc_STRCPY(dst->s_head, src, dst->s_size); dst->s_tail = dst->s_head + len; } - dst->s_size -= len; + dst->s_size = dst->s_init - len; return TRUE; } }