X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fstrings.c;h=78cd2ef4f5f510ca7a4bdc36349b9f9d62f81626;hp=8198ec4050adaccf5e7329c509e2b220b79bd996;hb=8e25fff6a5f576b6dc35eb02b9783fa58680d07b;hpb=c633e5103a29a38532cf1925257b91cea33fd090;ds=sidebyside diff --git a/ncurses/tinfo/strings.c b/ncurses/tinfo/strings.c index 8198ec40..78cd2ef4 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-2003,2007 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,14 +36,14 @@ #include -MODULE_ID("$Id") +MODULE_ID("$Id: strings.c,v 1.6 2007/08/11 17:12:17 tom Exp $") /**************************************************************************** * Useful string functions (especially for mvcur) ****************************************************************************/ #if !HAVE_STRSTR -char * +NCURSES_EXPORT(char *) _nc_strstr(const char *haystack, const char *needle) { size_t len1 = strlen(haystack); @@ -52,7 +52,7 @@ _nc_strstr(const char *haystack, const char *needle) while ((len1 != 0) && (len1-- >= len2)) { if (!strncmp(haystack, needle, len2)) { - result = haystack; + result = (char *) haystack; break; } haystack++; @@ -62,15 +62,18 @@ _nc_strstr(const char *haystack, const char *needle) #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. */ -string_desc * +NCURSES_EXPORT(string_desc *) _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; } @@ -80,7 +83,7 @@ _nc_str_init(string_desc * dst, char *src, size_t len) /* * Initialize the descriptor for only tracking the amount of memory used. */ -string_desc * +NCURSES_EXPORT(string_desc *) _nc_str_null(string_desc * dst, size_t len) { return _nc_str_init(dst, 0, len); @@ -89,7 +92,7 @@ _nc_str_null(string_desc * dst, size_t len) /* * Copy a descriptor */ -string_desc * +NCURSES_EXPORT(string_desc *) _nc_str_copy(string_desc * dst, string_desc * src) { *dst = *src; @@ -99,7 +102,7 @@ _nc_str_copy(string_desc * dst, string_desc * src) /* * Replaces strcat into a fixed buffer, returning false on failure. */ -bool +NCURSES_EXPORT(bool) _nc_safe_strcat(string_desc * dst, const char *src) { if (src != 0) { @@ -120,7 +123,7 @@ _nc_safe_strcat(string_desc * dst, const char *src) /* * Replaces strcpy into a fixed buffer, returning false on failure. */ -bool +NCURSES_EXPORT(bool) _nc_safe_strcpy(string_desc * dst, const char *src) { if (src != 0) { @@ -131,7 +134,7 @@ _nc_safe_strcpy(string_desc * dst, const char *src) strcpy(dst->s_head, src); dst->s_tail = dst->s_head + len; } - dst->s_size -= len; + dst->s_size = dst->s_init - len; return TRUE; } }