diff options
author | Christopher Faylor <me@cgf.cx> | 2012-02-15 15:33:56 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2012-02-15 15:33:56 +0000 |
commit | a0f4e7d3f19f5e7b5e3cab2f18790fcda4dae991 (patch) | |
tree | b939d2efc19566e77d4bfb739ee0f39aabd6100f /winsup/cygwin/smallprint.cc | |
parent | 5eb802f8ed164bce359bd604f3bb53cfa19fc69c (diff) | |
download | cygnal-a0f4e7d3f19f5e7b5e3cab2f18790fcda4dae991.tar.gz cygnal-a0f4e7d3f19f5e7b5e3cab2f18790fcda4dae991.tar.bz2 cygnal-a0f4e7d3f19f5e7b5e3cab2f18790fcda4dae991.zip |
* smallprint.cc (tmpbuf): Declare new class holding a static buffer, protected
by a lock.
(__small_vsprintf): Use tmpbuf to hold large buffer.
(__small_vswprintf): Ditto.
Diffstat (limited to 'winsup/cygwin/smallprint.cc')
-rw-r--r-- | winsup/cygwin/smallprint.cc | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/winsup/cygwin/smallprint.cc b/winsup/cygwin/smallprint.cc index 9e59cc7b0..1ca7ca817 100644 --- a/winsup/cygwin/smallprint.cc +++ b/winsup/cygwin/smallprint.cc @@ -1,6 +1,7 @@ /* smallprint.cc: small print routines for WIN32 - Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009 + Copyright 1996, 1998, 2000, 2001, 2002, 2003, 2005, 2006, + 2007, 2008, 2009, 2012 Red Hat, Inc. This file is part of Cygwin. @@ -11,6 +12,7 @@ details. */ #include "winsup.h" #include "ntdll.h" +#include "sync.h" #include <stdlib.h> #include <ctype.h> #include <wchar.h> @@ -23,6 +25,34 @@ details. */ static const char hex_str[] = "0123456789ABCDEF"; +class tmpbuf +{ + static WCHAR buf[NT_MAX_PATH]; + static muto lock; + bool locked; +public: + operator WCHAR * () + { + if (!locked) + { + lock.init ("smallprint_buf")->acquire (); + locked = true; + } + return buf; + } + operator char * () {return (char *) ((WCHAR *) *this);} + + tmpbuf (): locked (false) {}; + ~tmpbuf () + { + if (locked) + lock.release (); + } +}; + +WCHAR tmpbuf::buf[NT_MAX_PATH]; +muto tmpbuf::lock; + static char __fastcall * __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned long long mask) { @@ -65,7 +95,7 @@ __rn (char *dst, int base, int dosign, long long val, int len, int pad, unsigned int __small_vsprintf (char *dst, const char *fmt, va_list ap) { - char tmp[NT_MAX_PATH]; + tmpbuf tmp; char *orig = dst; const char *s; PWCHAR w; @@ -367,7 +397,7 @@ __wrn (PWCHAR dst, int base, int dosign, long long val, int len, int pad, unsign int __small_vswprintf (PWCHAR dst, const WCHAR *fmt, va_list ap) { - WCHAR tmp[NT_MAX_PATH]; + tmpbuf tmp; PWCHAR orig = dst; const char *s; PWCHAR w; |