diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2013-06-01 17:16:49 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-06-04 11:09:20 +0100 |
commit | 8de6167e36506a5cba21f6a35d4f064e9c9ea368 (patch) | |
tree | 33cf12274da8ff1f4bfeda2ea7c5d456bf4d34b9 /ucb | |
parent | 39e21050fe9e47b0496b0f4cc9e85f6577f0f6ce (diff) |
Resolves: #i122273# - Avoid using tmpfile()
(cherry picked from commit c4ef17d5e2844ca8d2459a3bfa1f91d99ac297f2)
Conflicts:
ucb/source/ucp/ftp/ftpcfunc.cxx
ucb/source/ucp/ftp/ftpinpstr.cxx
ucb/source/ucp/ftp/ftpinpstr.hxx
ucb/source/ucp/ftp/ftpurl.cxx
Change-Id: I267a9191f9b922380bef8653ac74543662ebf3ef
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/ftp/ftpcfunc.cxx | 16 | ||||
-rw-r--r-- | ucb/source/ucp/ftp/ftpcfunc.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/ftp/ftpurl.cxx | 26 | ||||
-rw-r--r-- | ucb/source/ucp/ftp/ftpurl.hxx | 4 |
4 files changed, 27 insertions, 21 deletions
diff --git a/ucb/source/ucp/ftp/ftpcfunc.cxx b/ucb/source/ucp/ftp/ftpcfunc.cxx index 1a445ab77337..93e11b92ae6c 100644 --- a/ucb/source/ucp/ftp/ftpcfunc.cxx +++ b/ucb/source/ucp/ftp/ftpcfunc.cxx @@ -23,10 +23,8 @@ ************************************************************************** *************************************************************************/ -#include <string.h> - +#include <osl/file.h> #include "ftpcontentidentifier.hxx" -#include <stdio.h> using namespace ftp; using namespace com::sun::star::uno; @@ -35,11 +33,15 @@ extern "C" { int file_write(void *buffer,size_t size,size_t nmemb,void *stream) { - FILE* file = - reinterpret_cast<FILE*>(stream); - if(!file) + oslFileHandle aFile = reinterpret_cast< oslFileHandle >( stream ); + if( !aFile ) return 0; - return fwrite(buffer,size,nmemb,file); + + sal_uInt64 nWritten = 0; + sal_uInt64 nToWrite( size * nmemb ); + osl_writeFile( aFile, buffer, nToWrite, &nWritten ); + + return nWritten != nToWrite ? 0 : nmemb; } } diff --git a/ucb/source/ucp/ftp/ftpcfunc.hxx b/ucb/source/ucp/ftp/ftpcfunc.hxx index 27eced59eb49..127d04b1a0b8 100644 --- a/ucb/source/ucp/ftp/ftpcfunc.hxx +++ b/ucb/source/ucp/ftp/ftpcfunc.hxx @@ -46,7 +46,7 @@ extern "C" { /** callback for curl_easy_perform(), * forwarding the written content to the stream. - * stream has to be of type 'FTPStreamContainer'. + * stream has to be of type oslFileHandle. */ diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx index ecee9edbcffe..50309e9d37f9 100644 --- a/ucb/source/ucp/ftp/ftpurl.cxx +++ b/ucb/source/ucp/ftp/ftpurl.cxx @@ -389,7 +389,7 @@ namespace ftp { CURLOPT_URL, \ urlParAscii.getStr()); -FILE* FTPURL::open() +oslFileHandle FTPURL::open() throw(curl_exception) { if(m_aPathSegmentVec.empty()) @@ -400,18 +400,22 @@ FILE* FTPURL::open() SET_CONTROL_CONTAINER; OUString url(ident(false,true)); SET_URL(url); - FILE *res = tmpfile(); - curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,file_write); - curl_easy_setopt(curl,CURLOPT_WRITEDATA,res); - curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); - CURLcode err = curl_easy_perform(curl); + oslFileHandle res( NULL ); + if ( osl_createTempFile( NULL, &res, NULL ) == osl_File_E_None ) + { + curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,file_write); + curl_easy_setopt(curl,CURLOPT_WRITEDATA,res); - if(err == CURLE_OK) - rewind(res); - else { - fclose(res),res = 0; - throw curl_exception(err); + curl_easy_setopt(curl,CURLOPT_POSTQUOTE,0); + CURLcode err = curl_easy_perform(curl); + + if(err == CURLE_OK) + osl_setFilePos( res, osl_Pos_Absolut, 0 ); + else { + osl_closeFile(res),res = 0; + throw curl_exception(err); + } } return res; diff --git a/ucb/source/ucp/ftp/ftpurl.hxx b/ucb/source/ucp/ftp/ftpurl.hxx index 76603d2d9d82..7d13b5ccc2c2 100644 --- a/ucb/source/ucp/ftp/ftpurl.hxx +++ b/ucb/source/ucp/ftp/ftpurl.hxx @@ -30,9 +30,9 @@ #include <curl/easy.h> #include <com/sun/star/io/XOutputStream.hpp> -#include <stdio.h> #include <rtl/ustring.hxx> #include <osl/mutex.hxx> +#include <osl/file.h> #include <vector> #include "ftpdirp.hxx" @@ -124,7 +124,7 @@ namespace ftp { // returns a pointer to an open tempfile, // seeked to the beginning of. - FILE* open() throw(curl_exception); + oslFileHandle open() throw(curl_exception); FTPDirentry direntry() const throw(curl_exception); |