diff options
Diffstat (limited to 'sal/osl/w32/tempfile.cxx')
-rw-r--r-- | sal/osl/w32/tempfile.cxx | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx index 708dbe15c..268fe0b6d 100644 --- a/sal/osl/w32/tempfile.cxx +++ b/sal/osl/w32/tempfile.cxx @@ -2,13 +2,10 @@ * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * Copyright 2008 by Sun Microsystems, Inc. + * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite * - * $RCSfile: file.cxx,v $ - * $Revision: 1.0 $ - * * This file is part of OpenOffice.org. * * OpenOffice.org is free software: you can redistribute it and/or modify @@ -37,6 +34,7 @@ #include "file_error.h" #include "file_url.h" +#include "path_helper.hxx" #include "osl/diagnose.h" @@ -215,7 +213,7 @@ oslFileError SAL_CALL osl_createTempFile( if (osl_File_E_None != osl_error) return osl_error; - /* allocate enough space on the stack */ + /* allocate enough space on the stack, the file name can not be longer than MAX_PATH */ STACK_ALLOC(tmp_name, WCHAR, (rtl_uString_getLength(base_directory) + MAX_PATH)); if (tmp_name) @@ -241,25 +239,21 @@ oslFileError SAL_CALL osl_createTempFile( //############################################# oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) { - WCHAR szBuffer[MAX_PATH]; - LPWSTR lpBuffer = szBuffer; - DWORD nBufferLength = ELEMENTS_OF_ARRAY(szBuffer) - 1; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + LPWSTR lpBuffer = aBuffer; + DWORD nBufferLength = aBuffer.getBufSizeInSymbols() - 1; DWORD nLength; oslFileError error; - do - { - nLength = GetTempPathW( ELEMENTS_OF_ARRAY(szBuffer), lpBuffer ); - if ( nLength > nBufferLength ) - { - nLength++; - lpBuffer = reinterpret_cast<WCHAR*>(alloca( sizeof(WCHAR) * nLength )); - nBufferLength = nLength - 1; - } - } while ( nLength > nBufferLength ); + nLength = GetTempPathW( aBuffer.getBufSizeInSymbols(), lpBuffer ); - if ( nLength ) + if ( nLength > nBufferLength ) + { + // the provided path has invalid length + error = osl_File_E_NOENT; + } + else if ( nLength ) { rtl_uString *ustrTempPath = NULL; @@ -277,3 +271,4 @@ oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) return error; } + |