diff --git a/expand.c b/expand.c index cadea78e7..3a56e050a 100644 --- a/expand.c +++ b/expand.c @@ -1121,9 +1121,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out ) break; - } - - + } len1 = (paran_begin-in); len2 = wcslen(paran_end)-1; @@ -1147,10 +1145,10 @@ static int expand_subshell( wchar_t *in, array_list_t *out ) free( subcmd ); return 0; } - + al_init( &tail_expand ); expand_subshell( wcsdup(paran_end+1), &tail_expand ); - + for( i=0; ibuff_len; data->buff_len += len; check_size(); - /* Insert space for extra character at the right position */ - if( data->buff_pos < data->buff_len ) + /* Insert space for extra characters at the right position */ + if( data->buff_pos < old_len ) { memmove( &data->buff[data->buff_pos+len], &data->buff[data->buff_pos], diff --git a/wutil.c b/wutil.c index 23a53d441..560ded689 100644 --- a/wutil.c +++ b/wutil.c @@ -22,22 +22,37 @@ #include "common.h" #include "wutil.h" +/** + Buffer for converting wide arguments to narrow arguments, used by + the \c wutil_wcs2str() function. +*/ static char *tmp=0; +/** + Length of the \c tmp buffer. +*/ static size_t tmp_len=0; -int c = 0; +/** + Counts the number of calls to the wutil wrapper functions +*/ +static int wutil_calls = 0; void wutil_destroy() { free( tmp ); tmp=0; tmp_len=0; - debug( 3, L"wutil functions called %d times", c ); + debug( 3, L"wutil functions called %d times", wutil_calls ); } +/** + Convert the specified wide aharacter string to a narrow character + string. This function uses an internal temporary buffer for storing + the result so subsequent results will overwrite previous results. +*/ static char *wutil_wcs2str( const wchar_t *in ) { - c++; + wutil_calls++; size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1; if( tmp_len < new_sz ) @@ -109,14 +124,17 @@ int wopen(const wchar_t *pathname, int flags, ...) if( tmp ) { - va_start( argp, flags ); if( ! (flags & O_CREAT) ) + { res = open(tmp, flags); + } else + { + va_start( argp, flags ); res = open(tmp, flags, va_arg(argp, int) ); - - va_end( argp ); + va_end( argp ); + } } return res;