diff options
Diffstat (limited to 'lib/String.cc')
-rw-r--r-- | lib/String.cc | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/String.cc b/lib/String.cc index ff6a45f..b2c3dbe 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: String.cc,v 1.33 2003-12-04 04:09:02 pixel Exp $ */ +/* $Id: String.cc,v 1.34 2004-07-23 16:56:03 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -157,20 +157,26 @@ const char * String::set(const char * s, va_list ap) { r = str; #else // !HAVE_VASPRINTF #ifdef HAVE_VSNPRINTF + LOCK; vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); + UNLOCK; #else // !HAVE_VSNPRINTF #ifdef _WIN32 #ifdef _MSC_VER r = str = (char *) malloc(_vscprintf(s, ap) + 1); vsprintf(str, s, ap); #else + LOCK; _vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); + UNLOCK; #endif #else + LOCK; vsprintf(t, s, ap); str = Base::strdup(r = t); + UNLOCK; #endif #endif // HAVE_VSNPRINTF #endif // HAVE_VASPRINTF @@ -229,7 +235,10 @@ int String::scanf(const ugly_string & s, ...) const { const char * String::to_charp(size_t from, ssize_t to) const { if (to < 0) { - strncpy(t, &(str[from]), BUFSIZ); + if (from) + strncpy(t, &(str[from]), BUFSIZ); + else + return str; } else { if (((size_t) to) >= siz) { to = siz - 1; @@ -257,7 +266,13 @@ String String::extract(size_t from, ssize_t to) const { } char * String::strdup(size_t from, ssize_t to) const { - return Base::strdup(extract(from, to).str); + char * r; + + LOCK; + r = Base::strdup(to_charp(from, to)); + UNLOCK; + + return r; } int String::to_int(void) const { @@ -361,9 +376,7 @@ char String::operator[](size_t i) const { } char & String::operator[](size_t i) { - static char zero; - - zero = 0; + static char zero = 0; if (i >= siz) { return zero; |